private void GetTargetCorners(Rect bounds, SnapLineOrientation orientation, SnapLineLocation location, out Point cornerPoint1, out Point cornerPoint2) { if (orientation == SnapLineOrientation.Horizontal) { if (location == SnapLineLocation.Minimum) { cornerPoint1 = bounds.TopLeft; cornerPoint2 = bounds.TopRight; } else { cornerPoint1 = bounds.BottomLeft; cornerPoint2 = bounds.BottomRight; } } else if (location == SnapLineLocation.Minimum) { cornerPoint1 = bounds.TopLeft; cornerPoint2 = bounds.BottomLeft; } else { cornerPoint1 = bounds.TopRight; cornerPoint2 = bounds.BottomRight; } }
public SnapLine(Point p1, Point p2, SnapLineOrientation orientation, SnapLineLocation location, bool isContainerLine) { this.p1 = p1; this.p2 = p2; this.orientation = orientation; this.location = location; this.isContainerLine = isContainerLine; }
private List <SnapLine> FindNearestSnapLines(Point p1, Point p2, SnapLineLocation location, SnapLineOrientation orientation, double snapThreshold, out double adjustment) { List <SnapLine> resultSnapLines = new List <SnapLine>(); double smallestSignedDistance = double.MaxValue; foreach (SnapLine snapLine in this.snapLines) { double offset; if (snapLine.Orientation == orientation && this.ShouldSnap(p1, p2, location, snapLine, out offset)) { smallestSignedDistance = this.CheckForCloserSnapLine(p1, location, snapThreshold, resultSnapLines, smallestSignedDistance, snapLine, offset); if (offset != 0.0) { smallestSignedDistance = this.CheckForCloserSnapLine(p1, location, snapThreshold, resultSnapLines, smallestSignedDistance, snapLine, 0.0); } } } adjustment = resultSnapLines.Count > 0 ? smallestSignedDistance : 0.0; return(resultSnapLines); }
private double CheckForCloserSnapLine(Point p1, SnapLineLocation location, double snapThreshold, List <SnapLine> resultSnapLines, double smallestSignedDistance, SnapLine snapLine, double offset) { double num1 = snapLine.GetSignedDistance(p1) + offset; double num2 = Math.Abs(num1); if (num2 <= snapThreshold) { if (num2 < Math.Abs(smallestSignedDistance)) { smallestSignedDistance = num1; resultSnapLines.Clear(); } if (Math.Abs(num1 - smallestSignedDistance) < 1E-06) { snapLine.LocationRelativeToTarget = location; snapLine.OffsetRelativeToTarget = offset; resultSnapLines.Add(snapLine); } } return(smallestSignedDistance); }
private bool ShouldSnap(Point p1, Point p2, SnapLineLocation location, SnapLine snapLine, out double offset) { offset = 0.0; if (location == snapLine.Location) { if (!snapLine.IsContainerLine) { return(true); } if (snapLine.RangeOverlaps(p1, p2)) { offset = location == SnapLineLocation.Minimum ? this.defaultPadding : -this.defaultPadding; return(true); } } else if ((location == SnapLineLocation.Minimum && snapLine.Location == SnapLineLocation.Maximum || location == SnapLineLocation.Maximum && snapLine.Location == SnapLineLocation.Minimum) && (!snapLine.IsContainerLine && snapLine.RangeOverlaps(p1, p2))) { offset = snapLine.Location == SnapLineLocation.Minimum ? -this.defaultMargin : this.defaultMargin; return(true); } return(false); }