Skip to content

Commit

Permalink
Ensure SETSCRUNCH transforms all turtle locations
Browse files Browse the repository at this point in the history
  • Loading branch information
inexorabletash committed Sep 20, 2023
1 parent b8d7f71 commit ede7a08
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
8 changes: 7 additions & 1 deletion tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -989,7 +989,7 @@ QUnit.test("Logical Operations", function(t) {
});

QUnit.test("Graphics", function(t) {
t.expect(180);
t.expect(182);

// NOTE: test canvas is 300,300 (so -150...150 coordinates before hitting)
// edge
Expand Down Expand Up @@ -1168,6 +1168,12 @@ QUnit.test("Graphics", function(t) {
this.assert_equals('cs pu setturtle 2 setturtle 1 pendownp', 0);
this.assert_equals('cs pu ask 2 [ ht ] pendownp', 0);

this.assert_equals('cs setxy 100 100 setscrunch 2 2 pos', [50, 50]);
this.run('cs setscrunch 1 1');
this.assert_equals('cs ask 2 [ setxy 100 100 ] setscrunch 2 2 setturtle 2 pos', [50, 50]);
this.run('cs setscrunch 1 1');


//
// 6.4 Turtle and Window Queries
//
Expand Down
9 changes: 9 additions & 0 deletions turtle.js
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,15 @@
this.x = this.px = this.x / sx * this.sx;
this.y = this.py = this.y / sy * this.sy;

for (var i = 0; i < this._turtles.length; ++i) {
if (this._turtles[i] === undefined || i == this.currentturtle) {
continue;
}
var t = this._turtles[i];
t.x = t.x / sx * this.sx;
t.y = t.y / sy * this.sy;
}

this.sx = sx;
this.sy = sy;

Expand Down

0 comments on commit ede7a08

Please sign in to comment.