Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 120411 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/gef/SnapToGeometry.java (-15 / +40 lines)
Lines 134-139 Link Here
134
 */
134
 */
135
protected static final double THRESHOLD = 5.0001;
135
protected static final double THRESHOLD = 5.0001;
136
136
137
private double threshold = THRESHOLD;
138
137
boolean cachedCloneBool;
139
boolean cachedCloneBool;
138
140
139
/**
141
/**
Lines 165-170 Link Here
165
}
167
}
166
168
167
/**
169
/**
170
 * The sensitivity of the snapping.  Corrections greater than this value will not occur.
171
 * 
172
 * @return the snapping threshold
173
 * @since 3.2
174
 */
175
public double getThreshold ()
176
{
177
	return threshold;
178
}
179
180
/**
181
 * Sets the sensitivity of the snapping
182
 * 
183
 * @see #getThreshold()
184
 * @param newThreshold the new snapping threshold
185
 * @since 3.2
186
 */
187
public void setThreshold (double newThreshold)
188
{
189
	threshold = newThreshold;
190
}
191
192
/**
168
 * Generates a list of parts which should be snapped to.  The list is the original
193
 * Generates a list of parts which should be snapped to.  The list is the original
169
 * children, minus the given exclusions, minus and children whose figures are not visible.
194
 * children, minus the given exclusions, minus and children whose figures are not visible.
170
 * @since 3.0
195
 * @since 3.0
Lines 196-202 Link Here
196
 * @param vert <code>true</code> if the correction is vertical
221
 * @param vert <code>true</code> if the correction is vertical
197
 * @param near the left/top side of the rectangle 
222
 * @param near the left/top side of the rectangle 
198
 * @param far the right/bottom side of the rectangle
223
 * @param far the right/bottom side of the rectangle
199
 * @return the correction amount or THRESHOLD if no correction was made
224
 * @return the correction amount or #getThreshold () if no correction was made
200
 */
225
 */
201
protected double getCorrectionFor(Entry entries[], Map extendedData, boolean vert, 
226
protected double getCorrectionFor(Entry entries[], Map extendedData, boolean vert, 
202
                                double near, double far) {
227
                                double near, double far) {
Lines 208-234 Link Here
208
	if ((int)(near - far) % 2 != 0)
233
	if ((int)(near - far) % 2 != 0)
209
		total -= 1.0;
234
		total -= 1.0;
210
	double result = getCorrectionFor(entries, extendedData, vert, total / 2, 0);
235
	double result = getCorrectionFor(entries, extendedData, vert, total / 2, 0);
211
	if (result == THRESHOLD)
236
	if (result == getThreshold ())
212
		result = getCorrectionFor(entries, extendedData, vert, near, -1);
237
		result = getCorrectionFor(entries, extendedData, vert, near, -1);
213
	if (result == THRESHOLD)
238
	if (result == getThreshold ())
214
		result = getCorrectionFor(entries, extendedData, vert, far, 1);
239
		result = getCorrectionFor(entries, extendedData, vert, far, 1);
215
	return result;
240
	return result;
216
}
241
}
217
242
218
/**
243
/**
219
 * Returns the correction value between ± {@link #THRESHOLD}, or the THRESHOLD if no
244
 * Returns the correction value between ± {@link #getThreshold ()}, or the #getThreshold () if no
220
 * corrections were found.
245
 * corrections were found.
221
 * @param entries the entries
246
 * @param entries the entries
222
 * @param extendedData the map for setting values
247
 * @param extendedData the map for setting values
223
 * @param vert <code>true</code> if vertical
248
 * @param vert <code>true</code> if vertical
224
 * @param value the value being corrected
249
 * @param value the value being corrected
225
 * @param side which sides should be considered
250
 * @param side which sides should be considered
226
 * @return the correction or THRESHOLD if no correction was made
251
 * @return the correction or #getThreshold () if no correction was made
227
 */
252
 */
228
protected double getCorrectionFor(Entry entries[], Map extendedData, boolean vert, 
253
protected double getCorrectionFor(Entry entries[], Map extendedData, boolean vert, 
229
                                double value, int side) {
254
                                double value, int side) {
230
	double resultMag = THRESHOLD;
255
	double resultMag = getThreshold ();
231
	double result = THRESHOLD;
256
	double result = getThreshold ();
232
	
257
	
233
	String property;
258
	String property;
234
	if (side == -1)
259
	if (side == -1)
Lines 322-341 Link Here
322
	}
347
	}
323
	
348
	
