Skip to content

Commit 69dae6d

Browse files
author
James Brundage
committed
feat: Turtle.get/set_Position ( Fixes #7 )
1 parent b2f1b78 commit 69dae6d

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

Types/Turtle/get_Position.ps1

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
if (-not $this.'.Position') {
2+
$this | Add-Member -MemberType NoteProperty -Force -Name '.Position' -Value [pscustomobject]@{ X = 0; Y = 0 }
3+
}
4+
return $this.'.Position'

Types/Turtle/set_Position.ps1

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
param([double[]]$xy)
2+
$x, $y = $xy
3+
if (-not $this.'.Position') {
4+
$this | Add-Member -MemberType NoteProperty -Force -Name '.Position' -Value ([pscustomobject]@{ X = 0; Y = 0 })
5+
}
6+
$this.'.Position'.X += $x
7+
$this.'.Position'.Y += $y
8+
$posX, $posY = $this.'.Position'.X, $this.'.Position'.Y
9+
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 })
14+
}
15+
if ($posX -lt $this.'.Minimum'.X) {
16+
$this.'.Minimum'.X = $posX
17+
}
18+
if ($posY -lt $this.'.Minimum'.Y) {
19+
$this.'.Minimum'.Y = $posY
20+
}
21+
if ($posX -gt $this.'.Maximum'.X) {
22+
$this.'.Maximum'.X = $posX
23+
}
24+
if ($posY -gt $this.'.Maximum'.Y) {
25+
$this.'.Maximum'.Y = $posY
26+
}

0 commit comments

Comments
 (0)