src/Polygon.cpp
bool Polygon::isComplex(const Vertices &polygon)
        {
            bool isComplex = false;

            const int n = polygon.size();
            for (int i = 0; !isComplex && (i < n); i++)
            {
                const int j = i + 1;
                for (int k = j; !isComplex && (k < n); k++)
                {
                    const int l = (k + 1 < n) ? (k + 1) : 0;
                    const Segment s0(polygon[i], polygon[j]);
                    const Segment s1(polygon[k], polygon[l]);
                    const bool adjacent = (k == j) || (l == i);
                    const Intersection itc = s0.intersection(s1);
                    if (adjacent)
                    {
                        isComplex = (itc == Intersection::OVERLAP);
                    }
                    else
                    {
                        isComplex = (itc == Intersection::INTERSECT) || (itc == Intersection::OVERLAP);
                    }
                }
            }

            return isComplex;
        }
/// Sides are represented by segments formed by two consecutive points. Each side
/// is checked for intersection or overlapping against all other sides. For example,
/// if the polygon has 5 sides [s1, s2, s3, s4, s5], the checks are:
///
///     s1 --> s2; s1 --> s3; s1 --> s4; s1 --> s5;
///     s2 --> s3; s2 --> s4; s2 --> s5;
///     s3 --> s4; s3 --> s5;
///     s4 --> s5
///
/// The algorithm has an external and an inner loop. The external one iterates over
/// all points (i) until the second last. The internal loop iterates over all points (k)
/// after i until the last one.
///
/// Making:
///   - `j = i + 1`
///   - `l = k + 1`
/// at each iteration of the internal loop, two segments are checked: `i --> j` and `k --> l`
///
/// Obs.: Originally I wanted to use Dan Sunday's [simple_Polygon algorithm](http://geomalgorithms.com/a09-_avl_code.html),
/// which should be less computationally intensive, but I was finding problems to correctly understand and rewrite.
/// I ended up simply checking for intersections of the polygon segments, also using an algorithm from Dan Sunday.
/// Check the documentation of class Segment for further details.
Sides are represented by segments formed by two consecutive points. Each side
is checked for intersection or overlapping against all other sides. For example,
if the polygon has 5 sides [s1, s2, s3, s4, s5], the checks are.



The algorithm has an external and an inner loop. The external one iterates over
all points (i) until the second last. The internal loop iterates over all points (k)
after i until the last one.



Obs.: Originally I wanted to use Dan Sunday's [simple_Polygon algorithm],
which should be less computationally intensive, but I was finding problems to correctly understand and rewrite.
I ended up simply checking for intersections of the polygon segments, also using an algorithm from Dan Sunday.
Check the documentation of class Segment for further details.
Sides are represented by segments formed by two consecutive points . Each side is checked for intersection or overlapping against all other sides . For example if the polygon has 5 sides [ s1 s2 s3 s4 s5 ] the checks are . The algorithm has an external and an inner loop . The external one iterates over all points ( i ) until the second last . The internal loop iterates over all points ( k ) after i until the last one . Obs . : Originally I wanted to use Dan Sunday ' s [ simple_Polygon algorithm ] which should be less computationally intensive but I was finding problems to correctly understand and rewrite . I ended up simply checking for intersections of the polygon segments also using an algorithm from Dan Sunday . Check the documentation of class Segment for further details .
bool Polygon::isComplex(const Vertices &polygon)
        {
            bool isComplex = false;
            const int n = polygon.size();
            for (int i = 0; !isComplex && (i < n); i++)
            {
                const int j = i + 1;
                for (int k = j; !isComplex && (k < n); k++)
                {
                    const int l = (k + 1 < n) ? (k + 1) : 0;
                    const Segment s0(polygon[i], polygon[j]);
                    const Segment s1(polygon[k], polygon[l]);
                    const bool adjacent = (k == j) || (l == i);
                    const Intersection itc = s0.intersection(s1);
                    if (adjacent)
                    {
                        isComplex = (itc == Intersection::OVERLAP);
                    }
                    else
                    {
                        isComplex = (itc == Intersection::INTERSECT) || (itc == Intersection::OVERLAP);
                    }
                }
            }
            return isComplex;
        }
bool Polygon :: isComplex ( const Vertices & polygon ) { bool isComplex = false ; const int n = polygon . size ( ) ; for ( int i = 0 ; ! isComplex && ( i < n ) ; i ++ ) { const int j = i + 1 ; for ( int k = j ; ! isComplex && ( k < n ) ; k ++ ) { const int l = ( k + 1 < n ) ? ( k + 1 ) : 0 ; const Segment s0 ( polygon [ i ] , polygon [ j ] ) ; const Segment s1 ( polygon [ k ] , polygon [ l ] ) ; const bool adjacent = ( k == j ) || ( l == i ) ; const Intersection itc = s0 . intersection ( s1 ) ; if ( adjacent ) { isComplex = ( itc == Intersection :: OVERLAP ) ; } else { isComplex = ( itc == Intersection :: INTERSECT ) || ( itc == Intersection :: OVERLAP ) ; } } } return isComplex ; }
Sides are represented by segments formed by two consecutive points.
Sides are represented by segments formed by two consecutive points .