324
	if ((snapOrientation & HORIZONTAL) != 0) {
349
	if ((snapOrientation & HORIZONTAL) != 0) {
325
		double xcorrect = THRESHOLD;
350
		double xcorrect = getThreshold ();
326
		xcorrect = getCorrectionFor(cols, request.getExtendedData(), true, 
351
		xcorrect = getCorrectionFor(cols, request.getExtendedData(), true, 
327
				baseRect.preciseX, baseRect.preciseRight());
352
				baseRect.preciseX, baseRect.preciseRight());
328
		if (xcorrect != THRESHOLD) {
353
		if (xcorrect != getThreshold ()) {
329
			snapOrientation &= ~HORIZONTAL;
354
			snapOrientation &= ~HORIZONTAL;
330
			correction.preciseX += xcorrect;
355
			correction.preciseX += xcorrect;
331
		}
356
		}
332
	}
357
	}
333
	
358
	
334
	if ((snapOrientation & VERTICAL) != 0) {
359
	if ((snapOrientation & VERTICAL) != 0) {
335
		double ycorrect = THRESHOLD;
360
		double ycorrect = getThreshold ();
336
		ycorrect = getCorrectionFor(rows, request.getExtendedData(), false, 
361
		ycorrect = getCorrectionFor(rows, request.getExtendedData(), false, 
337
				baseRect.preciseY, baseRect.preciseBottom());
362
				baseRect.preciseY, baseRect.preciseBottom());
338
		if (ycorrect != THRESHOLD) {
363
		if (ycorrect != getThreshold ()) {
339
			snapOrientation &= ~VERTICAL;
364
			snapOrientation &= ~VERTICAL;
340
			correction.preciseY += ycorrect;
365
			correction.preciseY += ycorrect;
341
		}
366
		}
Lines 344-350 Link Here
344
	if ((snapOrientation & EAST) != 0) {
369
	if ((snapOrientation & EAST) != 0) {
345
		double rightCorrection = getCorrectionFor(cols, request.getExtendedData(), 
370
		double rightCorrection = getCorrectionFor(cols, request.getExtendedData(), 
346
				true, baseRect.preciseRight() - 1, 1);
371
				true, baseRect.preciseRight() - 1, 1);
347
		if (rightCorrection != THRESHOLD) {
372
		if (rightCorrection != getThreshold ()) {
348
			snapOrientation &= ~EAST;
373
			snapOrientation &= ~EAST;
349
			correction.preciseWidth += rightCorrection;
374
			correction.preciseWidth += rightCorrection;
350
		}
375
		}
Lines 353-359 Link Here
353
	if ((snapOrientation & WEST) != 0) {
378
	if ((snapOrientation & WEST) != 0) {
354
		double leftCorrection = getCorrectionFor(cols, request.getExtendedData(), 
379
		double leftCorrection = getCorrectionFor(cols, request.getExtendedData(), 
355
				true, baseRect.preciseX, -1);
380
				true, baseRect.preciseX, -1);
356
		if (leftCorrection != THRESHOLD) {
381
		if (leftCorrection != getThreshold ()) {
357
			snapOrientation &= ~WEST;
382
			snapOrientation &= ~WEST;
358
			correction.preciseWidth -= leftCorrection;
383
			correction.preciseWidth -= leftCorrection;
359
			correction.preciseX += leftCorrection;
384
			correction.preciseX += leftCorrection;
Lines 363-369 Link Here
363
	if ((snapOrientation & SOUTH) != 0) {
388
	if ((snapOrientation & SOUTH) != 0) {
364
		double bottom = getCorrectionFor(rows, request.getExtendedData(), false,
389
		double bottom = getCorrectionFor(rows, request.getExtendedData(), false,
365
				baseRect.preciseBottom() - 1, 1);
390
				baseRect.preciseBottom() - 1, 1);
366
		if (bottom != THRESHOLD) {
391
		if (bottom != getThreshold ()) {
367
			snapOrientation &= ~SOUTH;
392
			snapOrientation &= ~SOUTH;
368
			correction.preciseHeight += bottom;
393
			correction.preciseHeight += bottom;
369
		}
394
		}
Lines 372-378 Link Here
372
	if ((snapOrientation & NORTH) != 0) {
397
	if ((snapOrientation & NORTH) != 0) {
373
		double topCorrection = getCorrectionFor(rows, request.getExtendedData(), 
398
		double topCorrection = getCorrectionFor(rows, request.getExtendedData(), 
374
				false, baseRect.preciseY, -1);
399
				false, baseRect.preciseY, -1);
375
		if (topCorrection != THRESHOLD) {
400
		if (topCorrection != getThreshold ()) {
376
			snapOrientation &= ~NORTH;
401
			snapOrientation &= ~NORTH;
377
			correction.preciseHeight -= topCorrection;
402
			correction.preciseHeight -= topCorrection;
378
			correction.preciseY += topCorrection;
403
			correction.preciseY += topCorrection;

Return to bug 120411