Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
github: [StartAutomating]
501 changes: 501 additions & 0 deletions .github/workflows/BuildVector.yml

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions Build/GitHub/Jobs/BuildVector.psd1
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
@{
"runs-on" = "ubuntu-latest"
if = '${{ success() }}'
steps = @(
@{
name = 'Check out repository'
uses = 'actions/checkout@main'
},
'RunEZOut' # ,
<#@{
name = 'Run Vector (on branch)'
if = '${{github.ref_name != ''main''}}'
uses = './'
id = 'VectorAction'
}#>
# 'BuildAndPublishContainer'
)
}
10 changes: 10 additions & 0 deletions Build/GitHub/Steps/PublishTestResults.psd1
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
@{
name = 'PublishTestResults'
uses = 'actions/upload-artifact@main'
with = @{
name = 'PesterResults'
path = '**.TestResults.xml'
}
if = '${{always()}}'
}

15 changes: 15 additions & 0 deletions Build/Vector.GitHubWorkflow.PSDevOps.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#requires -Module PSDevOps
Import-BuildStep -SourcePath (
Join-Path $PSScriptRoot 'GitHub'
) -BuildSystem GitHubWorkflow

Push-Location ($PSScriptRoot | Split-Path)
New-GitHubWorkflow -Name "Build Vector Module" -On Push,
PullRequest,
Demand -Job TestPowerShellOnLinux,
TagReleaseAndPublish, BuildVector -Environment ([Ordered]@{
REGISTRY = 'ghcr.io'
IMAGE_NAME = '${{ github.repository }}'
}) -OutputPath .\.github\workflows\BuildVector.yml

Pop-Location
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
## Vector 0.1:

