Skip to content

Commit 089bc0a

Browse files
feat: Get-Vector2 ( Fixes #2 )
1 parent 89daa13 commit 089bc0a

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

Commands/Get-Vector2.ps1

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
function Get-Vector2 {
2+
<#
3+
.SYNOPSIS
4+
Gets a Vector2
5+
.DESCRIPTION
6+
Gets any input and arguments as a Vector2
7+
.LINK
8+
https://learn.microsoft.com/en-us/dotnet/api/system.numerics.vector2?wt.mc_id=MVP_321542
9+
.EXAMPLE
10+
# Create a vector out of two numbers
11+
Vector2 1 2
12+
.EXAMPLE
13+
(Vector2 1 2) + (Vector2 2 1)
14+
.EXAMPLE
15+
(Vector2 1 2) - (Vector2 2 1)
16+
.EXAMPLE
17+
# Create a thousand vectors
18+
$vectors = Vector2 1..2kb
19+
.EXAMPLE
20+
# Create a thousand vectors in random order, using the pipeline
21+
$vectors = 1..2kb | Get-Random -Count 2kb | Vector2
22+
.EXAMPLE
23+
# Create a vector from a string
24+
$vector = Vector2 "hi"
25+
#>
26+
[Alias('V2','Vector2')]
27+
param()
28+
# Collect all of our input and arguments
29+
$allIn = @($input) + @(
30+
foreach ($arg in $args) {
31+
$arg
32+
}
33+
)
34+
35+
# and expand them
36+
$expandAllIn = @($allIn | Vector)
37+
38+
For ($n = 0; $n -lt $expandAllIn.Length; $n+=2) {
39+
$argSet = $expandAllIn[$n..($n+1)] -as [float[]]
40+
if ($argSet.Length -eq 1) {
41+
[Numerics.Vector2]::new($argSet[0])
42+
} else {
43+
[Numerics.Vector2]::new($argSet)
44+
}
45+
}
46+
}

0 commit comments

Comments
 (0)