1
/* This notice must be untouched at all times.
4
The latest version is available at
5
http://www.openjacob.org
7
Copyright (c) 2006 Andreas Herz. All rights reserved.
8
Created 5. 11. 2006 by Andreas Herz (Web: http://www.freegroup.de )
12
This library is free software; you can redistribute it and/or
13
modify it under the terms of the GNU Lesser General Public
14
License (LGPL) as published by the Free Software Foundation; either
15
version 2.1 of the License, or (at your option) any later version.
17
This library is distributed in the hope that it will be useful,
18
but WITHOUT ANY WARRANTY; without even the implied warranty of
19
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20
Lesser General Public License for more details.
22
You should have received a copy of the GNU Lesser General Public
23
License along with this library; if not, write to the Free Software
24
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA,
25
or see http://www.gnu.org/copyleft/lesser.html
31
* @author Andreas Herz
34
draw2d.SnapToGrid=function(/*:draw2d.Workflow*/ workflow)
36
draw2d.SnapToHelper.call(this,workflow);
39
draw2d.SnapToGrid.prototype = new draw2d.SnapToHelper;
42
* Applies a snapping correction to the given result. Snapping can occur in the four
43
* primary directions: NORTH, SOUTH, EAST, WEST, as defined on {@link draw2d.PositionConstants}.
44
* By default a Point is treated as an empty Rectangle. Only NORTH and WEST should be used
45
* in general. But SOUTH and EAST may also be used. Similarly, VERTICAL and HORIZONTAL
46
* may be used to allow a point to snap to the "center" or "middle" as defined by the
49
draw2d.SnapToGrid.prototype.snapPoint=function(/*:int*/ direction, /*:draw2d.Point*/ inputPoint, /*:draw2d.Point*/ resultPoint)
51
resultPoint.x=this.workflow.gridWidthX*Math.floor(((inputPoint.x + this.workflow.gridWidthX/2.0) / this.workflow.gridWidthX));
52
resultPoint.y=this.workflow.gridWidthY*Math.floor(((inputPoint.y + this.workflow.gridWidthY/2.0) / this.workflow.gridWidthY));
57
* Applies a snap correction to a Rectangle based on a given Rectangle. The provided
58
* baseRect will be used as a reference for snapping. The types of snapping to be
59
* performed are indicated by the snapOrientation parameter. The correction is applied to
62
* All coordinate information received and returned by this method should be in absolute
65
draw2d.SnapToGrid.prototype.snapRectangle=function(/*:draw2d.Dimension*/ inputBounds, /*:draw2d.Dimension*/ resultBounds)
67
resultBounds.x = inputBounds.x;
68
resultBounds.y = inputBounds.y;
69
resultBounds.w = inputBounds.w;
70
resultBounds.h = inputBounds.h;