-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added autofit button You can now pass a callback function to the command parser and command executors to be invoked after a command is executed (to access the updated position of the turtle) This mechanism is used to expand an Axis-Aligned Bounding Box every time the turtle moves with the pen down. * Autofit when selecting from dropdown Automatically autofit the drawing when selecting an example from the dropdown menu.
- Loading branch information
1 parent
03c2f78
commit 92411fe
Showing
7 changed files
with
99 additions
and
9 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,36 @@ | ||
class BoundingBox { | ||
|
||
constructor() { | ||
this.reset(); | ||
} | ||
|
||
reset() { | ||
// By default it's positioned with top-left corner at [0,0] with a width and height of 1. | ||
// The x and y values are always the center | ||
this.left = this.top = 0; | ||
this.right = this.bottom = 1; | ||
this.width = this.height = 1; | ||
this.x = this.y = .5; | ||
} | ||
|
||
move(x, y) { | ||
this.left += x; | ||
this.right += x; | ||
this.x += x; | ||
this.top += y; | ||
this.bottom += y; | ||
this.y += y; | ||
} | ||
|
||
includePoint(x, y) { | ||
this.left = Math.min(this.left, x); | ||
this.right = Math.max(this.right, x); | ||
this.top = Math.min(this.top, y); | ||
this.bottom = Math.max(this.bottom, y); | ||
this.width = this.right - this.left; | ||
this.height = this.bottom - this.top; | ||
this.x = this.left + this.width * .5; | ||
this.y = this.top + this.height * .5; | ||
} | ||
|
||
} |
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
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