Пример #1
0
 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;
     }
 }
Пример #2
0
 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;
 }
Пример #3
0
 private void ExtendLine(Rect bounds, SnapLineOrientation orientation, ref Point p1, ref Point p2)
 {
     if (orientation == SnapLineOrientation.Horizontal)
     {
         p1.X = Math.Min(p1.X, bounds.Left);
         p2.X = Math.Max(p2.X, bounds.Right);
     }
     else
     {
         p1.Y = Math.Min(p1.Y, bounds.Top);
         p2.Y = Math.Max(p2.Y, bounds.Bottom);
     }
 }
Пример #4
0
        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);
        }