From ede7a08fe6fd4832e2657c40b9168e02f10dda8b Mon Sep 17 00:00:00 2001 From: Joshua Bell Date: Tue, 19 Sep 2023 19:29:53 -0700 Subject: [PATCH] Ensure SETSCRUNCH transforms all turtle locations --- tests.js | 8 +++++++- turtle.js | 9 +++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/tests.js b/tests.js index c16621c..ed87bb4 100644 --- a/tests.js +++ b/tests.js @@ -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 @@ -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 // diff --git a/turtle.js b/turtle.js index 6c87b95..b95147c 100644 --- a/turtle.js +++ b/turtle.js @@ -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;