예제 #1
0
        internal static bool EdgeIsPierced(CdtEdge e, Point source, Point target, CdtTriangle cdtTriangle)
        {
            var area0 = Point.SignedDoubledTriangleArea(e.upperSite.Point, source, target);
            var area1 = Point.SignedDoubledTriangleArea(e.lowerSite.Point, source, target);

            if (ApproximateComparer.Sign(area0) * ApproximateComparer.Sign(area1) > 0)
            {
                return(false);
            }
            area0 = Point.SignedDoubledTriangleArea(e.upperSite.Point, e.lowerSite.Point, source);
            area1 = Point.SignedDoubledTriangleArea(e.upperSite.Point, e.lowerSite.Point, target);
            if (ApproximateComparer.Sign(area0) * ApproximateComparer.Sign(area1) > 0)
            {
                return(false);
            }
            var otherT = e.GetOtherTriangle(cdtTriangle);

            if (otherT == null)
            {
                return(true);
            }
            var otherSite = otherT.OppositeSite(e);

            area0 = Point.SignedDoubledTriangleArea(e.upperSite.Point, e.lowerSite.Point, otherSite.Point);
            return(ApproximateComparer.Sign(area0) * ApproximateComparer.Sign(area1) >= 0);
        }
예제 #2
0
        static CdtEdge FindNextEdgeOnPerimeter(CdtEdge e)
        {
            var t = e.CwTriangle ?? e.CcwTriangle;

            e = t.Edges[t.Edges.Index(e) + 2];
            while (e.CwTriangle != null && e.CcwTriangle != null)
            {
                t = e.GetOtherTriangle(t);
                e = t.Edges[t.Edges.Index(e) + 2];
            }
            return(e);
        }
예제 #3
0
        bool FindNextPierced(Point start, Point end, ref CdtTriangle t, ref CdtEdge piercedEdge)
        {
            t = piercedEdge.GetOtherTriangle(t);
            if (t == null)
            {
                return(false);
            }
            var i = t.Edges.Index(piercedEdge);

            for (int j = i + 1; j <= i + 2; j++)
            {
                var pe = t.Edges[j];
                piercedEdge = PiercedEdgeQuery(pe, start, end, t);
                if (piercedEdge != null)
                {
                    //                    CdtSweeper.ShowFront(trs, null,
                    //                        new []{new LineSegment(e.SourcePoint,e.TargetPoint)}, new []{new LineSegment(pe.upperSite.Point,pe.lowerSite.Point)});
                    break;
                }
            }
            return(!PointIsInsideOfTriangle(end, t));
        }
예제 #4
0
 internal static bool EdgeIsPierced(CdtEdge e, Point source, Point target, CdtTriangle cdtTriangle) {
     var area0 = Point.SignedDoubledTriangleArea(e.upperSite.Point, source, target);
     var area1 = Point.SignedDoubledTriangleArea(e.lowerSite.Point, source, target);
     if (ApproximateComparer.Sign(area0) * ApproximateComparer.Sign(area1) > 0)
         return false;
     area0 = Point.SignedDoubledTriangleArea(e.upperSite.Point, e.lowerSite.Point, source);
     area1 = Point.SignedDoubledTriangleArea(e.upperSite.Point, e.lowerSite.Point, target);
     if (ApproximateComparer.Sign(area0) * ApproximateComparer.Sign(area1) > 0)
         return false;
     var otherT = e.GetOtherTriangle(cdtTriangle);
     if (otherT == null)
         return true;
     var otherSite = otherT.OppositeSite(e);
     area0 = Point.SignedDoubledTriangleArea(e.upperSite.Point, e.lowerSite.Point, otherSite.Point);
     return (ApproximateComparer.Sign(area0) * ApproximateComparer.Sign(area1) >= 0);
 }
