private int eventCompare(bool p1_isStart, ref Vector2 p1_1, ref Vector2 p1_2, bool p2_isStart, ref Vector2 p2_1, ref Vector2 p2_2) { // compare the selected points first var comp = Epsilon.pointsCompare(p1_1, p2_1); if (comp != 0) { return(comp); } // the selected points are the same if (Epsilon.pointsSame(p1_2, p2_2)) // if the non-selected points are the same too... { return(0); // then the segments are equal } if (p1_isStart != p2_isStart) // if one is a start and the other isn't... { return(p1_isStart ? 1 : -1); // favor the one that isn't the start } // otherwise, we'll have to calculate which one is below the other manually return(Epsilon.pointAboveOrOnLine( p1_2, p2_isStart ? p2_1 : p2_2, // order matters p2_isStart ? p2_2 : p2_1 ) ? 1 : -1); }
public void addRegion(PointList region) { if (!selfIntersection) { throw new Exception("The addRegion() function is only intended for use when selfIntersection = false"); } // Ensure that the polygon is fully closed (the start point and end point are exactly the same) if (!Epsilon.pointsSame(region[region.Count - 1], region[0])) { region.Add(region[0]); } // regions are a list of points: // [ [0, 0], [100, 0], [50, 100] ] // you can add multiple regions before running calculate var pt1 = new Point(); var pt2 = region[region.Count - 1]; for (var i = 0; i < region.Count; i++) { pt1 = pt2; pt2 = region[i]; var forward = Epsilon.pointsCompare(pt1, pt2); if (forward == 0) // points are equal, so we have a zero-length segment { continue; // just skip it } eventAddSegment( segmentNew( forward < 0 ? pt1 : pt2, forward < 0 ? pt2 : pt1 ), true ); } }