public void Insert(int index, LineSegment segment)
 {
     Insert(index, segment.end);
     Insert(index, segment.start);
 }
Example #2
0
        public static Shape CreateLine(LineSegment segment)
        {
            Shape s = new Shape();

            s._vertices.Add(segment.start);
            s._vertices.Add(segment.end);

            return s;
        }
Example #3
0
        // TODO: return ALL hit points (including ends if they are within the bounds of the AABB)
        public static bool IntersectsLine(AABB a, Vector2 lineStart, Vector2 lineEnd, out Vector2 hitPoint)
        {
            LineSegment te, re, be, le;
            te = new LineSegment(new Vector2(a.Left, a.Top), new Vector2(a.Right, a.Top));
            re = new LineSegment(new Vector2(a.Right, a.Top), new Vector2(a.Right, a.Bottom));
            be = new LineSegment(new Vector2(a.Right, a.Bottom), new Vector2(a.Left, a.Bottom));
            le = new LineSegment(new Vector2(a.Left, a.Bottom), new Vector2(a.Left, a.Top));

            return (Collider.LinesIntersect(lineStart, lineEnd, te.start, te.end, out hitPoint) ||
                Collider.LinesIntersect(lineStart, lineEnd, re.start, re.end, out hitPoint) ||
                Collider.LinesIntersect(lineStart, lineEnd, be.start, be.end, out hitPoint) ||
                Collider.LinesIntersect(lineStart, lineEnd, le.start, le.end, out hitPoint));
        }
Example #4
0
        public static bool IntersectsLine_Fast(AABB a, Vector2 lineStart, Vector2 lineEnd)
        {
            if (a.Intersects(lineStart) || a.Intersects(lineEnd)) { return true; }

            LineSegment te, re, be, le;
            te = new LineSegment(new Vector2(a.Left, a.Top), new Vector2(a.Right, a.Top));
            re = new LineSegment(new Vector2(a.Right, a.Top), new Vector2(a.Right, a.Bottom));
            be = new LineSegment(new Vector2(a.Right, a.Bottom), new Vector2(a.Left, a.Bottom));
            le = new LineSegment(new Vector2(a.Left, a.Bottom), new Vector2(a.Left, a.Top));

            return (Collider.LinesIntersect_Fast(lineStart, lineEnd, te.start, te.end) ||
                Collider.LinesIntersect_Fast(lineStart, lineEnd, re.start, re.end) ||
                Collider.LinesIntersect_Fast(lineStart, lineEnd, be.start, be.end) ||
                Collider.LinesIntersect_Fast(lineStart, lineEnd, le.start, le.end));
        }
 // TODO: adjust these functions to take into account the primitive type selected
 public void AddLine(LineSegment segment, Color color)
 {
     AddVertex(segment.start, color);
     AddVertex(segment.end, color);
 }