-
Notifications
You must be signed in to change notification settings - Fork 771
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
draw: constrain object move with Shift
- Added src/layer/vector/Path.Constraint.ts Issue #7933 Signed-off-by: Hubert Figuière <[email protected]> Change-Id: Ie39c15a8552276bc5919ffbbd5dd859695048b9c
- Loading branch information
Showing
5 changed files
with
98 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
declare var L: any; | ||
|
||
namespace cool { | ||
|
||
export class Constraint { | ||
/** | ||
* Near means within +/- PI / 8 since we do diagonals | ||
*/ | ||
public static angleNear (angle: number, near: number): boolean { | ||
return Math.abs(near - angle) < (Math.PI / 8); | ||
} | ||
|
||
/** | ||
* Will recalculate delta based on a shift constraint | ||
*/ | ||
public static shiftConstraint (delta: Point): Point { | ||
var angle = delta.angleOf(); | ||
|
||
if (Constraint.angleNear(angle, 0) || Constraint.angleNear(angle, Math.PI)) { | ||
// Snap back the y to 0 | ||
return new Point(delta.x, 0); | ||
} else if (Constraint.angleNear(angle, Math.PI / 2) || | ||
Constraint.angleNear(angle, -Math.PI / 2)) { | ||
|
||
// Snap back the x to 0 | ||
return new Point(0, delta.y); | ||
} else { | ||
var deltaD = (Math.abs(delta.x) + Math.abs(delta.y)) / 2; | ||
if (Constraint.angleNear(angle, Math.PI / 4)) { | ||
return new Point(deltaD, deltaD); | ||
} else if (Constraint.angleNear(angle, -Math.PI / 4)) { | ||
return new Point(deltaD, -deltaD); | ||
} else if (Constraint.angleNear(angle, Math.PI * 0.75)) { | ||
return new Point(-deltaD, deltaD); | ||
} else { | ||
return new Point(-deltaD, -deltaD); | ||
} | ||
} | ||
} | ||
} | ||
|
||
} | ||
|
||
L.Constraint = cool.Constraint; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters