Skip to content

Commit

Permalink
Drawing bounding box always included first point
Browse files Browse the repository at this point in the history
This was only noticeable in drawings that would `pu` then move some distance and `pd` and start drawing. It would include a patch of empty space in the bounding box.
  • Loading branch information
TheTastefulToastie committed Nov 22, 2018
1 parent 9dc916f commit 8362784
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion assets/tests.json

Large diffs are not rendered by default.

13 changes: 10 additions & 3 deletions sketch.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ let canvasScrollY = 0;
let canvasScaleX = 1;
let canvasScaleY = 1;
let drawingBounds = new BoundingBox();
let drawingBoundsFirstPoint = true;

let primary_keywords = ['fd', 'bd', 'rt', 'lt'];
let secondary_keywords = ['color', 'colorrgb', 'pensize', 'repeat', 'pu', 'pd'];
Expand Down Expand Up @@ -170,14 +171,20 @@ function scaleToFitBoundingBox(boundingBox) {

function afterCommandExecuted() {
if (turtle.pen) {
drawingBounds.includePoint(turtle.x, turtle.y);
if (drawingBoundsFirstPoint) {
drawingBounds.reset();
drawingBounds.move(turtle.x, turtle.y);
drawingBoundsFirstPoint = false;
} else {
drawingBounds.includePoint(turtle.x, turtle.y);
drawingBounds.includePoint(turtle.prevX, turtle.prevY);
}
}
}

function goTurtle() {
turtle = new Turtle(0, 0, 0);
drawingBounds.reset();
drawingBounds.move(turtle.x, turtle.y);
drawingBoundsFirstPoint = true;
background(bgcolor);

push();
Expand Down

0 comments on commit 8362784

Please sign in to comment.