void WriteEllipseInSvgStyle(Ellipse ellipse)
 {
     if (ApproximateComparer.Close(ellipse.ParStart, 0) && ApproximateComparer.Close(ellipse.ParEnd, 2 * Math.PI))
     {
         WriteFullEllipse(ellipse);
     }
     else
     {
         WriteEllepticalArc(ellipse);
     }
 }
Ejemplo n.º 2
0
        double SeparationCostForAdjacentBundleBases(BundleBase base0, BundleBase base1)
        {
            Debug.Assert(base0.Curve == base1.Curve);

            ICurve boundaryCurve = base0.Curve;
            double len           = IntervalsOverlapLength(base0.ParRight, base0.ParLeft, base1.ParRight, base1.ParLeft, boundaryCurve);
            double mn            = Math.Min(base0.Span, base1.Span);

            Debug.Assert(ApproximateComparer.LessOrEqual(len, mn));
            Debug.Assert(mn > 0);
            return(Math.Exp(len / mn * 10) - 1);
        }
Ejemplo n.º 3
0
        public PortEntryOnCurve(ICurve entryCurve, IEnumerable <Tuple <double, double> > parameterSpans)
        {
            EntryCurve = entryCurve;
#if TEST_MSAGL
            var polyline = entryCurve as Polyline;
            curveIsClosed = (polyline != null) ? polyline.Closed : ApproximateComparer.Close(EntryCurve.Start, EntryCurve.End);
#endif
            Spans = parameterSpans;
#if TEST_MSAGL
            TestSpans(entryCurve, parameterSpans, curveIsClosed);
#endif
        }
        static bool ParallelToDirection(VisibilityEdge edge, Directions direction)
        {
            switch (direction)
            {
            case Directions.North:
            case Directions.South:
                return(ApproximateComparer.Close(edge.SourcePoint.X, edge.TargetPoint.X));

            default:
                return(ApproximateComparer.Close(edge.SourcePoint.Y, edge.TargetPoint.Y));
            }
        }
 static LinkedPoint TrySplitHorizontalPoint(LinkedPoint horizontalPoint, Point point, bool xAligned)
 {
     Debug.Assert(ApproximateComparer.Close(horizontalPoint.Y, horizontalPoint.Next.Y));
     if (xAligned && horizontalPoint.X + ApproximateComparer.DistanceEpsilon < point.X &&
         point.X + ApproximateComparer.DistanceEpsilon < horizontalPoint.Next.X ||
         !xAligned && horizontalPoint.Next.X + ApproximateComparer.DistanceEpsilon < point.X &&
         point.X + ApproximateComparer.DistanceEpsilon < horizontalPoint.X)
     {
         horizontalPoint.SetNewNext(point);
         return(horizontalPoint.Next);
     }
     return(horizontalPoint);
 }
        /// <summary>
        ///     Gets the possible sides for the given label and the given derivative point.
        /// </summary>
        /// <returns>An enumeration of the possible sides (-1 or 1).</returns>
        static double[] GetPossibleSides(Label.PlacementSide side, Point derivative)
        {
            if (derivative.Length == 0)
            {
                side = Label.PlacementSide.Any;
            }

            switch (side)
            {
            case Label.PlacementSide.Port:
                return(new double[] { -1 });

            case Label.PlacementSide.Starboard:
                return(new double[] { 1 });

            case Label.PlacementSide.Top:
                if (ApproximateComparer.Close(derivative.X, 0))
                {
                    // If the line is vertical, Top becomes Left
                    return(GetPossibleSides(Label.PlacementSide.Left, derivative));
                }
                return(new double[] { derivative.X < 0 ? 1 : -1 });

            case Label.PlacementSide.Bottom:
                if (ApproximateComparer.Close(derivative.X, 0))
                {
                    // If the line is vertical, Bottom becomes Right
                    return(GetPossibleSides(Label.PlacementSide.Right, derivative));
                }
                return(new double[] { derivative.X < 0 ? -1 : 1 });

            case Label.PlacementSide.Left:
                if (ApproximateComparer.Close(derivative.Y, 0))
                {
                    // If the line is horizontal, Left becomes Top
                    return(GetPossibleSides(Label.PlacementSide.Top, derivative));
                }
                return(new double[] { derivative.Y < 0 ? -1 : 1 });

            case Label.PlacementSide.Right:
                if (ApproximateComparer.Close(derivative.Y, 0))
                {
                    // If the line is horizontal, Right becomes Bottom
                    return(GetPossibleSides(Label.PlacementSide.Bottom, derivative));
                }
                return(new double[] { derivative.Y < 0 ? 1 : -1 });

            default:
                return(new double[] { -1, 1 });
            }
        }
