Skip to content

Commit b286c1a

Browse files
feat: Get-Vector3 ( Fixes #3 )
1 parent 089bc0a commit b286c1a

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

Commands/Get-Vector3.ps1

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
function Get-Vector3 {
2+
<#
3+
.SYNOPSIS
4+
Gets a Vector3
5+
.DESCRIPTION
6+
Gets any input and arguments as a Vector3
7+
.LINK
8+
https://learn.microsoft.com/en-us/dotnet/api/system.numerics.vector3?wt.mc_id=MVP_321542
9+
.EXAMPLE
10+
# Create a vector out of two numbers
11+
Vector3 1 2 3
12+
.EXAMPLE
13+
(Vector3 1 2 3 ) + (Vector3 3 2 1)
14+
.EXAMPLE
15+
(Vector3 1 2 3 ) - (Vector3 3 2 1)
16+
.EXAMPLE
17+
# Create a thousand vectors
18+
$vectors = Vector3 1..3kb
19+
.EXAMPLE
20+
# Create a thousand vectors in random order, using the pipeline
21+
$vectors = 1..3kb | Get-Random -Count 3kb | Vector3
22+
.EXAMPLE
23+
# Create a vector from a string
24+
$vector = Vector3 "hi"
25+
.NOTES
26+
This script is self contained so that it can be easily dropped into any project
27+
#>
28+
[Alias('Vector3','V3')]
29+
param()
30+
31+
32+
# Collect all of our input and arguments
33+
$allIn = @($input) + @(
34+
foreach ($arg in $args) {
35+
$arg
36+
}
37+
)
38+
39+
# and expand them
40+
$expandAllIn = @($allIn | Vector)
41+
42+
# Go over our arguments three at a time
43+
For ($n = 0; $n -lt $expandAllIn.Length; $n+=3) {
44+
$argSet = $expandAllIn[$n..($n+2)] -as [float[]]
45+
switch ($argSet.Length) {
46+
1 {
47+
[Numerics.Vector3]::new($argSet[0])
48+
}
49+
2 {
50+
[Numerics.Vector3]::new([Numerics.Vector2]::new($argSet[0],$argSet[1]), 1)
51+
}
52+
3 {
53+
[Numerics.Vector3]::new($argSet)
54+
}
55+
}
56+
}
57+
}

0 commit comments

Comments
 (0)