private void _ComputeIntersections() { for (int i = 0; i < _clip.NumberOfVertices; ++i) { for (int j = 0; j < _subject.NumberOfVertices; ++j) { SegmentIntersectionInfo SegmentIntersectionInfo = _clip._GetSide(i) .GetIntersectionWith(_subject._GetSide(j)); if (SegmentIntersectionInfo.Point.HasValue) { PointD p = SegmentIntersectionInfo.Point.Value; _clipPoints[i].Add(new PolygonIntersectionPoint(p)); _subjectPoints[j].Add(new PolygonIntersectionPoint(p)); } } } }
public bool Contains(PointD p) { if (this.HasOnSide(p)) { return(true); } double maxX = _polygon._vertexManager.Vertices.Max(v => v.Location.X); Segment horizontalLine = new Segment(p, new PointD(maxX + 5, p.Y)); int cnt = 0, inc = 1; for (int i = 0; i < _polygon.NumberOfVertices; i += inc) { SegmentIntersectionInfo intersectionInfo = _polygon._GetSide(i) .GetIntersectionWith(horizontalLine); switch (intersectionInfo.Type) { case IntersectionType.Touches: int nextInd = (i + 1) % _polygon.NumberOfVertices; int prevInd = (i - 1 + _polygon.NumberOfVertices) % _polygon.NumberOfVertices; if (_polygon._GetSide(nextInd).GetIntersectionWith(horizontalLine).Type == IntersectionType.Covers) { inc = 3; cnt += _GetIncrementationForSideCoveringCase(i + 1, horizontalLine); } else if (_polygon._GetSide(prevInd).GetIntersectionWith(horizontalLine).Type == IntersectionType.Covers) { inc = 1; cnt += _GetIncrementationForSideCoveringCase(i - 1, horizontalLine); } else { PointD touchPoint = intersectionInfo.Point.Value; inc = (touchPoint == _polygon._vertexManager.GetVertex(i).Location ? 1 : 2); cnt += _GetIncrementationForVertexTouchingCase(i, touchPoint, horizontalLine); } break; case IntersectionType.Covers: inc = 2; cnt += _GetIncrementationForSideCoveringCase(i, horizontalLine); break; case IntersectionType.Intersects: cnt += 1; inc = 1; break; default: // no intersection inc = 1; break; } } return(cnt % 2 == 0 ? false : true); }