Пример #1
0
 internal _SplitEvent(float distance, Vector2 intersectionPoint, SkeletonVertex vertex, SkeletonLineSegment oppositeEdge)
 {
     this.Distance          = distance;
     this.IntersectionPoint = intersectionPoint;
     this.Vertex            = vertex;
     this.OppositeEdge      = oppositeEdge;
 }
Пример #2
0
        public float Distance(Vector2 a)
        {
            var d = SqrMagnitude(this.V);     //magnitudesqrt

            if (d != 0)
            {
                var u = ((a.X - this.P.X) * this.V.X + (a.Y - this.P.Y) * this.V.Y) / d;
                //# Parallel, connect an endpoint with a line
                var t = Helpers.MathHelper.ConnectLineToPoint(this, a);

                if (!this._u_in(u))
                {
                    u = (float)Math.Max(Math.Min(u, 1.0), 0.0);
                    t = new SkeletonLineSegment(a, this.P + u * this.V);
                }

                //swap
                var oldP = t.P;
                t.P  = t.P1 = t.P2;
                t.P2 = oldP;
                t.V *= -1;

                return(t.Length);
            }

            return(0f);
        }
Пример #3
0
        internal SkeletonVertex(Vector2 p, SkeletonLineSegment l1, SkeletonLineSegment l2, Vector2[] direction_vectors = null)
        {
            this.EdgeLeft  = l1;
            this.EdgeRight = l2;
            this.Point     = p;
            this._valid    = true;

            var creator_vectors = new Vector2[] { l1.V.Normalized() * -1, l2.V.Normalized() };
            var reflex_vectors  = direction_vectors;

            if (direction_vectors == null)
            {
                reflex_vectors = creator_vectors;
            }

            var cross = Vector3.Cross(new Vector3(reflex_vectors[0]), new Vector3(reflex_vectors[1])).Z;

            if (cross < 0)
            {
                this.Is_Reflex = true;
            }

            this.BiSector = new SkeletonRay2(this.Point, Vector2.Add(creator_vectors[0], creator_vectors[1]) * (this.Is_Reflex ? -1 : 1));
            this.Vertices = new SkeletonVertices();
        }
Пример #4
0
        public SkeletonLineSegment ConnectPoint2Line2(Vector2 p, SkeletonLineSegment l)
        {
            var d = SqrMagnitude(l.V);
            //assert d != 0;
            var u = ((p.X - l.P.X) * l.V.X + (p.Y - l.P.Y) * l.V.Y) / d;

            if (l._u_in(u))
            {
                u = (float)Math.Max(Math.Min(u, 1.0), 0.0);
            }
            return(new SkeletonLineSegment(P, l.P + u * l.V));
        }
Пример #5
0
        public Vector2 Intersect(SkeletonLineSegment other, bool rayline = false)
        {
            var d = Helpers.MathHelper.Cross(other.V, this.V);

            if (d == 0)
            {
                return(Vector2.Zero);
            }

            var d2 = other.P - this.P;
            var ua = Helpers.MathHelper.Cross(this.V, d2) / d;

            if (rayline)
            {
                if (!other._u_in(ua))
                {
                    return(Vector2.Zero);
                }
            }
            var ub = Helpers.MathHelper.Cross(other.V, d2) / d;

            return(other.P + ua * other.V);
        }
Пример #6
0
 public SkeletonLine2(SkeletonLineSegment lineSegment)
 {
     this.P = lineSegment.P;
     this.V = lineSegment.V;
 }
Пример #7
0
 public SkeletonEdge(SkeletonLineSegment edge, SkeletonRay2 biSector_Left, SkeletonRay2 biSector_Right)
 {
     this.Edge           = edge;
     this.BiSector_Left  = biSector_Left;
     this.BiSector_Right = biSector_Right;
 }