private void ProcessPolygonQ(Polygon q)
        {
            TangentPair tangentPair = new TangentPair(currentPolygon, q);

            if (this.useLeftPTangents)
            {
                tangentPair.CalculateLeftTangents();
            }
            else
            {
                tangentPair.CalculateRightTangents();
            }
            Tuple <int, int> couple = useLeftPTangents ? tangentPair.leftPLeftQ : tangentPair.rightPLeftQ;

            Tangent t0 = new Tangent(currentPolygon[couple.Item1], q[couple.Item2]);

            t0.IsLow = true;
            t0.SeparatingPolygons = !this.useLeftPTangents;
            couple = useLeftPTangents ? tangentPair.leftPRightQ : tangentPair.rightPRightQ;
            Tangent t1 = new Tangent(currentPolygon[couple.Item1], q[couple.Item2]);

            t1.IsLow = false;
            t1.SeparatingPolygons = this.useLeftPTangents;
            t0.Comp = t1;
            t1.Comp = t0;

            this.tangents.Add(t0);
            this.tangents.Add(t1);
            this.diagonals.Add(new Diagonal(t0, t1));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Distance between two polygons
        /// p and q are the closest points
        /// The function doesn't work if the polygons intersect each other
        /// </summary>
        static public double Distance(Polygon a, Polygon b, out Point p, out Point q)
        {
            var tp = new TangentPair(a, b);

            tp.FindClosestPoints(out p, out q);
#if TEST_MSAGL
            if (!ApproximateComparer.Close((p - q).Length, TestPolygonDist(a, b)))
            {
                using (var stream = File.Open(@"c:\tmp\polygonBug", FileMode.Create)) {
                    var bf = new BinaryFormatter();
                    bf.Serialize(stream, a);
                    bf.Serialize(stream, b);
                }
                LayoutAlgorithmSettings.ShowDebugCurves?.Invoke(
                    new DebugCurve(100, 0.1, "red", a.Polyline),
                    new DebugCurve(100, 0.1, "blue", b.Polyline),
                    new DebugCurve(100, 0.1, "black", new LineSegment(p, q)));
                System.Diagnostics.Debug.Fail("wrong distance between two polygons");
            }
#endif
            return((p - q).Length);
        }
        private void ProcessPolygonQ(Polygon q) {
            TangentPair tangentPair = new TangentPair(currentPolygon, q);
            if (this.useLeftPTangents)
                tangentPair.CalculateLeftTangents();
            else
                tangentPair.CalculateRightTangents();
            Tuple<int, int> couple = useLeftPTangents ? tangentPair.leftPLeftQ : tangentPair.rightPLeftQ;

            Tangent t0 = new Tangent(currentPolygon[couple.Item1], q[couple.Item2]);
            t0.IsLow = true;
            t0.SeparatingPolygons = !this.useLeftPTangents;
            couple = useLeftPTangents ? tangentPair.leftPRightQ : tangentPair.rightPRightQ;
            Tangent t1 = new Tangent(currentPolygon[couple.Item1], q[couple.Item2]);
            t1.IsLow = false;
            t1.SeparatingPolygons = this.useLeftPTangents;
            t0.Comp = t1;
            t1.Comp = t0;

            this.tangents.Add(t0);
            this.tangents.Add(t1);
            this.diagonals.Add(new Diagonal(t0, t1));
        }
        /// <summary>
        /// Distance between two polygons
        /// p and q are the closest points
        /// The function doesn't work if the polygons intersect each other
        /// </summary>
        static public double Distance(Polygon a, Polygon b, out Point p, out Point q) {
            var tp = new TangentPair(a, b);
            tp.FindClosestPoints(out p, out q);
#if TEST_MSAGL
            if(!ApproximateComparer.Close((p - q).Length,TestPolygonDist(a,b))) {
                using(var stream = File.Open(@"c:\tmp\polygonBug",FileMode.Create)) {
                    var bf = new BinaryFormatter();
                    bf.Serialize(stream, a);
                    bf.Serialize(stream, b);                    
                }

                LayoutAlgorithmSettings.ShowDebugCurves(
                    new DebugCurve(100, 0.1, "red", a.Polyline),
                    new DebugCurve(100, 0.1, "blue", b.Polyline),
                    new DebugCurve(100, 0.1, "black", new LineSegment(p, q)));
                System.Diagnostics.Debug.Fail("wrong distance between two polygons");
            }
#endif
            return (p - q).Length;
        }