annotate SilverlightGlimpse/SilverFlow.Controls/Controllers/SnapinController.cs @ 63:536498832a79

Latest version before changing bindings to Listbox
author Steven Hollidge <stevenhollidge@hotmail.com>
date Sun, 22 Apr 2012 13:33:42 +0100
parents
children
rev   line source
63
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
1 using System.Collections.Generic;
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
2 using System.Windows;
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
3 using SilverFlow.Controls.Extensions;
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
4 using SilverFlow.Geometry;
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
5
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
6 namespace SilverFlow.Controls.Controllers
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
7 {
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
8 /// <summary>
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
9 /// Provides helpers methods for calculating window position
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
10 /// during movement and resizing.
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
11 /// </summary>
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
12 public class SnapinController : ISnapinController
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
13 {
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
14 /// <summary>
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
15 /// Distance on which snapping works.
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
16 /// </summary>
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
17 private const double SnapinDistanceDefaultValue = 5;
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
18
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
19 /// <summary>
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
20 /// Gets or sets a value indicating whether snap in is enabled.
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
21 /// </summary>
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
22 /// <value><c>true</c> if snap in is enabled; otherwise, <c>false</c>.</value>
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
23 public bool SnapinEnabled { get; set; }
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
24
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
25 /// <summary>
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
26 /// Gets or sets snap in bounds.
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
27 /// </summary>
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
28 /// <value>Snap in bounds.</value>
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
29 public IEnumerable<Rect> SnapinBounds { get; set; }
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
30
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
31 /// <summary>
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
32 /// Gets or sets snap in distance.
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
33 /// </summary>
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
34 /// <value>Snap in distance.</value>
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
35 public double SnapinDistance { get; set; }
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
36
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
37 /// <summary>
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
38 /// Gets or sets a value snap in margin - distance between adjacent edges.
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
39 /// </summary>
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
40 /// <value>Snap in margin.</value>
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
41 public double SnapinMargin { get; set; }
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
42
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
43 /// <summary>
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
44 /// Gets calculations accuracy.
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
45 /// </summary>
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
46 /// <value>Accuracy.</value>
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
47 private double Accuracy
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
48 {
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
49 get { return SnapinDistance + SnapinMargin; }
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
50 }
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
51
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
52 /// <summary>
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
53 /// Returns new position of the specified rectangle
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
54 /// taking into account bounds the rectangle can be attracted to.
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
55 /// </summary>
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
56 /// <param name="rect">The rectangle.</param>
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
57 /// <returns>New position.</returns>
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
58 public Point SnapRectangle(Rect rect)
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
59 {
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
60 Point point = rect.Position();
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
61
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
62 if (SnapinEnabled)
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
63 {
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
64 Distance minDistance = new Distance();
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
65 foreach (var bound in SnapinBounds)
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
66 {
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
67 Distance distance = DistanceBetweenRectangles(rect, bound);
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
68 minDistance = Distance.Min(distance, minDistance);
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
69 }
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
70
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
71 point = point.Add(minDistance);
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
72 }
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
73
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
74 return point;
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
75 }
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
76
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
77 /// <summary>
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
78 /// Snaps the bottom right corner of the specified rectangle to the nearest bounds.
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
79 /// </summary>
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
80 /// <param name="rect">The rectangle.</param>
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
81 /// <returns>New position.</returns>
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
82 public Point SnapBottomRightCorner(Rect rect)
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
83 {
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
84 Point point = rect.BottomRight();
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
85
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
86 if (SnapinEnabled)
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
87 {
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
88 Distance minDistance = new Distance();
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
89 foreach (var bound in SnapinBounds)
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
90 {
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
91 Distance distance = new Distance()
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
92 {
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
93 X = DistanceBetweenRightEdgeAndRectangle(rect, bound),
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
94 Y = DistanceBetweenBottomEdgeAndRectangle(rect, bound)
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
95 };
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
96
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
97 minDistance = Distance.Min(distance, minDistance);
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
98 }
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
99
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
100 point = point.Add(minDistance);
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
101 }
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
102
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
103 return point;
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
104 }
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
105
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
106 /// <summary>
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
107 /// Snaps the upper left corner of the specified rectangle to the nearest bounds.
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
108 /// </summary>
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
109 /// <param name="rect">The rectangle.</param>
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
110 /// <returns>New position.</returns>
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
111 public Point SnapTopLeftCorner(Rect rect)
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
112 {
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
113 Point point = rect.Position();
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
114
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
115 if (SnapinEnabled)
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
116 {
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
117 Distance minDistance = new Distance();
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
118 foreach (var bound in SnapinBounds)
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
119 {
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
120 Distance distance = new Distance()
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
121 {
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
122 X = DistanceBetweenLeftEdgeAndRectangle(rect, bound),
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
123 Y = DistanceBetweenTopEdgeAndRectangle(rect, bound)
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
124 };
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
125
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
126 minDistance = Distance.Min(distance, minDistance);
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
127 }
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
128
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
129 point = point.Add(minDistance);
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
130 }
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
131
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
132 return point;
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
133 }
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
134
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
135 /// <summary>
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
136 /// Snaps the lower left corner of the specified rectangle to the nearest bounds.
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
137 /// </summary>
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
138 /// <param name="rect">The rectangle.</param>
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
139 /// <returns>New position.</returns>
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
140 public Point SnapBottomLeftCorner(Rect rect)
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
141 {
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
142 Point point = rect.BottomLeft();
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
143
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
144 if (SnapinEnabled)
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
145 {
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
146 Distance minDistance = new Distance();
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
147 foreach (var bound in SnapinBounds)
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
148 {
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
149 Distance distance = new Distance()
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
150 {
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
151 X = DistanceBetweenLeftEdgeAndRectangle(rect, bound),
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
152 Y = DistanceBetweenBottomEdgeAndRectangle(rect, bound)
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
153 };
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
154
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
155 minDistance = Distance.Min(distance, minDistance);
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
156 }
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
157
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
158 point = point.Add(minDistance);
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
159 }
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
160
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
161 return point;
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
162 }
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
163
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
164 /// <summary>
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
165 /// Snaps the upper right corner of the specified rectangle to the nearest bounds.
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
166 /// </summary>
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
167 /// <param name="rect">The rectangle.</param>
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
168 /// <returns>New position.</returns>
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
169 public Point SnapTopRightCorner(Rect rect)
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
170 {
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
171 Point point = rect.TopRight();
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
172
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
173 if (SnapinEnabled)
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
174 {
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
175 Distance minDistance = new Distance();
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
176 foreach (var bound in SnapinBounds)
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
177 {
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
178 Distance distance = new Distance()
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
179 {
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
180 X = DistanceBetweenRightEdgeAndRectangle(rect, bound),
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
181 Y = DistanceBetweenTopEdgeAndRectangle(rect, bound)
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
182 };
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
183
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
184 minDistance = Distance.Min(distance, minDistance);
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
185 }
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
186
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
187 point = point.Add(minDistance);
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
188 }
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
189
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
190 return point;
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
191 }
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
192
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
193 /// <summary>
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
194 /// Returns mininal distance between two rectangles.
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
195 /// </summary>
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
196 /// <param name="first">First rectangle.</param>
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
197 /// <param name="second">Second rectangle.</param>
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
198 /// <returns>Minimal distance.</returns>
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
199 private Distance DistanceBetweenRectangles(Rect first, Rect second)
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
200 {
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
201 double x1 = DistanceBetweenRightEdgeAndRectangle(first, second);
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
202 double x2 = DistanceBetweenLeftEdgeAndRectangle(first, second);
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
203 double y1 = DistanceBetweenBottomEdgeAndRectangle(first, second);
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
204 double y2 = DistanceBetweenTopEdgeAndRectangle(first, second);
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
205
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
206 Distance distance = new Distance()
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
207 {
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
208 X = MathExtensions.AbsMin(x1, x2),
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
209 Y = MathExtensions.AbsMin(y1, y2)
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
210 };
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
211
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
212 return distance;
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
213 }
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
214
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
215 /// <summary>
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
216 /// Returns distance between the right edge of the rectangle and another rectangle.
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
217 /// </summary>
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
218 /// <param name="first">First rectangle.</param>
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
219 /// <param name="second">Second rectangle.</param>
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
220 /// <returns>Minimal distance.</returns>
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
221 private double DistanceBetweenRightEdgeAndRectangle(Rect first, Rect second)
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
222 {
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
223 double snap;
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
224 double distance = double.NaN;
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
225 double x = first.X + first.Width - 1;
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
226
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
227 if (first.OverlapsVertically(second, Accuracy))
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
228 {
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
229 snap = second.X - 1 - SnapinMargin;
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
230 if (x.IsNear(snap, SnapinDistance))
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
231 {
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
232 distance = MathExtensions.AbsMin(snap - x, distance);
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
233 }
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
234
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
235 snap = second.X + second.Width - 1;
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
236 if (x.IsNear(snap, SnapinDistance))
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
237 {
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
238 distance = MathExtensions.AbsMin(snap - x, distance);
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
239 }
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
240 }
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
241
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
242 return distance;
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
243 }
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
244
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
245 /// <summary>
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
246 /// Returns distance between the left edge of the rectangle and another rectangle.
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
247 /// </summary>
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
248 /// <param name="first">First rectangle.</param>
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
249 /// <param name="second">Second rectangle.</param>
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
250 /// <returns>Minimal distance.</returns>
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
251 private double DistanceBetweenLeftEdgeAndRectangle(Rect first, Rect second)
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
252 {
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
253 double snap;
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
254 double distance = double.NaN;
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
255
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
256 if (first.OverlapsVertically(second, Accuracy))
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
257 {
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
258 snap = second.X;
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
259 if (first.X.IsNear(snap, SnapinDistance))
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
260 {
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
261 distance = MathExtensions.AbsMin(snap - first.X, distance);
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
262 }
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
263
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
264 snap = second.X + second.Width + SnapinMargin;
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
265 if (first.X.IsNear(snap, SnapinDistance))
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
266 {
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
267 distance = MathExtensions.AbsMin(snap - first.X, distance);
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
268 }
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
269 }
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
270
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
271 return distance;
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
272 }
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
273
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
274 /// <summary>
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
275 /// Returns distance between the bottom edge of the rectangle and another rectangle.
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
276 /// </summary>
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
277 /// <param name="first">First rectangle.</param>
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
278 /// <param name="second">Second rectangle.</param>
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
279 /// <returns>Minimal distance.</returns>
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
280 private double DistanceBetweenBottomEdgeAndRectangle(Rect first, Rect second)
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
281 {
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
282 double snap;
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
283 double distance = double.NaN;
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
284 double y = first.Y + first.Height - 1;
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
285
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
286 if (first.OverlapsHorizontally(second, Accuracy))
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
287 {
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
288 snap = second.Y - 1 - SnapinMargin;
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
289 if (y.IsNear(snap, SnapinDistance))
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
290 {
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
291 distance = MathExtensions.AbsMin(snap - y, distance);
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
292 }
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
293
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
294 snap = second.Y + second.Height - 1;
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
295 if (y.IsNear(snap, SnapinDistance))
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
296 {
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
297 distance = MathExtensions.AbsMin(snap - y, distance);
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
298 }
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
299 }
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
300
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
301 return distance;
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
302 }
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
303
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
304 /// <summary>
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
305 /// Returns distance between the top edge of the rectangle and another rectangle.
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
306 /// </summary>
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
307 /// <param name="first">First rectangle.</param>
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
308 /// <param name="second">Second rectangle.</param>
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
309 /// <returns>Minimal distance.</returns>
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
310 private double DistanceBetweenTopEdgeAndRectangle(Rect first, Rect second)
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
311 {
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
312 double snap;
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
313 double distance = double.NaN;
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
314
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
315 if (first.OverlapsHorizontally(second, Accuracy))
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
316 {
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
317 snap = second.Y;
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
318 if (first.Y.IsNear(snap, SnapinDistance))
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
319 {
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
320 distance = MathExtensions.AbsMin(snap - first.Y, distance);
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
321 }
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
322
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
323 snap = second.Y + second.Height + SnapinMargin;
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
324 if (first.Y.IsNear(snap, SnapinDistance))
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
325 {
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
326 distance = MathExtensions.AbsMin(snap - first.Y, distance);
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
327 }
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
328 }
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
329
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
330 return distance;
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
331 }
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
332 }
536498832a79 Latest version before changing bindings to Listbox
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
333 }