Skip to content

Commit 8c73ce0

Browse files
feat: Get-Vector4 ( Fixes #4 )
1 parent b286c1a commit 8c73ce0

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

Commands/Get-Vector4.ps1

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
function Get-Vector4 {
2+
<#
3+
.SYNOPSIS
4+
Gets a Vector4
5+
.DESCRIPTION
6+
Gets any input and arguments as a Vector4
7+
.LINK
8+
https://learn.microsoft.com/en-us/dotnet/api/system.numerics.vector4?wt.mc_id=MVP_321542
9+
.EXAMPLE
10+
# Create a vector out of four numbers
11+
Vector4 1 2 3 4
12+
.EXAMPLE
13+
(Vector4 1 2 3 4 ) + (Vector4 4 3 2 1 )
14+
.EXAMPLE
15+
(Vector4 1 2 3 4 ) - (Vector4 4 3 2 1)
16+
.EXAMPLE
17+
# Create a thousand vectors
18+
$vectors = Vector4 1..4kb
19+
.EXAMPLE
20+
# Create a thousand vectors in random order, using the pipeline
21+
$vectors = 1..4kb | Get-Random -Count 4kb | Vector4
22+
.EXAMPLE
23+
# Create vectors from a string
24+
Vector4 "hi"
25+
#>
26+
[Alias('v4','Vector4')]
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+
For ($n = 0; $n -lt $expandAllIn.Length; $n+=4) {
38+
$argSet = $expandAllIn[$n..($n+3)] -as [float[]]
39+
switch ($argSet.Length) {
40+
1 {[Numerics.Vector4]::new($argSet[0]) }
41+
2 {
42+
[Numerics.Vector4]::new([Numerics.Vector2]::new($argSet[0],$argSet[1]), 1, 1)
43+
}
44+
3 {
45+
[Numerics.Vector4]::new([Numerics.Vector3]::new($argSet[0],$argSet[1],$argSet[2]), 1)
46+
}
47+
4 {
48+
[Numerics.Vector4]::new($argSet)
49+
}
50+
}
51+
}
52+
}

0 commit comments

Comments
 (0)