Ejemplo n.º 7
0
        internal IntersectionInfo(double pr0, double pr1, Point x, ICurve s0, ICurve s1)
        {
            par0   = pr0;
            par1   = pr1;
            this.x = x;
            seg0   = s0;
            seg1   = s1;
#if DETAILED_DEBUG
            System.Diagnostics.Debug.Assert(ApproximateComparer.Close(x, s0[pr0], ApproximateComparer.IntersectionEpsilon * 10),
                                            string.Format("intersection not at curve[param]; x = {0}, s0[pr0] = {1}, diff = {2}", x, s0[pr0], x - s0[pr0]));
            System.Diagnostics.Debug.Assert(ApproximateComparer.Close(x, s1[pr1], ApproximateComparer.IntersectionEpsilon * 10),
                                            string.Format("intersection not at curve[param]; x = {0}, s1[pr1] = {1}, diff = {2}", x, s1[pr1], x - s1[pr1]));
#endif
        }
Ejemplo n.º 8
0
        internal double GetWidth(IEnumerable <Metroline> metrolines, double edgeSeparation)
        {
            double width = 0;

            foreach (var metroline in metrolines)
            {
                width += metroline.Width;
            }
            int count = metrolines.Count();

            width += count > 0 ? (count - 1) * edgeSeparation : 0;
            Debug.Assert(ApproximateComparer.GreaterOrEqual(width, 0));
            return(width);
        }
Ejemplo n.º 9
0
        void InsertTilesRightHalf(Point p1, Point p2, Tuple <int, int> rightTile, List <Tuple <int, int> > tiles)
        {
            var leftTile = PointToTuple(p1);

            if (leftTile.Equals(rightTile) || ApproximateComparer.Close(p1, p2, ((double)TileWidth) / 10))
            {
                return;
            }
            tiles.Add(leftTile);
            var midPoint = (p1 + p2) / 2;

            InsertTilesLeftHalf(leftTile, p1, midPoint, tiles);
            InsertTilesRightHalf(midPoint, p2, rightTile, tiles);
        }
        /// <summary>
        /// Returns the trim curve
        /// </summary>
        /// <param name="start"></param>
        /// <param name="end"></param>
        /// <returns></returns>
        public ICurve Trim(double start, double end)
        {
            if (start > end)
            {
                throw new InvalidOperationException();//"wrong params in trimming");
            }
            Point p1 = start <= ParStart ? Start : (1 - start) * a + start * b;
            Point p2 = end >= ParEnd ? End : (1 - end) * a + end * b;

            if (ApproximateComparer.Close(start, end))
            {
                return(null);
            }
            return(new LineSegment(p1, p2));
        }
        //void show(params DebugCurve[] cs) {
        //    var l = new List<DebugCurve>();
        //    l.AddRange(anchors.Select(aa => new DebugCurve(100, 1, "red", aa.PolygonalBoundary)));
        //    l.AddRange(thinRightNodes.Select(n => n.Parallelogram).Select(p => new Polyline(p.Vertex(VertexId.Corner), p.Vertex(VertexId.VertexA),
        //          p.Vertex(VertexId.OtherCorner), p.Vertex(VertexId.VertexB))).Select(c => new DebugCurve(100, 3, "brown", c)));
        //    foreach (var le in this.edgePath.LayerEdges)
        //        l.Add(new DebugCurve(100, 1, "blue", new LineSegment(anchors[le.Source].Origin, anchors[le.Target].Origin)));
        //    l.AddRange(cs);
        //    LayoutAlgorithmSettings.ShowDebugCurvesEnumeration(l);
        //    // Database(db, thinRightNodes.Select(p=>new Polyline(p.Parallelogram.Vertex(VertexId.Corner), p.Parallelogram.Vertex(VertexId.VertexA),
        //    //p.Parallelogram.Vertex(VertexId.OtherCorner), p.Parallelogram.Vertex(VertexId.VertexB)){Closed=true}).ToArray());
        //}
