Skip to content

Commit 2f56aad

Browse files
fix: Turtle.Pop output fix ( Fixes #264 )
Adding inner docs and using Rotate/Teleport method chain
1 parent 86f4883 commit 2f56aad

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

Types/Turtle/Pop.ps1

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,16 @@
99
# Draws a T shape by pushing and popping
1010
turtle rotate -90 forward 42 push rotate 90 forward 21 pop rotate -90 forward 21 show
1111
#>
12-
if ($this.'.Stack' -isnot [Collections.Stack]) { return }
13-
14-
if ($this.'.Stack'.Count -eq 0) { return }
12+
param()
1513

14+
# If the stack is not a stack, return ourself
15+
if ($this.'.Stack' -isnot [Collections.Stack]) { return $this }
16+
# If the stack is empty, return ourself
17+
if ($this.'.Stack'.Count -eq 0) { return $this }
18+
# Pop the stack
1619
$popped = $this.'.Stack'.Pop()
17-
$null = $this.PenUp().Goto($popped.Position.X, $popped.Position.Y).PenDown()
18-
$this.Heading = $popped.Heading
19-
return $this
20+
21+
$this. # Rotate by the differene in heading,
22+
Rotate($popped.Heading - $this.Heading).
23+
# then teleport to the popped location
24+
Teleport($popped.Position.X, $popped.Position.Y)

0 commit comments

Comments
 (0)