|
| 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 | +#> |
1 | 11 | param([double[]]$xy) |
| 12 | +# break apart the components |
2 | 13 | $x, $y = $xy |
| 14 | +# and add a position if we do not have one. |
3 | 15 | 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 }) |
5 | 17 | } |
| 18 | +# Modify the position without creating a new object |
6 | 19 | $this.'.Position'.X += $x |
7 | 20 | $this.'.Position'.Y += $y |
| 21 | +# And readback our new position |
8 | 22 | $posX, $posY = $this.'.Position'.X, $this.'.Position'.Y |
| 23 | +# If we have no .Minimum |
9 | 24 | 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 }) |
14 | 27 | } |
| 28 | + |
| 29 | +# Then check if we need to update our minimum point. |
15 | 30 | if ($posX -lt $this.'.Minimum'.X) { |
16 | 31 | $this.'.Minimum'.X = $posX |
17 | 32 | } |
18 | 33 | if ($posY -lt $this.'.Minimum'.Y) { |
19 | 34 | $this.'.Minimum'.Y = $posY |
20 | 35 | } |
| 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 |
21 | 44 | if ($posX -gt $this.'.Maximum'.X) { |
22 | 45 | $this.'.Maximum'.X = $posX |
23 | 46 | } |
|
0 commit comments