public bool IsPointInside(Vector2 point)
{
Vector2D[] farFarAwayPoints = new Vector2D[] {
new Vector2D(point) + new Vector2D(99999, 99998),
new Vector2D(point) + new Vector2D(-99999, 89990),
};
LineSegment2D[] lineSegments = new LineSegment2D[] {
new LineSegment2D(new Vector2D(point), farFarAwayPoints[0]),
new LineSegment2D(new Vector2D(point), farFarAwayPoints[1]),
};
foreach (var ls in lineSegments)
{
int hits = 0;
for (int i = 0; i < vertices.Count; i++)
{
LineSegment2D l1 = new LineSegment2D(Polygon.V2(vertices[i]), Polygon.V2(vertices[(i + 1) % vertices.Count]));
Vector2D res = Vector2D.zero;
if (ls.LineIntersect(l1, out res))
{
hits++;
}
}
if (hits % 2 == 1)
{
return(true);
}
}
return(false);
}