Skip to content

Commit 743227d

Browse files
author
James Brundage
committed
feat: Turtle.Distance ( Fixes #99 )
1 parent bfe8e8b commit 743227d

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

Types/Turtle/Distance.ps1

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<#
2+
.SYNOPSIS
3+
Determines the distance to a point
4+
.DESCRIPTION
5+
Determines the distance from the turtle's current position to a point.
6+
#>
7+
param(
8+
# The X-coordinate
9+
[double]$X = 0,
10+
# The Y-coordinate
11+
[double]$Y = 0
12+
)
13+
14+
# Determine the delta from the turtle's current position to the specified point
15+
$deltaX = $this.Position.X - $X
16+
$deltaY = $this.Position.Y - $Y
17+
# Calculate the distance using the Pythagorean theorem
18+
return [Math]::Sqrt($deltaX * $deltaX + $deltaY * $deltaY)

0 commit comments

Comments
 (0)