#endif

        private bool PositionsAreLegal(double sax, double sbx, int sign, Anchor a, Anchor b, int middleNodeIndex)
        {
            if (!ApproximateComparer.Close(sax, sbx) && (sax - sbx) * sign > 0)
            {
                return(false);
            }
            Anchor mAnchor = anchors[middleNodeIndex];
            double mx      = MiddlePos(sax, sbx, a, b, mAnchor.Y);

            if (!MiddleAnchorLegal(mx, middleNodeIndex, mAnchor))
            {
                return(false);
            }

            return(!LineSegIntersectBound(new Point(sax, a.Bottom), new Point(sbx, b.Top)));
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Gain of bundles
        /// if a newPosition is not valid (e.g. intersect obstacles) the result is -inf
        /// </summary>
        internal double BundleGain(Station node, Point newPosition)
        {
            double gain = node.cachedBundleCost;

            foreach (var adj in node.Neighbors)
            {
                double lgain = BundleCost(node, adj, newPosition);
                if (ApproximateComparer.GreaterOrEqual(lgain, Inf))
                {
                    return(-Inf);
                }
                gain -= lgain;
            }

            return(gain);
        }
Ejemplo n.º 13
0
 /// <summary>
 /// Add an EdgeGeometry to route
 /// </summary>
 /// <param name="edgeGeometry"></param>
 public void AddEdgeGeometryToRoute(EdgeGeometry edgeGeometry)
 {
     ValidateArg.IsNotNull(edgeGeometry, "edgeGeometry");
     // The Port.Location values are not necessarily rounded by the caller.  The values
     // will be rounded upon acquisition in PortManager.cs.  PointComparer.Equal expects
     // all values to be rounded.
     if (!PointComparer.Equal(ApproximateComparer.Round(edgeGeometry.SourcePort.Location)
                              , ApproximateComparer.Round(edgeGeometry.TargetPort.Location)))
     {
         EdgeGeometries.Add(edgeGeometry);
     }
     else
     {
         selfEdges.Add(edgeGeometry);
     }
 }
Ejemplo n.º 14
0
 public static void VerifyPointsAreInOrOnHull(IEnumerable <Point> points, Polyline hull)
 {
     // A convex hull may not pick up points that are just barely outside the hull because GetTriangleOrientation won't
     // show a significant enough distance to consider them non-collinear.
     foreach (var point in points)
     {
         if (Curve.PointRelativeToCurveLocation(point, hull) == PointLocation.Outside)
         {
             var hullPoint = hull[hull.ClosestParameter(point)];
             if (!ApproximateComparer.CloseIntersections(point, hullPoint))
             {
                 Validate.Fail(String.Format("not CloseIntersections: initial point {0}, closest hull point {1}", point, hullPoint));
             }
         }
     }
 }
        private Curve ExtendCurveToEndpoints(Curve curve)
        {
            Point p = this.EdgePathPoint(0);

            if (!ApproximateComparer.Close(p, curve.Start))
            {
                Curve nc = new Curve();
                nc.AddSegs(new LineSegment(p, curve.Start), curve);
                curve = nc;
            }
            p = this.EdgePathPoint(edgePath.Count);
            if (!ApproximateComparer.Close(p, curve.End))
            {
                curve.AddSegment(new LineSegment(curve.End, p));
            }
            return(curve);
        }
Ejemplo n.º 16
0
        VisibilityVertex GlueOrAddToPolylineAndVisGraph(Point[] polySplitArray, int i, VisibilityVertex v, Polyline poly)
        {
            var ip = polySplitArray[i];

            if (ApproximateComparer.Close(v.Point, ip))
            {
                return(v); // gluing ip to the previous point on the polyline
            }
            if (ApproximateComparer.Close(ip, poly.StartPoint.Point))
            {
                var vv = VisGraph.FindVertex(poly.StartPoint.Point);
                Debug.Assert(vv != null);
                return(vv);
            }
            poly.AddPoint(ip);
            return(VisGraph.AddVertex(ip));
        }
        private Curve ExtendCurveToEndpoints(Curve curve)
        {
            Point p = headSite.Point;

            if (!ApproximateComparer.Close(p, curve.Start))
            {
                Curve nc = new Curve();
                nc.AddSegs(new LineSegment(p, curve.Start), curve);
                curve = nc;
            }
            p = TailSite.Point;
            if (!ApproximateComparer.Close(p, curve.End))
            {
                curve.AddSegment(new LineSegment(curve.End, p));
            }
            return(curve);
        }
Ejemplo n.º 18
0
        /// <summary>
        /// calculates new curve ends that are the arrowhead starts
        /// </summary>
        /// <param name="edgeGeometry">The edgeGeometry.Curve is trimmed already by the node boundaries</param>
        /// <returns></returns>
        internal static bool CalculateArrowheads(EdgeGeometry edgeGeometry)
        {
            ValidateArg.IsNotNull(edgeGeometry, "edgeGeometry");

            if (edgeGeometry.SourceArrowhead == null && edgeGeometry.TargetArrowhead == null)
            {
                return(true);
            }

            double parStart, parEnd;

            if (!FindTrimStartForArrowheadAtSource(edgeGeometry, out parStart))
            {
                return(false);
            }

            if (!FindTrimEndForArrowheadAtTarget(edgeGeometry, out parEnd))
            {
                return(false);
            }

            if (parStart > parEnd - ApproximateComparer.IntersectionEpsilon || ApproximateComparer.CloseIntersections(edgeGeometry.Curve[parStart], edgeGeometry.Curve[parEnd]))
            {
                return(false); //after the trim nothing would be left of the curve
            }
            var c = edgeGeometry.Curve.Trim(parStart, parEnd);

            if (c == null)
            {
                return(false);
            }

            if (edgeGeometry.SourceArrowhead != null)
            {
                edgeGeometry.SourceArrowhead.TipPosition = PlaceTip(c.Start, edgeGeometry.Curve.Start, edgeGeometry.SourceArrowhead.Offset);
            }

            if (edgeGeometry.TargetArrowhead != null)
            {
                edgeGeometry.TargetArrowhead.TipPosition = PlaceTip(c.End, edgeGeometry.Curve.End, edgeGeometry.TargetArrowhead.Offset);
            }

            edgeGeometry.Curve = c;

            return(true);
        }
 void ProcessEvent(LinkedPoint linkedPoint, double z)
 {
     if (ApproximateComparer.Close(linkedPoint.Next.Point.X, linkedPoint.Point.X))
     {
         if (z == Low(linkedPoint))
         {
             ProcessLowLinkedPointEvent(linkedPoint);
         }
         else
         {
             ProcessHighLinkedPointEvent(linkedPoint);
         }
     }
     else
     {
         IntersectWithTree(linkedPoint);
     }
 }
Ejemplo n.º 20
0
        /// <summary>
        /// find a cut point for 2 segments
        /// </summary>
        /// <returns>true if the segment interiors intersect</returns>
        double RegularCut(double l1, double r1, double l2, double r2, double span1, double span2)
        {
            double cutParam = (span1 * r2 + span2 * l1) / (span1 + span2);
            double mn       = Math.Min(r1, r2);
            double mx       = Math.Max(l1, l2);

            Debug.Assert(ApproximateComparer.LessOrEqual(mx, cutParam) && ApproximateComparer.LessOrEqual(cutParam, mn));
            if (cutParam < mx)
            {
                cutParam = mx;
            }
            if (cutParam > mn)
            {
                cutParam = mn;
            }

            return(cutParam);
        }
        private static Point GetBarycenterOfUniquePortLocations(IEnumerable <VisibilityVertex> vertices)
        {
            var center = new Point();
            VisibilityVertex prevVertex = null;
            int count = 0;

            foreach (var vertex in vertices.OrderBy(s => s.Point))
            {
                if ((prevVertex != null) && ApproximateComparer.CloseIntersections(vertex.Point, prevVertex.Point))
                {
                    continue;
                }
                prevVertex = vertex;
                ++count;
                center += vertex.Point;
            }
            return(center / count);
        }
Ejemplo n.º 22
0
        internal void ExtendEdgeChain(VisibilityVertex startVertex, Rectangle limitRect, LineSegment maxVisibilitySegment,
                                      PointAndCrossingsList pacList, bool isOverlapped)
        {
            var dir = PointComparer.GetDirections(maxVisibilitySegment.Start, maxVisibilitySegment.End);

            if (dir == Directions.None)
            {
                return;
            }

            Debug.Assert(CompassVector.IsPureDirection(dir), "impure max visibility segment");

            // Shoot the edge chain out to the shorter of max visibility or intersection with the limitrect.
            StaticGraphUtility.Assert(PointComparer.Equal(maxVisibilitySegment.Start, startVertex.Point) ||
                                      (PointComparer.GetPureDirection(maxVisibilitySegment.Start, startVertex.Point) == dir)
                                      , "Inconsistent direction found", ObstacleTree, VisGraph);
            double oppositeFarBound      = StaticGraphUtility.GetRectangleBound(limitRect, dir);
            Point  maxDesiredSplicePoint = StaticGraphUtility.IsVertical(dir)
                                    ? ApproximateComparer.Round(new Point(startVertex.Point.X, oppositeFarBound))
                                    : ApproximateComparer.Round(new Point(oppositeFarBound, startVertex.Point.Y));

            if (PointComparer.Equal(maxDesiredSplicePoint, startVertex.Point))
            {
                // Nothing to do.
                return;
            }
            if (PointComparer.GetPureDirection(startVertex.Point, maxDesiredSplicePoint) != dir)
            {
                // It's in the opposite direction, so no need to do anything.
                return;
            }

            // If maxDesiredSplicePoint is shorter, create a new shorter segment.  We have to pass both segments
            // through to the worker function so it knows whether it can go past maxDesiredSegment (which may be limited
            // by limitRect).
            var maxDesiredSegment = maxVisibilitySegment;

            if (PointComparer.GetDirections(maxDesiredSplicePoint, maxDesiredSegment.End) == dir)
            {
                maxDesiredSegment = new LineSegment(maxDesiredSegment.Start, maxDesiredSplicePoint);
            }

            ExtendEdgeChain(startVertex, dir, maxDesiredSegment, maxVisibilitySegment, pacList, isOverlapped);
        }
Ejemplo n.º 23
0
/*
 *      ICurve Ls(int p0, int p1) {
 *          return new LineSegment(P[p0].Point, Q[p1].Point);
 *      }
 */



        //chunks go clockwise from p1 to p2 and from q2 to q1
        void FindClosestPoints(ref int p1, ref int p2, ref int q2, ref int q1, out Point pClosest, out Point qClosest)
        {
            while (ChunksAreLong(p2, p1, q2, q1))
            {
                ShrinkChunks(ref p2, ref p1, ref q2, ref q1);
            }


            if (p1 == p2)
            {
                pClosest = P[p2].Point;
                if (q1 == q2)
                {
                    qClosest = Q[q1].Point;
                }
                else
                {
//                    if(debug) LayoutAlgorithmSettings.Show(new LineSegment(P.Pnt(p2), Q.Pnt(q2)), new LineSegment(P.Pnt(p1), Q.Pnt(q1)), P.Polyline, Q.Polyline);
                    qClosest = Point.ClosestPointAtLineSegment(pClosest, Q[q1].Point, Q[q2].Point);
                    if (ApproximateComparer.Close(qClosest, Q.Pnt(q1)))
                    {
                        q2 = q1;
                    }
                    else if (ApproximateComparer.Close(qClosest, Q.Pnt(q2)))
                    {
                        q1 = q2;
                    }
                }
            }
            else
            {
                Debug.Assert(q1 == q2);
                qClosest = Q[q1].Point;
                pClosest = Point.ClosestPointAtLineSegment(qClosest, P[p1].Point, P[p2].Point);
                if (ApproximateComparer.Close(pClosest, P.Pnt(p1)))
                {
                    p2 = p1;
                }
                else if (ApproximateComparer.Close(qClosest, P.Pnt(p2)))
                {
                    p1 = p2;
                }
            }
        }
        void IntersectWithTree(LinkedPoint horizontalPoint)
        {
            double left, right;
            bool   xAligned;

            Debug.Assert(ApproximateComparer.Close(horizontalPoint.Y, horizontalPoint.Next.Y));
            var y = horizontalPoint.Y;

            if (horizontalPoint.Point.X < horizontalPoint.Next.Point.X)
            {
                left     = horizontalPoint.Point.X;
                right    = horizontalPoint.Next.Point.X;
                xAligned = true;
            }
            else
            {
                right    = horizontalPoint.Point.X;
                left     = horizontalPoint.Next.Point.X;
                xAligned = false;
            }
            if (xAligned)
            {
                for (var node = tree.FindFirst(p => left <= p.Point.X);
                     node != null && node.Item.Point.X <= right;
                     node = tree.Next(node))
                {
                    var p = new Point(node.Item.Point.X, y);
                    horizontalPoint = TrySplitHorizontalPoint(horizontalPoint, p, true);
                    TrySplitVerticalPoint(node.Item, p);
                }
            }
            else  //xAligned==false
            {
                for (var node = tree.FindLast(p => p.Point.X <= right);
                     node != null && node.Item.Point.X >= left;
                     node = tree.Previous(node))
                {
                    var p = new Point(node.Item.Point.X, y);
                    horizontalPoint = TrySplitHorizontalPoint(horizontalPoint, p, false);
                    TrySplitVerticalPoint(node.Item, p);
                }
            }
        }
Ejemplo n.º 25
0
        internal static void RoundVertices(Polyline polyline)
        {
            // Following creation of the padded border, round off the vertices for consistency
            // in later operations (intersections and event ordering).
            PolylinePoint ppt = polyline.StartPoint;

            do
            {
                ppt.Point = ApproximateComparer.Round(ppt.Point);
                ppt       = ppt.NextOnPolyline;
            } while (ppt != polyline.StartPoint);
            RemoveCloseAndCollinearVerticesInPlace(polyline);

            // We've modified the points so the BoundingBox may have changed; force it to be recalculated.
            polyline.RequireInit();

            // Verify that the polyline is still clockwise.
            Debug.Assert(polyline.IsClockwise(), "Polyline is not clockwise after RoundVertices");
        }
        void FindPiercedTriangle(RBNode <CdtFrontElement> v)
        {
            var e      = v.Item.Edge;
            var t      = e.CcwTriangle ?? e.CwTriangle;
            var eIndex = t.Edges.Index(e);

            for (int i = 1; i <= 2; i++)
            {
                var ei          = t.Edges[i + eIndex];
                var signedArea0 = ApproximateComparer.Sign(Point.SignedDoubledTriangleArea(ei.lowerSite.Point, a.Point, b.Point));
                var signedArea1 = ApproximateComparer.Sign(Point.SignedDoubledTriangleArea(ei.upperSite.Point, a.Point, b.Point));
                if (signedArea1 * signedArea0 <= 0)
                {
                    piercedTriangle = t;
                    piercedEdge     = ei;
                    break;
                }
            }
        }
        public void NestedDeepTranslationTest()
        {
            EnableDebugViewer();
            List <Node> nodes =
                new[]
            {
                new Node(CurveFactory.CreateRectangle(30, 20, new Point())),
                new Node(CurveFactory.CreateRectangle(30, 20, new Point(100, 0))),
                new Node(CurveFactory.CreateRectangle(30, 20, new Point(200, 0)))
            }
            .ToList();
            var graph = new GeometryGraph();

            nodes.ForEach(graph.Nodes.Add);
            nodes.Add(CreateCluster(nodes.Take(2), 10));

            Assert.AreEqual(nodes[3].BoundingBox.Width, 150, "Inner Cluster has incorrect width");
            Assert.AreEqual(nodes[3].BoundingBox.Height, 40, "Inner Cluster has incorrect height");

            nodes.Add(CreateCluster(new[] { nodes[3], nodes[2] }, 10));
            graph.RootCluster = new Cluster(new Node[] { }, new[] { (Cluster)nodes[4] });
            List <Edge> edges = new[]
            {
                new Edge(nodes[0], nodes[1]), new Edge(nodes[0], nodes[2]), new Edge(nodes[2], nodes[1]), new Edge(nodes[3], nodes[2]),
                new Edge(nodes[2], nodes[3])
            }
            .ToList();

            edges.ForEach(graph.Edges.Add);
            RouteEdges(graph, 10);
            var bounds = (from v in nodes select v.BoundingBox).Concat(from e in edges select e.BoundingBox).ToList();
            var delta  = new Point(10, 20);

            ((Cluster)nodes[4]).DeepTranslation(delta, true);
            ShowGraphInDebugViewer(graph);
            IEnumerable <GeometryObject> geometryObjects = (from v in nodes select(GeometryObject) v).Concat(from e in edges select(GeometryObject) e);

            foreach (var b in geometryObjects.Zip(bounds, (g, b) => new { G = g, Original = b, Target = g.BoundingBox }))
            {
                Assert.IsTrue(ApproximateComparer.Close(Rectangle.Translate(b.Original, delta), b.Target), "object was not translated: " + b.G);
            }
        }
Ejemplo n.º 28
0
        static object TryCreateFeatureWhichIsNotSite(PolylinePoint pp, CdtTriangle triangle)
        {
            Debug.Assert(!triangle.Sites.Any(s => ApproximateComparer.Close(pp.Point, s.Point)));
            var a0 = Point.GetTriangleOrientation(pp.Point, triangle.Sites[0].Point, triangle.Sites[1].Point);

            if (a0 == TriangleOrientation.Clockwise)
            {
                return(null);
            }

            var a1 = Point.GetTriangleOrientation(pp.Point, triangle.Sites[1].Point, triangle.Sites[2].Point);

            if (a1 == TriangleOrientation.Clockwise)
            {
                return(null);
            }

            var a2 = Point.GetTriangleOrientation(pp.Point, triangle.Sites[2].Point, triangle.Sites[3].Point);

            if (a2 == TriangleOrientation.Clockwise)
            {
                return(null);
            }

            if (a0 == TriangleOrientation.Counterclockwise &&
                a1 == TriangleOrientation.Counterclockwise &&
                a2 == TriangleOrientation.Counterclockwise)
            {
                return(triangle);
            }

            if (a0 == TriangleOrientation.Collinear)
            {
                return(triangle.Edges[0]);
            }
            if (a1 == TriangleOrientation.Collinear)
            {
                return(triangle.Edges[1]);
            }
            Debug.Assert(a2 == TriangleOrientation.Collinear);
            return(triangle.Edges[2]);
        }
 // Make sure that we intersect the object space.
 static internal double MungeIntersect(double site, double intersect, double start, double end)
 {
     if (site < intersect)
     {
         double min = Math.Min(start, end);
         if (intersect < min)
         {
             intersect = min;
         }
     }
     else if (site > intersect)
     {
         double max = Math.Max(start, end);
         if (intersect > max)
         {
             intersect = max;
         }
     }
     return(ApproximateComparer.Round(intersect));
 }
Ejemplo n.º 30
0
        CdtSite LeftCase(CdtSite pi, RBNode <CdtFrontElement> hittedFrontElementNode, out CdtSite rightSite)
        {
            //left case
            //                if(db)ShowFrontWithSite(pi, new LineSegment(pi.Point, hittedFrontElementNode.Item.Edge.upperSite.Point), new LineSegment(pi.Point, hittedFrontElementNode.Item.Edge.lowerSite.Point));
            Debug.Assert(ApproximateComparer.Close(pi.Point.X, hittedFrontElementNode.Item.X));
            var hittedFrontElement = hittedFrontElementNode.Item;

            InsertAndLegalizeTriangle(pi, hittedFrontElement);
            var prevToHitted = front.Previous(hittedFrontElementNode);
            var leftSite     = prevToHitted.Item.LeftSite;

            rightSite = hittedFrontElementNode.Item.RightSite;
            //                if(db)ShowFrontWithSite(pi, new LineSegment(pi.Point, leftSite.Point), new LineSegment(pi.Point, prevToHitted.Item.RightSite.Point));
            InsertAndLegalizeTriangle(pi, prevToHitted.Item);
            front.DeleteNodeInternal(prevToHitted);
            var d = front.Remove(hittedFrontElement);

            Debug.Assert(d != null);
            return(leftSite);
        }