Beispiel #1
0
        public static bool IsInside(Vector2 point, Geo2D geo2d)
        {
            Vector2   lineEnd = new Vector2(-Mathf.Infinity, point.y);
            GeoEdge2D edge    = new GeoEdge2D(point, lineEnd);

            int intersectCount = 0;

            foreach (GeoEdge2D e in geo2d.Edges)
            {
                if (GeoEdge2D.IsParallel(e, edge))
                {
                    continue;
                }

                if (GeoEdge2D.IsOnline(point, e))
                {
                    return(true);
                }

                if (GeoEdge2D.IsIntersected(edge, e))
                {
                    intersectCount++;
                }
            }

            return(intersectCount % 2 != 0);
        }
Beispiel #2
0
        public static bool IsIntersect(Geo2D poly2d, Geo2D rect2d)
        {
            if (!poly2d.AABBTest(rect2d))
            {
                return(false);
            }

            foreach (GeoEdge2D e1 in poly2d.Edges)
            {
                foreach (GeoEdge2D e2 in rect2d.Edges)
                {
                    if (GeoEdge2D.IsIntersected(e1, e2))
                    {
                        return(true);
                    }
                }
            }

            return(IsInside(poly2d.Center, rect2d) || IsInside(rect2d.Center, poly2d));
        }