예제 #5
0
 bool FindNextPierced(Point start, Point end, ref CdtTriangle t, ref CdtEdge piercedEdge) {
     t = piercedEdge.GetOtherTriangle(t);
     if (t == null)
         return false;
     var i = t.Edges.Index(piercedEdge);
     for (int j = i + 1; j <= i + 2; j++) {
         var pe = t.Edges[j];
         piercedEdge = PiercedEdgeQuery(pe, start, end, t);
         if (piercedEdge != null) {
             //                    CdtSweeper.ShowFront(trs, null, 
             //                        new []{new LineSegment(e.SourcePoint,e.TargetPoint)}, new []{new LineSegment(pe.upperSite.Point,pe.lowerSite.Point)});
             break;
         }
     }
     return !PointIsInsideOfTriangle(end, t);
 }
        internal void FindNextPierced()
        {
            Debug.Assert(negativeSign < positiveSign);

            /*List<DebugCurve> l = null;
             * if (db) {
             *  l = new List<DebugCurve>();
             *  l.Add(new DebugCurve(0.05, "red", new LineSegment(start, end)));
             *  l.Add(new DebugCurve(0.05, "blue", new LineSegment(piercedEdge.upperSite.Point, piercedEdge.lowerSite.Point)));
             *  l.Add(new DebugCurve(new Ellipse(3, 3, end)));
             *
             *  var ii = currentTriangle.Edges.Index(piercedEdge);
             *  for (int j = ii + 1; j <= ii + 2; j++)
             *      l.Add(new DebugCurve(0.05, "brown", new LineSegment(currentTriangle.Edges[j].upperSite.Point, currentTriangle.Edges[j].lowerSite.Point)));
             * }*/
            currentTriangle = currentPiercedEdge.GetOtherTriangle(currentTriangle);
//            ShowDebug(null,currentPiercedEdge,currentTriangle);

            /* if (db) {
             *   for (int j = 0; j <= 2; j++) {
             *       var piercedEdge = currentTriangle.Edges[j];
             *       if (piercedEdge == piercedEdge) continue;
             *       l.Add(new DebugCurve(0.05, new LineSegment(piercedEdge.upperSite.Point, piercedEdge.lowerSite.Point)));
             *   }
             *
             *   LayoutAlgorithmSettings.ShowDebugCurvesEnumeration(l.ToArray());
             * }*/
            if (currentTriangle == null)
            {
                currentPiercedEdge = null;
                return;
            }
            var i = currentTriangle.Edges.Index(currentPiercedEdge);
            int j; //pierced index
            var oppositeSite     = currentTriangle.Sites[i + 2];
            var oppositeSiteSign = GetHyperplaneSign(oppositeSite);

            if (negativeSign == 0)
            {
                Debug.Assert(positiveSign == 1);
                if (oppositeSiteSign == -1 || oppositeSiteSign == 0)
                {
                    negativeSign = oppositeSiteSign;
                    j            = i + 1;
                }
                else
                {
                    j = i + 2;
                }
            }
            else if (positiveSign == 0)
            {
                Debug.Assert(negativeSign == -1);
                if (oppositeSiteSign == 1 || oppositeSiteSign == 0)
                {
                    positiveSign = oppositeSiteSign;
                    j            = i + 2;
                }
                else
                {
                    j = i + 1;
                }
            }
            else if (oppositeSiteSign != positiveSign)
            {
                negativeSign = oppositeSiteSign;
                j            = i + 1;
            }
            else
            {
                Debug.Assert(negativeSign != oppositeSiteSign);
                positiveSign = oppositeSiteSign;
                j            = i + 2;
            }

            currentPiercedEdge =
                Point.SignedDoubledTriangleArea(end, currentTriangle.Sites[j].Point, currentTriangle.Sites[j + 1].Point) <
                -ApproximateComparer.DistanceEpsilon
                    ? currentTriangle.Edges[j]
                    : null;

//            ShowDebug(null,currentPiercedEdge, currentTriangle);
        }
 static CdtEdge FindNextEdgeOnPerimeter(CdtEdge e) {
     var t = e.CwTriangle ?? e.CcwTriangle;
     e = t.Edges[t.Edges.Index(e) + 2];
     while(e.CwTriangle != null && e.CcwTriangle != null) {
         t = e.GetOtherTriangle(t);
         e = t.Edges[t.Edges.Index(e) + 2];
     }
     return e;
 }