* Initial Release of Vector module
* Commands:
* Get-Vector (#1)
* Get-Vector2 (#2)
* Get-Vector3 (#3)
* Get-Vector4 (#4)
* Vector Workflow (#5)
* Vector Tests (#6)
* Vector Docs
* Demo (#7)
* README (#8)
* FUNDING (#9)
* CODE_OF_CONDUCT (#10)
* CONTRIBUTING (#11)
* SECURITY (#12)
9 changes: 9 additions & 0 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Code of Conduct

We have a simple subjective code of conduct:

1. Be Respectful
2. Be Helpful
3. Do No Harm

Failure to follow the code of conduct may result in blocks or banishment.
11 changes: 11 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Contibuting

We welcome suggestions and careful contributions.

To suggest something, please [open an issue](https://github.com/PowerShellWeb/Vector/issues) or start a [discussion](https://github.com/PowerShellWeb/Vector/discussion)

To add a feature, please open an issue and create a pull request.

## Contributing Examples

Examples are more than welcome! To contribute an example, please open an issue describing your example and create a pull request.
119 changes: 119 additions & 0 deletions Commands/Get-Vector.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
function Get-Vector
{
<#
.SYNOPSIS
Gets a one dimensional vector
.DESCRIPTION
Gets a one dimensional vector (or, more simply, a list of numbers)

This will convert a variety of types into numbers.
.NOTES
This attempts to convert any type into a number.

Some types are special:

* Primitive types will be casted to float
* `[Numerics.Vector2]`,`[Numerics.Vector3]`,`[Numerics.Vector4]` output each component
* `[string]`s that match a range (`$start..$end`) will output that range
* `[Version]`s will output each numeric component
* `[semver]`s will output each numeric component, followed by the bytes of a release type
* `[DateTime]` and `[DateTimeOffset]` will become a series of 12 numbers
* `year`,`month`,`day`
* `hour`, `minute`, `second`
* `millisecond`, `microsecond`, `nanosecond`
* `offset.hours`, `offset.minutes`, `offset.seconds`
* `[string]s` will return their bytes in the current `$outputEncoding`
* Anything unknown will be stringified and the bytes will be returned
#>
[Alias('Vector','Vector1','V1')]
param()

filter toVector {
$arg = $_
# Return primitive types
if ($arg.GetType -and $arg.GetType().IsPrimitive) {
# casted to float
return ($arg -as [float])
}
# Return vector components
if ($arg -is [ValueType]) {
if ($arg -is [Numerics.Vector2]) {
return $arg.X,$arg.Y
}
elseif ($arg -is [Numerics.Vector3]) {
return $arg.X,$arg.Y,$arg.Z
}
elseif ($arg -is [Numerics.Vector4]) {
return $arg.X,$arg.Y,$arg.Z, $arg.W
}
}
# Look for inline ranges.
if ($arg -is [string]) {
if ($arg -match '^\d..\d') {
$start, $end = $arg -split '\..', 2
$startInt = ($start -as [int])
$endInt = ($end -as [int])
if ($null -ne $startInt -and $null -ne $endInt) {
# If found, return them expanded.
return ($startInt..$endInt)
}
}
if ($arg -as [float]) {
return $arg -as [float]
}
}


# If the arg is a version, get each number of the version
if ($arg -is [version]) {return $arg.Major,$arg.Minor,$arg.Build,$arg.Revision}

# If we support semver and the arg is semver
if (('semver' -as [type]) -and $arg -is [semver]) {
# Return the numeric parts of the semver
$arg.Major,$arg.Minor,$arg.Patch
# and turn any string portions to bytes
if ($arg.PreReleaseLabel) {
# make sure to include a leading dash for pre-releases
$OutputEncoding.GetBytes("-$($arg.PreReleaseLabel)")
}

if ($arg.BuildLabel) {
# make sure to include a leading plus for build labels
$OutputEncoding.GetBytes("+$($arg.BuildLabel)")
}
return
}

# If the arg is a datetime or datetimeoffset
if ($arg -is [DateTime] -or $arg -is [DateTimeOffset]) {
# make it an offset, and then output 12 values
$dateArg = $arg -as [DateTimeOffset]
# * `year` `month` `day`
$dateArg.Year, $dateArg.Month, $dateArg.Day,
# * `hour` `minute` `second`
$dateArg.Hour, $dateArg.Minute, $dateArg.Second,
# * `millisecond`, `microsecond`, `nanosecond`
$dateArg.Millisecond, $dateArg.Microsecond, $dateArg.Nanosecond,
# * `offset hours`, `offset minutes`, `offset seconds`
$dateArg.Offset.Hours,$dateArg.Offset.Minutes,$dateArg.Offset.Seconds
return
}
# If the arg is a string
if ($arg -is [string]) {
# return its bytes
return $OutputEncoding.GetBytes($arg)
}
# any input we have not caught, stringify and turn to bytes
return $OutputEncoding.GetBytes("$arg")
}


# Collect all of our input and arguments
$allIn = @($input) + @(
foreach ($arg in $args) {
$arg
}
)

return $allIn | toVector
}
46 changes: 46 additions & 0 deletions Commands/Get-Vector2.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
function Get-Vector2 {
<#
.SYNOPSIS
Gets a Vector2
.DESCRIPTION
Gets any input and arguments as a Vector2
.LINK
https://learn.microsoft.com/en-us/dotnet/api/system.numerics.vector2?wt.mc_id=MVP_321542
.EXAMPLE
# Create a vector out of two numbers
Vector2 1 2
.EXAMPLE
(Vector2 1 2) + (Vector2 2 1)
.EXAMPLE
(Vector2 1 2) - (Vector2 2 1)
.EXAMPLE
# Create a thousand vectors
$vectors = Vector2 1..2kb
.EXAMPLE
# Create a thousand vectors in random order, using the pipeline
$vectors = 1..2kb | Get-Random -Count 2kb | Vector2
.EXAMPLE
# Create a vector from a string
$vector = Vector2 "hi"
#>
[Alias('V2','Vector2')]
param()
# Collect all of our input and arguments
$allIn = @($input) + @(
foreach ($arg in $args) {
$arg
}
)

# and expand them
$expandAllIn = @($allIn | Vector)

For ($n = 0; $n -lt $expandAllIn.Length; $n+=2) {
$argSet = $expandAllIn[$n..($n+1)] -as [float[]]
if ($argSet.Length -eq 1) {
[Numerics.Vector2]::new($argSet[0])
} else {
[Numerics.Vector2]::new($argSet)
}
}
}
57 changes: 57 additions & 0 deletions Commands/Get-Vector3.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
function Get-Vector3 {
<#
.SYNOPSIS
Gets a Vector3
.DESCRIPTION
Gets any input and arguments as a Vector3
.LINK
https://learn.microsoft.com/en-us/dotnet/api/system.numerics.vector3?wt.mc_id=MVP_321542
.EXAMPLE
# Create a vector out of two numbers
Vector3 1 2 3
.EXAMPLE
(Vector3 1 2 3 ) + (Vector3 3 2 1)
.EXAMPLE
(Vector3 1 2 3 ) - (Vector3 3 2 1)
.EXAMPLE
# Create a thousand vectors
$vectors = Vector3 1..3kb
.EXAMPLE
# Create a thousand vectors in random order, using the pipeline
$vectors = 1..3kb | Get-Random -Count 3kb | Vector3
.EXAMPLE
# Create a vector from a string
$vector = Vector3 "hi"
.NOTES
This script is self contained so that it can be easily dropped into any project
#>
[Alias('Vector3','V3')]
param()


# Collect all of our input and arguments
$allIn = @($input) + @(
foreach ($arg in $args) {
$arg
}
)

# and expand them
$expandAllIn = @($allIn | Vector)

# Go over our arguments three at a time
For ($n = 0; $n -lt $expandAllIn.Length; $n+=3) {
$argSet = $expandAllIn[$n..($n+2)] -as [float[]]
switch ($argSet.Length) {
1 {
[Numerics.Vector3]::new($argSet[0])
}
2 {
[Numerics.Vector3]::new([Numerics.Vector2]::new($argSet[0],$argSet[1]), 1)
}
3 {
[Numerics.Vector3]::new($argSet)
}
}
}
}
52 changes: 52 additions & 0 deletions Commands/Get-Vector4.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
function Get-Vector4 {
<#
.SYNOPSIS
Gets a Vector4
.DESCRIPTION
Gets any input and arguments as a Vector4
.LINK
https://learn.microsoft.com/en-us/dotnet/api/system.numerics.vector4?wt.mc_id=MVP_321542
.EXAMPLE
# Create a vector out of four numbers
Vector4 1 2 3 4
.EXAMPLE
(Vector4 1 2 3 4 ) + (Vector4 4 3 2 1 )
.EXAMPLE
(Vector4 1 2 3 4 ) - (Vector4 4 3 2 1)
.EXAMPLE
# Create a thousand vectors
$vectors = Vector4 1..4kb
.EXAMPLE
# Create a thousand vectors in random order, using the pipeline
$vectors = 1..4kb | Get-Random -Count 4kb | Vector4
.EXAMPLE
# Create vectors from a string
Vector4 "hi"
#>
[Alias('v4','Vector4')]
param()
# Collect all of our input and arguments
$allIn = @($input) + @(
foreach ($arg in $args) {
$arg
}
)

# and expand them
$expandAllIn = @($allIn | vector)
For ($n = 0; $n -lt $expandAllIn.Length; $n+=4) {
$argSet = $expandAllIn[$n..($n+3)] -as [float[]]
switch ($argSet.Length) {
1 {[Numerics.Vector4]::new($argSet[0]) }
2 {
[Numerics.Vector4]::new([Numerics.Vector2]::new($argSet[0],$argSet[1]), 1, 1)
}
3 {
[Numerics.Vector4]::new([Numerics.Vector3]::new($argSet[0],$argSet[1],$argSet[2]), 1)
}
4 {
[Numerics.Vector4]::new($argSet)
}
}
}
}
Loading
Loading