Skip to content

Commit 236ecb1

Browse files
feat: Turtle Position Vector ( Fixes #274, Fixes #275, Fixes #276 )
Also adding docs
1 parent 8741ce2 commit 236ecb1

File tree

2 files changed

+39
-6
lines changed

2 files changed

+39
-6
lines changed

Types/Turtle/get_Position.ps1

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
1+
<#
2+
.SYNOPSIS
3+
Gets the Turtle's position
4+
.DESCRIPTION
5+
Gets the current position of the turtle as a vector.
6+
#>
7+
[OutputType([Numerics.Vector2])]
8+
param()
19
if (-not $this.'.Position') {
2-
$this | Add-Member -MemberType NoteProperty -Force -Name '.Position' -Value ([pscustomobject]@{ X = 0; Y = 0 })
10+
$this | Add-Member -MemberType NoteProperty -Force -Name '.Position' -Value (
11+
[Numerics.Vector2]::new(0,0)
12+
)
313
}
414
return $this.'.Position'

Types/Turtle/set_Position.ps1

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,46 @@
1+
<#
2+
.SYNOPSIS
3+
Sets the Turtle's position
4+
.DESCRIPTION
5+
Sets the position of the Turtle and updates its minimum and maximum.
6+
7+
This should really not be done directly - the position should be updated as the Turtle moves.
8+
.NOTES
9+
Changing the position outside of the turtle will probably not work how you would expect.
10+
#>
111
param([double[]]$xy)
12+
# break apart the components
213
$x, $y = $xy
14+
# and add a position if we do not have one.
315
if (-not $this.'.Position') {
4-
$this | Add-Member -MemberType NoteProperty -Force -Name '.Position' -Value ([pscustomobject]@{ X = 0; Y = 0 })
16+
$this | Add-Member -MemberType NoteProperty -Force -Name '.Position' -Value ([Numerics.Vector2]@{ X = 0; Y = 0 })
517
}
18+
# Modify the position without creating a new object
619
$this.'.Position'.X += $x
720
$this.'.Position'.Y += $y
21+
# And readback our new position
822
$posX, $posY = $this.'.Position'.X, $this.'.Position'.Y
23+
# If we have no .Minimum
924
if (-not $this.'.Minimum') {
10-
$this | Add-Member -MemberType NoteProperty -Force -Name '.Minimum' -Value ([pscustomobject]@{ X = 0; Y = 0 })
11-
}
12-
if (-not $this.'.Maximum') {
13-
$this | Add-Member -MemberType NoteProperty -Force -Name '.Maximum' -Value ([pscustomobject]@{ X = 0; Y = 0 })
25+
# create one.
26+
$this | Add-Member -MemberType NoteProperty -Force -Name '.Minimum' -Value ([Numerics.Vector2]@{ X = 0; Y = 0 })
1427
}
28+
29+
# Then check if we need to update our minimum point.
1530
if ($posX -lt $this.'.Minimum'.X) {
1631
$this.'.Minimum'.X = $posX
1732
}
1833
if ($posY -lt $this.'.Minimum'.Y) {
1934
$this.'.Minimum'.Y = $posY
2035
}
36+
37+
# If we have no .Maximum
38+
if (-not $this.'.Maximum') {
39+
# create one.
40+
$this | Add-Member -MemberType NoteProperty -Force -Name '.Maximum' -Value ([Numerics.Vector2]@{ X = 0; Y = 0 })
41+
}
42+
43+
# Then update our maximum point
2144
if ($posX -gt $this.'.Maximum'.X) {
2245
$this.'.Maximum'.X = $posX
2346
}

0 commit comments

Comments
 (0)