public override object Clone()
        {
            Vector2[] points  = new Vector2[_points.Count];
            int       counter = 0;

            foreach (Vector2 vec in _points)
            {
                points[counter] = (Vector2)vec.Clone();
                counter++;
            }

            Polygon2 shape = new Polygon2(points);

            return(shape);
        }
        public static Shape2 Convert(Polygon2 inPolygon, ShapeType shapeType)
        {
            Vector2 corner = inPolygon.Corner;
            Vector2 size   = inPolygon.GetSize();

            switch (shapeType)
            {
            case ShapeType.Circle:
                return(new Circle((corner + size / 2f), (size.X + size.Y) / 4f));

            case ShapeType.Rectangle:
                return(new Rectangle((corner + size / 2f), size.X, size.Y));
            }

            return(inPolygon);
        }
Beispiel #3
0
        public bool Touch(Polygon2 inShape)
        {
            bool     inside   = true;
            Polygon2 selfPoly = (Polygon2)GeoConverter.Convert(this, ShapeType.Polygon);

            Vector2 primoPoint = null;
            Vector2 lastPoint  = null;

            foreach (Vector2 vec in inShape.Points)
            {
                if (lastPoint != null)
                {
                    for (int i = 0; i < 4; i++)
                    {
                        if (Line.LineIntersectsLine(selfPoly.Points[0 + i], selfPoly.Points[(1 + i) % 4], vec, lastPoint))
                        {
                            return(true);
                        }
                    }
                }
                else
                {
                    primoPoint = new Vector2(vec.X, vec.Y);
                }

                //1 point not inside ? it's not inside...
                if (!Contains(vec))
                {
                    inside = false;
                }

                lastPoint = new Vector2(vec.X, vec.Y);
            }

            //Last chance... last segment
            for (int i = 0; i < 4; i++)
            {
                if (Line.LineIntersectsLine(selfPoly.Points[0 + i], selfPoly.Points[(1 + i) % 4], primoPoint, lastPoint))
                {
                    return(true);
                }
            }

            return(inside);
        }
Beispiel #4
0
        public bool Touch(Polygon2 inShape)
        {
            bool inside = true;

            Vector2 primoPoint = null;
            Vector2 lastPoint  = null;

            for (int i = 1; i < _points.Count; i++)
            {
                foreach (Vector2 vec in inShape.Points)
                {
                    if (lastPoint != null)
                    {
                        if (Line.LineIntersectsLine(_points[i - 1], _points[i], vec, lastPoint))
                        {
                            return(true);
                        }
                    }
                    else
                    {
                        primoPoint = new Vector2(vec.X, vec.Y);
                    }

                    lastPoint = new Vector2(vec.X, vec.Y);
                }

                //Last chance... last segment
                if (Line.LineIntersectsLine(_points[i - 1], _points[i], primoPoint, lastPoint))
                {
                    return(true);
                }

                //1 point not inside ? it's not inside...
                if (!inShape.Contains(_points[i - 1]))
                {
                    inside = false;
                }
            }

            return(inside);
        }
Beispiel #5
0
        public bool Touch(Stroke2 inStroke)
        {
            Polygon2 selfPoly = (Polygon2)GeoConverter.Convert(this, ShapeType.Polygon);

            Vector2 lastPoint = null;

            foreach (Vector2 vec in inStroke.Points)
            {
                if (lastPoint != null)
                {
                    for (int i = 0; i < 4; i++)
                    {
                        if (Line.LineIntersectsLine(selfPoly.Points[0 + i], selfPoly.Points[(1 + i) % 4], vec, lastPoint))
                        {
                            return(true);
                        }
                    }
                }

                lastPoint = new Vector2(vec.X, vec.Y);
            }

            return(false);
        }