Exemplo n.º 1
0
        public static IEnumerator <Pair <float, Point <float> > > FindIntersectionsWith(LineSegment <float> seg, IEnumerator <Point <float> > e, bool isClosedShape)
        {
            int i = 0;

            if (e.MoveNext())
            {
                Point <float> first = e.Current, prev = first;
                float         frac;
                while (e.MoveNext())
                {
                    Point <float> cur = e.Current;
                    if (seg.ComputeIntersection(prev.To(cur), out frac))
                    {
                        yield return(Pair.Create(frac, seg.PointAlong(frac)));
                    }
                    prev = cur;
                    i++;
                }
                if (i > 1 && isClosedShape)
                {
                    if (seg.ComputeIntersection(prev.To(first), out frac))
                    {
                        yield return(Pair.Create(frac, seg.PointAlong(frac)));
                    }
                }
            }
        }
Exemplo n.º 2
0
		private void TestItsc(LineSegment<float> p, LineSegment<float> q, Point<float>? expected, float expect_pFrac, LineType pt = LineType.Segment, LineType qt = LineType.Segment)
		{
			float pFrac, qFrac;
			bool intersected = p.ComputeIntersection(pt, out pFrac, q, qt, out qFrac);
			Assert.AreEqual(expected.HasValue, intersected);
			Point<float>? result = p.ComputeIntersection(pt, q, qt);
			Assert.AreEqual(expected, result);
			Assert.AreEqual(expect_pFrac, pFrac);
		}
Exemplo n.º 3
0
        private DoOrUndo AttachedAnchorChanged(Anchor anchor, bool toSide)
        {
            PointT        p0 = default(PointT), p1 = default(PointT);
            List <PointT> old = null;

            return(@do =>
            {
                IList <PointT> points = Points;
                if (toSide)
                {
                    points = points.Reverse();
                }

                Debug.Assert(points.Count >= 2);
                if (points.Count < 2)
                {
                    return;
                }

                _bbox = null;
                if (@do)
                {
                    // save undo info in either (p0, p1) or (old) for complicated cases
                    p0 = points[0];
                    p1 = points[1];
                    old = new List <PointT>(Points);

                    var newAnchor = anchor.Point;
                    LineSegment <float> one = newAnchor.To(newAnchor.Add(points[1].Sub(points[0]))), two;
                    if (points.Count > 2)
                    {
                        two = points[1].To(points[2]);
                    }
                    else
                    {
                        two = one.B.To(one.B.Add(one.B.Sub(one.A).Rot90()));                         // fake it
                    }
                    points[0] = newAnchor;
                    PointT?itsc = one.ComputeIntersection(two, LineType.Infinite), itsc2;
                    if (itsc != null && !(points.Count == 2 && (toSide ? _fromAnchor : _toAnchor) != null))
                    {
                        points[1] = itsc.Value;
                    }
                    else
                    {
                        itsc = points[1];
                    }

                    if (points.Count >= 3 && points[1] == points[2])
                    {
                        int remove = 1;
                        if (points.Count > 3)
                        {
                            int a0 = AngleMod256(points[1].Sub(points[0])), a1 = AngleMod256(points[3].Sub(points[2]));
                            if ((a0 & 127) == (a1 & 127))
                            {
                                remove = 2;
                            }
                        }
                        points.RemoveRange(1, remove);
                    }
                    else if (points.Count >= 4 && (itsc2 = points[0].To(points[1]).ComputeIntersection(points[2].To(points[3]))) != null)
                    {
                        points.RemoveRange(1, 2);
                        points.Insert(1, itsc2.Value);
                    }
                    else
                    {
                        old = null;                         // save memory
                    }
                }
                else
                {
                    if (old != null)
                    {
                        Points = old;
                    }
                    else
                    {
                        points[0] = p0;
                        points[1] = p1;
                    }
                }
            });
        }