/// <summary> /// Chooses in which form to draw line, as common line or pattern /// </summary> void ApplyPattern() { if (_options.LinePattern == null) { // using line settings _options.UseLinePattern = false; } else if (_options.LinePattern.Count == 1 && _options.LinePattern.get_Line(0).LineType == tkLineType.lltSimple) { // the pattern can be represented as a single line // we need to copy the options only, as all settings were set to pattern ILineSegment line = _options.LinePattern.get_Line(0); if (line != null) { _options.LineStipple = line.LineStyle; _options.LineWidth = line.LineWidth; _options.LineColor = line.Color; } _options.UseLinePattern = false; } else { // line pattern _options.UseLinePattern = true; } }
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); } }
/// <summary> /// Initializes a new instance of the <see cref="Polygon" /> class. /// </summary> /// <param name="segment">The segment.</param> public Polygon(ILineSegment segment) { this.LineSegments = ImmutableArray.Create(segment); this.innerPath = new InternalPath(segment, true); this.path = new PolygonPath(this); this.Paths = ImmutableArray.Create <IPath>(this.path); }
/// <summary> /// /// </summary> /// <param name="p"></param> /// <param name="seg"></param> private void TestLineSegment(ICoordinate p, ILineSegment seg) { double xInt; // x intersection of segment with ray double x1; // translated coordinates double y1; double x2; double y2; /* * Test if segment crosses ray from test point in positive x direction. */ ICoordinate p1 = seg.P0; ICoordinate p2 = seg.P1; x1 = p1.X - p.X; y1 = p1.Y - p.Y; x2 = p2.X - p.X; y2 = p2.Y - p.Y; if (((y1 > 0) && (y2 <= 0)) || ((y2 > 0) && (y1 <= 0))) { /* * segment straddles x axis, so compute intersection. */ xInt = RobustDeterminant.SignOfDet2x2(x1, y1, x2, y2) / (y2 - y1); /* * crosses ray if strictly positive intersection. */ if (0.0 < xInt) { crossings++; } } }
/// <summary> /// /// </summary> /// <param name="pts"></param> /// <param name="seg"></param> /// <param name="startIndex"></param> /// <returns></returns> private int FindMaxPerpDistance(IList <Coordinate> pts, ILineSegment seg, int startIndex) { double maxPerpDistance = seg.DistancePerpendicular(pts[startIndex]); double nextPerpDistance = maxPerpDistance; int maxIndex = startIndex; int nextIndex = maxIndex; while (nextPerpDistance >= maxPerpDistance) { maxPerpDistance = nextPerpDistance; maxIndex = nextIndex; nextIndex = NextIndex(pts, maxIndex); nextPerpDistance = seg.DistancePerpendicular(pts[nextIndex]); } // found maximum width for this segment - update global min dist if appropriate if (maxPerpDistance < _minWidth) { _minPtIndex = maxIndex; _minWidth = maxPerpDistance; _minWidthPt = pts[_minPtIndex]; _minBaseSeg = new LineSegment(seg); } return(maxIndex); }
/// <summary> /// This should only be used if the Intersection is not actually required because it uses the Intersection method /// and returns false if the return value is null. /// </summary> /// <param name="self">The <c>IEnvelope</c> that is being extended by this method</param> /// <param name="segment">The segment to be tested against this envelope.</param> /// <returns>The line segment to compare against.</returns> public static bool Intersects(this IEnvelope self, ILineSegment segment) { if (self.Intersection(segment) != null) { return(true); } return(false); }
internal static ILineSegment GetMockLineSegment(string text, bool isATag = false) { ILineSegment lineSegment = Substitute.For <ILineSegment>(); lineSegment.DisplayText.Returns(text); lineSegment.IsTag.Returns(isATag); return(lineSegment); }
/// <summary> /// Gets an array of 4 line segments working clockwise from the top segment. /// </summary> /// <param name="self">The IEnvelope to use with this method</param> public static ILineSegment[] BorderSegments(this IEnvelope self) { ILineSegment[] result = new ILineSegment[4]; result[0] = self.TopBorder(); result[1] = self.RightBorder(); result[2] = self.BottomBorder(); result[3] = self.LeftBorder(); return result; }
/// <summary> /// Returns the intersection of the specified segment with this bounding box. If there is no intersection, /// then this returns null. If the intersection is a corner, then the LineSegment will be degenerate, /// that is both the coordinates will be the same. Otherwise, the segment will be returned so that the /// direction is the same as the original segment. /// </summary> /// <param name="self">The IEnvelope to use with this method</param> /// <param name="segment">The LineSegment to intersect.</param> /// <returns>An ILineSegment that is cropped to fit within the bounding box.</returns> public static ILineSegment Intersection(this IEnvelope self, ILineSegment segment) { if (self == null) { return(null); } if (self.IsNull) { return(null); } if (segment == null) { return(null); } // If the line segment is completely contained by this envelope, simply return the original. if (self.Contains(segment.P0) && self.Contains(segment.P1)) { return(segment); } int count = 0; Coordinate[] borderPoints = new Coordinate[2]; ILineSegment[] border = self.BorderSegments(); for (int i = 0; i < 4; i++) { borderPoints[count] = border[i].Intersection(segment); if (borderPoints[count] != null) { count++; if (count > 1) { break; } } } // If there are two intersections, the line crosses this envelope if (count == 2) { Vector v = new Vector(segment.P0, segment.P1); Vector t = new Vector(borderPoints[0], borderPoints[1]); return(t.Dot(v) < 0 ? new LineSegment(borderPoints[1], borderPoints[0]) : new LineSegment(borderPoints[0], borderPoints[1])); } // if there is only one intersection, we probably have one point contained and one point not-contained if (count == 1) { if (self.Contains(segment.P0)) { // P1 got cropped, so make a line from p0 to the cropped point return(new LineSegment(segment.P0, borderPoints[0])); } return(self.Contains(segment.P1) ? new LineSegment(borderPoints[0], segment.P1) : new LineSegment(borderPoints[0], borderPoints[0])); } return(null); }
/// <summary> /// Gets an array of 4 line segments working clockwise from the top segment. /// </summary> /// <param name="self">The IEnvelope to use with this method</param> public static ILineSegment[] BorderSegments(this IEnvelope self) { ILineSegment[] result = new ILineSegment[4]; result[0] = self.TopBorder(); result[1] = self.RightBorder(); result[2] = self.BottomBorder(); result[3] = self.LeftBorder(); return(result); }
/// <summary> /// Transforms the rectangle using specified matrix. /// </summary> /// <param name="matrix">The matrix.</param> /// <returns> /// A new path with the matrix applied to it. /// </returns> public IPath Transform(Matrix3x2 matrix) { var segments = new ILineSegment[this.LineSegments.Length]; var i = 0; foreach (var s in this.LineSegments) { segments[i++] = s.Transform(matrix); } return(new Path(segments)); }
private void VerifyPoints(PointF[] expectedPoints, IPath path) { Path innerPath = Assert.IsType <Path>(path); ILineSegment segment = Assert.Single(innerPath.LineSegments); CubicBezierLineSegment bezierSegment = Assert.IsType <CubicBezierLineSegment>(segment); Assert.Equal(expectedPoints, bezierSegment.ControlPoints.ToArray()); ISimplePath simplePath = Assert.Single(path.Flatten()); Assert.False(simplePath.IsClosed); }
public Arrow(ILineSegment arrowCoordinates) { _arrowCoordinates = arrowCoordinates; _sprite = new Line(); _sprite.Tag = this; _sprite.Stroke = new SolidColorBrush(Color.FromArgb(255, 0, 0, 0)); _sprite.StrokeThickness = 2.0; _sprite.X1 = _arrowCoordinates.PointA.X; _sprite.Y1 = _arrowCoordinates.PointA.Y; _sprite.X2 = _arrowCoordinates.PointB.X; _sprite.Y2 = _arrowCoordinates.PointB.Y; }
public bool FindIntersection(ILineSegment testSegment, out ILineSegment intersection, out Point intersectionCoordinates) { double testSegmentCoefficient = testSegment.Coefficient; double testSegmentConstant = testSegment.Constant; foreach (ILineSegment lineSegment in _lineSegments) { double lineSegmentCoefficient = lineSegment.Coefficient; if (testSegmentCoefficient == lineSegmentCoefficient) { continue; } double lineSegmentConstant = lineSegment.Constant; double constantDifference = lineSegmentConstant - testSegmentConstant; double coefficientDifference = testSegmentCoefficient - lineSegmentCoefficient; double yIntersectCoordinate = ((testSegmentCoefficient * constantDifference) / coefficientDifference) + testSegmentConstant; double xIntersectCoordinate = constantDifference / coefficientDifference; //if (!((yIntersectCoordinate > testSegment.PointA.Y && yIntersectCoordinate > testSegment.PointB.Y) || (yIntersectCoordinate < testSegment.PointA.Y && yIntersectCoordinate < testSegment.PointB.Y)) || testSegment.IgnoreLength) //{ // if (!((xIntersectCoordinate > testSegment.PointA.X && xIntersectCoordinate > testSegment.PointB.X) || (xIntersectCoordinate < testSegment.PointA.X && xIntersectCoordinate < testSegment.PointB.X)) || testSegment.IgnoreLength) // { // if (!((yIntersectCoordinate > lineSegment.PointA.Y && yIntersectCoordinate > lineSegment.PointB.Y) || (yIntersectCoordinate < lineSegment.PointA.Y && yIntersectCoordinate < lineSegment.PointB.Y)) || lineSegment.IgnoreLength) // { //if (!((xIntersectCoordinate > lineSegment.PointA.X && xIntersectCoordinate > lineSegment.PointB.X) || (xIntersectCoordinate < lineSegment.PointA.X && xIntersectCoordinate < lineSegment.PointB.X)) || lineSegment.IgnoreLength) //{ if ((yIntersectCoordinate < lineSegment.PointA.Y && yIntersectCoordinate > lineSegment.PointB.Y) || (yIntersectCoordinate > lineSegment.PointA.Y && yIntersectCoordinate < lineSegment.PointB.Y) || lineSegment.IgnoreLength) { if ((xIntersectCoordinate < lineSegment.PointA.X && xIntersectCoordinate > lineSegment.PointB.X) || (xIntersectCoordinate > lineSegment.PointA.X && xIntersectCoordinate < lineSegment.PointB.X) || lineSegment.IgnoreLength) { intersection = lineSegment; intersectionCoordinates = new Point(xIntersectCoordinate, yIntersectCoordinate); return(true); } } //} // } // } //} } intersection = null; intersectionCoordinates = new Point(); return(false); }
public bool FindIntersection(ILineSegment testSegment, out ILineSegment intersection, out Point intersectionCoordinates) { double testSegmentCoefficient = testSegment.Coefficient; double testSegmentConstant = testSegment.Constant; foreach (ILineSegment lineSegment in _lineSegments) { double lineSegmentCoefficient = lineSegment.Coefficient; if (testSegmentCoefficient == lineSegmentCoefficient) { continue; } double lineSegmentConstant = lineSegment.Constant; double constantDifference = lineSegmentConstant - testSegmentConstant; double coefficientDifference = testSegmentCoefficient - lineSegmentCoefficient; double yIntersectCoordinate = ((testSegmentCoefficient * constantDifference) / coefficientDifference) + testSegmentConstant; double xIntersectCoordinate = constantDifference / coefficientDifference; //if (!((yIntersectCoordinate > testSegment.PointA.Y && yIntersectCoordinate > testSegment.PointB.Y) || (yIntersectCoordinate < testSegment.PointA.Y && yIntersectCoordinate < testSegment.PointB.Y)) || testSegment.IgnoreLength) //{ // if (!((xIntersectCoordinate > testSegment.PointA.X && xIntersectCoordinate > testSegment.PointB.X) || (xIntersectCoordinate < testSegment.PointA.X && xIntersectCoordinate < testSegment.PointB.X)) || testSegment.IgnoreLength) // { // if (!((yIntersectCoordinate > lineSegment.PointA.Y && yIntersectCoordinate > lineSegment.PointB.Y) || (yIntersectCoordinate < lineSegment.PointA.Y && yIntersectCoordinate < lineSegment.PointB.Y)) || lineSegment.IgnoreLength) // { //if (!((xIntersectCoordinate > lineSegment.PointA.X && xIntersectCoordinate > lineSegment.PointB.X) || (xIntersectCoordinate < lineSegment.PointA.X && xIntersectCoordinate < lineSegment.PointB.X)) || lineSegment.IgnoreLength) //{ if ((yIntersectCoordinate < lineSegment.PointA.Y && yIntersectCoordinate > lineSegment.PointB.Y) || (yIntersectCoordinate > lineSegment.PointA.Y && yIntersectCoordinate < lineSegment.PointB.Y) || lineSegment.IgnoreLength) { if ((xIntersectCoordinate < lineSegment.PointA.X && xIntersectCoordinate > lineSegment.PointB.X) || (xIntersectCoordinate > lineSegment.PointA.X && xIntersectCoordinate < lineSegment.PointB.X) || lineSegment.IgnoreLength) { intersection = lineSegment; intersectionCoordinates = new Point(xIntersectCoordinate, yIntersectCoordinate); return true; } } //} // } // } //} } intersection = null; intersectionCoordinates = new Point(); return false; }
/// <summary> /// Transforms the rectangle using specified matrix. /// </summary> /// <param name="matrix">The matrix.</param> /// <returns> /// A new path with the matrix applied to it. /// </returns> public virtual IPath Transform(Matrix3x2 matrix) { if (matrix.IsIdentity) { return this; } var segments = new ILineSegment[this.lineSegments.Length]; for (int i = 0; i < this.LineSegments.Count; i++) { segments[i] = this.lineSegments[i].Transform(matrix); } return new Path(segments); }
public void FindCurrentHitWord(out int startAt, out int len) { if (_currentTextRun == null) { startAt = 0; len = 0; return; } // //we read entire line //and send to line parser to parse a word StringBuilder stbuilder = new StringBuilder(); _currentLine.CopyLineContent(stbuilder); string lineContent = stbuilder.ToString(); //find char at TextBufferSpan textBufferSpan = new TextBufferSpan(lineContent.ToCharArray()); using (ILineSegmentList segmentList = this.RootGfx.TextServices.BreakToLineSegments(ref textBufferSpan)) { if (segmentList == null) { startAt = 0; len = 0; return; } int segcount = segmentList.Count; for (int i = 0; i < segcount; ++i) { ILineSegment seg = segmentList[i]; if (seg.StartAt + seg.Length >= caret_char_index) { //stop at this segment startAt = seg.StartAt; len = seg.Length; return; } } } //? startAt = 0; len = 0; }
/// <summary> /// Transforms the rectangle using specified matrix. /// </summary> /// <param name="matrix">The matrix.</param> /// <returns> /// A new shape with the matrix applied to it. /// </returns> public Polygon Transform(Matrix3x2 matrix) { if (matrix.IsIdentity) { return(this); } var segments = new ILineSegment[this.LineSegments.Length]; var i = 0; foreach (var s in this.LineSegments) { segments[i++] = s.Transform(matrix); } return(new Polygon(segments)); }
/// <summary> /// Transforms the rectangle using specified matrix. /// </summary> /// <param name="matrix">The matrix.</param> /// <returns> /// A new shape with the matrix applied to it. /// </returns> public override IPath Transform(Matrix3x2 matrix) { if (matrix.IsIdentity) { return(this); } ILineSegment[] segments = new ILineSegment[this.LineSegments.Count]; int i = 0; foreach (ILineSegment s in this.LineSegments) { segments[i++] = s.Transform(matrix); } return(new Polygon(segments)); }
/// <summary> /// Transforms the rectangle using specified matrix. /// </summary> /// <param name="matrix">The matrix.</param> /// <returns> /// A new path with the matrix applied to it. /// </returns> public virtual IPath Transform(Matrix3x2 matrix) { if (matrix.IsIdentity) { return(this); } ILineSegment[] segments = new ILineSegment[this.lineSegments.Length]; int i = 0; foreach (ILineSegment s in this.LineSegments) { segments[i++] = s.Transform(matrix); } return(new Path(segments)); }
public Dictionary <ILineSegment, Point> FindIntersections(ILineSegment testSegment) { Dictionary <ILineSegment, Point> intersectingLineSegments = new Dictionary <ILineSegment, Point>(); double testSegmentCoefficient = testSegment.Coefficient; double testSegmentConstant = testSegment.Constant; foreach (ILineSegment lineSegment in _lineSegments) { double lineSegmentCoefficient = lineSegment.Coefficient; if (testSegmentCoefficient == lineSegmentCoefficient) { continue; } double lineSegmentConstant = lineSegment.Constant; double constantDifference = lineSegmentConstant - testSegmentConstant; double coefficientDifference = testSegmentCoefficient - lineSegmentCoefficient; double yIntersectCoordinate = ((testSegmentCoefficient * constantDifference) / coefficientDifference) + testSegmentConstant; double xIntersectCoordinate = constantDifference / coefficientDifference; if ((yIntersectCoordinate > testSegment.PointA.Y && yIntersectCoordinate < testSegment.PointB.Y) || (yIntersectCoordinate < testSegment.PointA.Y && yIntersectCoordinate > testSegment.PointB.Y)) { if ((xIntersectCoordinate > testSegment.PointA.X && xIntersectCoordinate < testSegment.PointB.X) || (xIntersectCoordinate < testSegment.PointA.X && xIntersectCoordinate > testSegment.PointB.X)) { if ((yIntersectCoordinate > lineSegment.PointA.Y && yIntersectCoordinate < lineSegment.PointB.Y) || (yIntersectCoordinate < lineSegment.PointA.Y && yIntersectCoordinate > lineSegment.PointB.Y)) { if ((xIntersectCoordinate > lineSegment.PointA.X && xIntersectCoordinate < lineSegment.PointB.X) || (xIntersectCoordinate < lineSegment.PointA.X && xIntersectCoordinate > lineSegment.PointB.X)) { Point intersectionPoint = new Point(xIntersectCoordinate, yIntersectCoordinate); LineSegment segment = (LineSegment)lineSegment; intersectingLineSegments.Add(lineSegment, intersectionPoint); } } } } } return(intersectingLineSegments); }
/// <summary> /// Initializes a new instance of the <see cref="PathGradientBrush"/> class. /// </summary> /// <param name="points">Points that constitute a polygon that represents the gradient area.</param> /// <param name="colors">Array of colors that correspond to each point in the polygon.</param> /// <param name="centerColor">Color at the center of the gradient area to which the other colors converge.</param> public PathGradientBrush(PointF[] points, Color[] colors, Color centerColor) { if (points == null) { throw new ArgumentNullException(nameof(points)); } if (points.Length < 3) { throw new ArgumentOutOfRangeException( nameof(points), "There must be at least 3 lines to construct a path gradient brush."); } if (colors == null) { throw new ArgumentNullException(nameof(colors)); } if (!colors.Any()) { throw new ArgumentOutOfRangeException( nameof(colors), "One or more color is needed to construct a path gradient brush."); } int size = points.Length; var lines = new ILineSegment[size]; for (int i = 0; i < size; i++) { lines[i] = new LinearLineSegment(points[i % size], points[(i + 1) % size]); } this.centerColor = centerColor; Color ColorAt(int index) => colors[index % colors.Length]; this.edges = lines.Select(s => new Path(s)) .Select((path, i) => new Edge(path, ColorAt(i), ColorAt(i + 1))).ToList(); }
/// <summary> /// 应用组合的样式 /// </summary> void ApplyPattern() { if (_options.LinePattern == null) { _options.UseLinePattern = false; } else if (_options.LinePattern.Count == 1 && _options.LinePattern.get_Line(0).LineType == tkLineType.lltSimple) { ILineSegment line = _options.LinePattern.get_Line(0); if (line != null) { _options.LineStipple = line.LineStyle; _options.LineWidth = line.LineWidth; _options.LineColor = line.Color; } _options.UseLinePattern = false; } else { _options.UseLinePattern = true; } }
public bool Contains(ILineSegment lineSegment) { return _lineSegments.Contains(lineSegment); }
public void Remove(ILineSegment lineSegment) { _lineSegments.Remove(lineSegment); }
/// <summary> /// Initializes a new instance of the <see cref="InternalPath" /> class. /// </summary> /// <param name="segment">The segment.</param> /// <param name="isClosedPath">if set to <c>true</c> [is closed path].</param> internal InternalPath(ILineSegment segment, bool isClosedPath) : this(segment.Flatten(), isClosedPath) { }
/// <summary> /// Initializes a new instance of the <see cref="InternalPath" /> class. /// </summary> /// <param name="segment">The segment.</param> /// <param name="isClosedPath">if set to <c>true</c> [is closed path].</param> internal InternalPath(ILineSegment segment, bool isClosedPath) : this(segment.AsSimpleLinearPath(), isClosedPath) { }
/// <summary> /// Initializes a new instance of the <see cref="InternalPath" /> class. /// </summary> /// <param name="segment">The segment.</param> /// <param name="isClosedPath">if set to <c>true</c> [is closed path].</param> internal InternalPath(ILineSegment segment, bool isClosedPath) : this(segment?.Flatten() ?? ImmutableArray <Vector2> .Empty, isClosedPath) { }
/// <summary> /// Initializes a new instance of the <see cref="Polygon" /> class. /// </summary> /// <param name="segment">The segment.</param> public Polygon(ILineSegment segment) { this.innerPath = new InternalPath(segment, true); this.pathCollection = new[] { this }; }
public void AddSegment(ILineSegment segment) { this.segments.Add(segment); }
/// <summary> /// Initializes a new instance of the <see cref="Polygon" /> class. /// </summary> /// <param name="segment">The segment.</param> public Polygon(ILineSegment segment) : base(segment) { }
/// <summary> /// Returns the intersection of the specified segment with this bounding box. If there is no intersection, /// then this returns null. If the intersection is a corner, then the LineSegment will be degenerate, /// that is both the coordinates will be the same. Otherwise, the segment will be returned so that the /// direction is the same as the original segment. /// </summary> /// <param name="self">The IEnvelope to use with this method</param> /// <param name="segment">The LineSegment to intersect.</param> /// <returns>An ILineSegment that is cropped to fit within the bounding box.</returns> public static ILineSegment Intersection(this IEnvelope self, ILineSegment segment) { if (self == null) return null; if (self.IsNull) return null; if (segment == null) return null; // If the line segment is completely contained by this envelope, simply return the original. if (self.Contains(segment.P0) && self.Contains(segment.P1)) return segment; int count = 0; Coordinate[] borderPoints = new Coordinate[2]; ILineSegment[] border = self.BorderSegments(); for (int i = 0; i < 4; i++) { borderPoints[count] = border[i].Intersection(segment); if (borderPoints[count] != null) { count++; } } // If there are two intersections, the line crosses this envelope if (count == 2) { Vector v = new Vector(segment.P0, segment.P1); Vector t = new Vector(borderPoints[0], borderPoints[1]); return t.Dot(v) < 0 ? new LineSegment(borderPoints[1], borderPoints[0]) : new LineSegment(borderPoints[0], borderPoints[1]); } // if there is only one intersection, we probably have one point contained and one point not-contained if (count == 1) { if (self.Contains(segment.P0)) { // P1 got cropped, so make a line from p0 to the cropped point return new LineSegment(segment.P0, borderPoints[0]); } return self.Contains(segment.P1) ? new LineSegment(borderPoints[0], segment.P1) : new LineSegment(borderPoints[0], borderPoints[0]); } return null; }
/// <summary> /// Adds the segment. /// </summary> /// <param name="segment">The segment.</param> public PathBuilder AddSegment(ILineSegment segment) { this.currentFigure.AddSegment(segment.Transform(this.currentTransform)); return(this); }
/// <summary> /// /// </summary> /// <param name="pts"></param> /// <param name="seg"></param> /// <param name="startIndex"></param> /// <returns></returns> private int FindMaxPerpDistance(IList<Coordinate> pts, ILineSegment seg, int startIndex) { double maxPerpDistance = seg.DistancePerpendicular(pts[startIndex]); double nextPerpDistance = maxPerpDistance; int maxIndex = startIndex; int nextIndex = maxIndex; while (nextPerpDistance >= maxPerpDistance) { maxPerpDistance = nextPerpDistance; maxIndex = nextIndex; nextIndex = NextIndex(pts, maxIndex); nextPerpDistance = seg.DistancePerpendicular(pts[nextIndex]); } // found maximum width for this segment - update global min dist if appropriate if (maxPerpDistance < _minWidth) { _minPtIndex = maxIndex; _minWidth = maxPerpDistance; _minWidthPt = pts[_minPtIndex]; _minBaseSeg = new LineSegment(seg); } return maxIndex; }
/// <summary> /// Initializes a new instance of the <see cref="InternalPath" /> class. /// </summary> /// <param name="segment">The segment.</param> /// <param name="isClosedPath">if set to <c>true</c> [is closed path].</param> internal InternalPath(ILineSegment segment, bool isClosedPath) : this(segment?.Flatten() ?? Enumerable.Empty <PointF>(), isClosedPath) { }
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; } }
public Dictionary<ILineSegment, Point> FindIntersections(ILineSegment testSegment) { Dictionary<ILineSegment, Point> intersectingLineSegments = new Dictionary<ILineSegment, Point>(); double testSegmentCoefficient = testSegment.Coefficient; double testSegmentConstant = testSegment.Constant; foreach (ILineSegment lineSegment in _lineSegments) { double lineSegmentCoefficient = lineSegment.Coefficient; if (testSegmentCoefficient == lineSegmentCoefficient) { continue; } double lineSegmentConstant = lineSegment.Constant; double constantDifference = lineSegmentConstant - testSegmentConstant; double coefficientDifference = testSegmentCoefficient - lineSegmentCoefficient; double yIntersectCoordinate = ((testSegmentCoefficient * constantDifference) / coefficientDifference) + testSegmentConstant; double xIntersectCoordinate = constantDifference / coefficientDifference; if ((yIntersectCoordinate > testSegment.PointA.Y && yIntersectCoordinate < testSegment.PointB.Y) || (yIntersectCoordinate < testSegment.PointA.Y && yIntersectCoordinate > testSegment.PointB.Y)) { if ((xIntersectCoordinate > testSegment.PointA.X && xIntersectCoordinate < testSegment.PointB.X) || (xIntersectCoordinate < testSegment.PointA.X && xIntersectCoordinate > testSegment.PointB.X)) { if ((yIntersectCoordinate > lineSegment.PointA.Y && yIntersectCoordinate < lineSegment.PointB.Y) || (yIntersectCoordinate < lineSegment.PointA.Y && yIntersectCoordinate > lineSegment.PointB.Y)) { if ((xIntersectCoordinate > lineSegment.PointA.X && xIntersectCoordinate < lineSegment.PointB.X) || (xIntersectCoordinate < lineSegment.PointA.X && xIntersectCoordinate > lineSegment.PointB.X)) { Point intersectionPoint = new Point(xIntersectCoordinate, yIntersectCoordinate); LineSegment segment = (LineSegment)lineSegment; intersectingLineSegments.Add(lineSegment, intersectionPoint); } } } } } return intersectingLineSegments; }
public void Add(ILineSegment lineSegment) { _lineSegments.Add(lineSegment); }
public void AddLineSegment(ILineSegment lineSegment) { _segments.Add(lineSegment); }
/// <summary> /// This should only be used if the Intersection is not actually required because it uses the Intersection method /// and returns false if the return value is null. /// </summary> /// <param name="self">The <c>IEnvelope</c> that is being extended by this method</param> /// <param name="segment">The segment to be tested against this envelope.</param> /// <returns>The line segment to compare against.</returns> public static bool Intersects(this IEnvelope self, ILineSegment segment) { if (self.Intersection(segment) != null) return true; return false; }