Inheritance: ILineSegment
コード例 #1
0
ファイル: LineSegment.cs プロジェクト: chris-tomich/Glyma
        public ILineSegment Resize(IntersectionDetector detector)
        {
            LineSegment lineSegment = new LineSegment(PointA, PointB, new Point(0, 0));
            lineSegment.Id = Id;
            Dictionary<ILineSegment, Point> intersections = detector.FindIntersections(lineSegment);

            foreach (KeyValuePair<ILineSegment, Point> intersection in intersections)
            {
                if (intersection.Key.TriangulationPoint.X != 0 && intersection.Key.TriangulationPoint.Y != 0)
                {
                    Point closestPoint;

                    if (intersection.Key.TriangulateClosestEndPoint(this, out closestPoint))
                    {
                        if (lineSegment.PointA == closestPoint)
                        {
                            lineSegment.PointA = intersection.Value;
                        }
                        else
                        {
                            lineSegment.PointB = intersection.Value;
                        }
                    }
                }
            }

            return lineSegment;
        }
コード例 #2
0
ファイル: LineSegment.cs プロジェクト: chris-tomich/Glyma
        public bool TriangulateClosestEndPoint(ILineSegment intersectingLineSegment, out Point closestPoint)
        {
            ILineSegment pointASegment = new LineSegment(intersectingLineSegment.PointA, TriangulationPoint);
            ILineSegment pointBSegment = new LineSegment(intersectingLineSegment.PointB, TriangulationPoint);

            IntersectionDetector detector = new IntersectionDetector();

            detector.Add(pointASegment);
            detector.Add(pointBSegment);

            ILineSegment closestSegment;
            Point closestSegmentIntersectionPoint;

            ILineSegment segment = new LineSegment(this.PointA, this.PointB, this.TriangulationPoint, true);

            if (detector.FindIntersection(segment, out closestSegment, out closestSegmentIntersectionPoint))
            {
                closestPoint = closestSegment.PointA;

                return true;
            }
            else
            {
                closestPoint = new Point(0, 0);

                return false;
            }
        }