Skip to content

Commit 3cce2aa

Browse files
Merge pull request #71 from StartAutomating/PSSVG-Updates
Pssvg updates
2 parents 579c6f7 + 9cf67d4 commit 3cce2aa

File tree

119 files changed

+1396
-529
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

119 files changed

+1396
-529
lines changed

Assets/PSSVG.svg

Lines changed: 3 additions & 3 deletions
Loading

Build_PSSVG.ps1

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,6 @@ $OutputPath
689689
$paramCopy = [Ordered]@{} + $PSBoundParameters
690690
$myCmd = $MyInvocation.MyCommand
691691

692-
$inputObject = $_
693692
$elementName = foreach ($myAttr in $myCmd.ScriptBlock.Attributes) {
694693
if ($myAttr.Key -eq 'SVG.ElementName') {
695694
$myAttr.Value
@@ -714,8 +713,8 @@ $OutputPath
714713
if ($content) {
715714
$writeSvgSplat.Content = $content
716715
}
717-
if ($OutputPath) {
718-
$writeSvgSplat.OutputPath = $OutputPath
716+
if ($paramCopy['OutputPath']) {
717+
$writeSvgSplat.OutputPath = $paramCopy['OutputPath']
719718
}
720719

721720
if ($data) {

Build_PSSVG.ps1.ps1

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -704,7 +704,6 @@ $OutputPath
704704
$paramCopy = [Ordered]@{} + $PSBoundParameters
705705
$myCmd = $MyInvocation.MyCommand
706706

707-
$inputObject = $_
708707
$elementName = foreach ($myAttr in $myCmd.ScriptBlock.Attributes) {
709708
if ($myAttr.Key -eq 'SVG.ElementName') {
710709
$myAttr.Value
@@ -729,8 +728,8 @@ $OutputPath
729728
if ($content) {
730729
$writeSvgSplat.Content = $content
731730
}
732-
if ($OutputPath) {
733-
$writeSvgSplat.OutputPath = $OutputPath
731+
if ($paramCopy['OutputPath']) {
732+
$writeSvgSplat.OutputPath = $paramCopy['OutputPath']
734733
}
735734

736735
if ($data) {

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
### 0.2.7:
2+
* Adding SVG.Star (Fixes #68)
3+
* Fixing OutputPath issue (Fixes #67)
4+
* Renaming SVG.RegularPolygon to SVG.ConvexPolygon (Fixes #70)
5+
* Improving README and docs
6+
7+
---
8+
19
### 0.2.6:
210
* Adding SVG.RegularPolygon (Fixes #65)
311

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
1-
function SVG.RegularPolygon {
1+
function SVG.ConvexPolygon {
22
<#
33
.SYNOPSIS
4-
SVG Regular Polygon
4+
SVG Convex Polygon
55
.DESCRIPTION
6-
Creates a Regular Polygon of an number of sides.
6+
Creates a Regular Convex Polygon of an number of sides.
77
.LINK
8-
SVG.Polygon
8+
SVG.Path
99
#>
10-
[inherit('SVG.Polygon', Abstract,Dynamic, ExcludeParameter='Points')]
10+
[inherit('SVG.Path', Abstract,Dynamic, ExcludeParameter='D')]
1111
param(
1212
# The number of sides in the polygon
1313
[Parameter(ValueFromPipelineByPropertyName)]
14-
[Alias('NumberOfSides','SC','Sides','NumSides')]
14+
[Alias('NumberOfSides','SC','Sides','NumSides','PC','D','PointCount')]
15+
[ValidateRange(3,360)]
1516
[int]
1617
$SideCount,
1718

@@ -45,17 +46,21 @@ function SVG.RegularPolygon {
4546
foreach ($sideNumber in 1..$SideCount) {
4647
$pointY = $centerY + $r * [math]::round([math]::cos($angle * [Math]::PI/180),15)
4748
$pointX = $centerX + $r * [math]::round([math]::sin($angle * [Math]::PI/180),15)
48-
"$pointX, $pointY"
49+
if ($sideNumber -eq 1) {
50+
"M $pointX $pointY"
51+
} else {
52+
"L $pointX $pointY"
53+
}
4954
$angle += $anglePerPoint
5055
}) -join ' '
5156
$myParams = @{} + $PSBoundParameters
52-
$myParams["Points"] = $points
57+
$myParams["D"] = $points
5358
$myParams.Remove('SideCount')
5459
$myParams.Remove('Rotate')
5560
$myParams.Remove('Radius')
5661
$myParams.Remove('CenterX')
5762
$myParams.Remove('CenterY')
5863

59-
svg.Polygon @myParams
64+
svg.Path @myParams
6065
}
6166
}
Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
1-
function SVG.RegularPolygon {
1+
function SVG.ConvexPolygon {
22
<#
33
.SYNOPSIS
4-
SVG Regular Polygon
4+
SVG Convex Polygon
55
.DESCRIPTION
6-
Creates a Regular Polygon of an number of sides.
6+
Creates a Regular Convex Polygon of an number of sides.
77
.LINK
8-
SVG.Polygon
8+
SVG.Path
99
1010
#>
1111

1212
[CmdletBinding(PositionalBinding=$false)]
1313
param(
1414
# The number of sides in the polygon
1515
[Parameter(ValueFromPipelineByPropertyName)]
16-
[Alias('NumberOfSides','SC','Sides','NumSides')]
16+
[Alias('NumberOfSides','SC','Sides','NumSides','PC','D','PointCount')]
17+
[ValidateRange(3,360)]
1718
[int]
1819
$SideCount,
1920
# The initial rotation of the polygon.
@@ -35,15 +36,15 @@ function SVG.RegularPolygon {
3536
)
3637
dynamicParam {
3738
$baseCommand =
38-
if (-not $script:SVGPolygon) {
39-
$script:SVGPolygon =
40-
$executionContext.SessionState.InvokeCommand.GetCommand('SVG.Polygon','Function')
41-
$script:SVGPolygon
39+
if (-not $script:SVGPath) {
40+
$script:SVGPath =
41+
$executionContext.SessionState.InvokeCommand.GetCommand('SVG.Path','Function')
42+
$script:SVGPath
4243
} else {
43-
$script:SVGPolygon
44+
$script:SVGPath
4445
}
4546
$IncludeParameter = @()
46-
$ExcludeParameter = 'Points'
47+
$ExcludeParameter = 'D'
4748
$DynamicParameters = [Management.Automation.RuntimeDefinedParameterDictionary]::new()
4849
:nextInputParameter foreach ($paramName in ([Management.Automation.CommandMetaData]$baseCommand).Parameters.Keys) {
4950
if ($ExcludeParameter) {
@@ -76,18 +77,22 @@ dynamicParam {
7677
foreach ($sideNumber in 1..$SideCount) {
7778
$pointY = $centerY + $r * [math]::round([math]::cos($angle * [Math]::PI/180),15)
7879
$pointX = $centerX + $r * [math]::round([math]::sin($angle * [Math]::PI/180),15)
79-
"$pointX, $pointY"
80+
if ($sideNumber -eq 1) {
81+
"M $pointX $pointY"
82+
} else {
83+
"L $pointX $pointY"
84+
}
8085
$angle += $anglePerPoint
8186
}) -join ' '
8287
$myParams = @{} + $PSBoundParameters
83-
$myParams["Points"] = $points
88+
$myParams["D"] = $points
8489
$myParams.Remove('SideCount')
8590
$myParams.Remove('Rotate')
8691
$myParams.Remove('Radius')
8792
$myParams.Remove('CenterX')
8893
$myParams.Remove('CenterY')
8994

90-
svg.Polygon @myParams
95+
svg.Path @myParams
9196

9297
}
9398
}

Commands/Custom/SVG.Star.ps.ps1

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
function SVG.Star {
2+
<#
3+
.SYNOPSIS
4+
SVG Star
5+
.DESCRIPTION
6+
Creates a Star of an number of points.
7+
.LINK
8+
SVG.Path
9+
#>
10+
[inherit('SVG.Path', Abstract,Dynamic, ExcludeParameter='D')]
11+
param(
12+
# The number of sides in the polygon
13+
[Parameter(ValueFromPipelineByPropertyName)]
14+
[ValidateRange(3,360)]
15+
[Alias('PC','Points')]
16+
[int]
17+
$PointCount,
18+
19+
# The initial rotation of the polygon.
20+
[Alias('Rotation')]
21+
[double]
22+
$Rotate = 0,
23+
24+
# The center X coordinate for the polygon.
25+
[Alias('CX')]
26+
[double]
27+
$CenterX = 1,
28+
29+
# The center Y coordinate for the polygon.
30+
[Alias('CY')]
31+
[double]
32+
$CenterY = 1,
33+
34+
# The radius of the polygon.
35+
[Alias('R')]
36+
[double]
37+
$Radius = 1
38+
)
39+
40+
process {
41+
# We can construct a regular polygon by creating N points along a unit circle
42+
$anglePerPoint = 360 / $PointCount
43+
$r = $Radius
44+
$angle = $Rotate
45+
$q = 2
46+
$points = @()
47+
$vertices = @(
48+
foreach ($sideNumber in 1..$PointCount) {
49+
$pointY = $centerY + $r * [math]::round([math]::cos($angle * [Math]::PI/180),15)
50+
$pointX = $centerX + $r * [math]::round([math]::sin($angle * [Math]::PI/180),15)
51+
"$pointX $pointY"
52+
$angle += $anglePerPoint
53+
})
54+
55+
if ($vertices.Count % 2) {
56+
for ($pointIndex = 0; $points.Length -lt $PointCount; $pointIndex += $q) {
57+
58+
$vertex = $vertices[$pointIndex % $vertices.Count]
59+
60+
if (-not $points) {
61+
$points += "M $($vertices[$pointIndex % $vertices.Count])"
62+
} else {
63+
$points += "L $($vertices[$pointIndex % $vertices.Count])"
64+
}
65+
}
66+
$points += "L $($vertices[0])"
67+
} else {
68+
for ($pointIndex = 0; $pointIndex -le $vertices.Count; $pointIndex += $q) {
69+
$points +=
70+
if ($pointIndex -eq 0) {
71+
"M $($vertices[$pointIndex % $vertices.Count])"
72+
} else {
73+
"L $($vertices[$pointIndex % $vertices.Count])"
74+
}
75+
}
76+
for ($pointIndex = 1; $pointIndex -le ($vertices.Count + 1); $pointIndex += $q) {
77+
$points +=
78+
if ($pointIndex -eq 1) {
79+
"M $($vertices[$pointIndex % $vertices.Count])"
80+
} else {
81+
"L $($vertices[$pointIndex % $vertices.Count])"
82+
}
83+
84+
}
85+
}
86+
87+
88+
$myParams = @{} + $PSBoundParameters
89+
$myParams["D"] = $points -join ' '
90+
$myParams.Remove('PointCount')
91+
$myParams.Remove('Rotate')
92+
$myParams.Remove('Radius')
93+
$myParams.Remove('CenterX')
94+
$myParams.Remove('CenterY')
95+
96+
svg.Path @myParams
97+
98+
}
99+
}

0 commit comments

Comments
 (0)