Skip to content

Commit e6fac21

Browse files
Merge pull request #66 from StartAutomating/SVG-Regular-Polygon
Svg regular polygon
2 parents 8d721bc + bbe8a52 commit e6fac21

File tree

15 files changed

+349
-64
lines changed

15 files changed

+349
-64
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
### 0.2.6:
2+
* Adding SVG.RegularPolygon (Fixes #65)
3+
4+
---
5+
6+
17
### 0.2.5:
28
* ConvertTo-PSSVG improvements:
39
* Better at handling malformed XML (#59)
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
function SVG.RegularPolygon {
2+
<#
3+
.SYNOPSIS
4+
SVG Regular Polygon
5+
.DESCRIPTION
6+
Creates a Regular Polygon of an number of sides.
7+
.LINK
8+
SVG.Polygon
9+
#>
10+
[inherit('SVG.Polygon', Abstract,Dynamic, ExcludeParameter='Points')]
11+
param(
12+
# The number of sides in the polygon
13+
[Parameter(ValueFromPipelineByPropertyName)]
14+
[Alias('NumberOfSides','SC','Sides','NumSides')]
15+
[int]
16+
$SideCount,
17+
18+
# The initial rotation of the polygon.
19+
[Alias('Rotation')]
20+
[double]
21+
$Rotate = 0,
22+
23+
# The center X coordinate for the polygon.
24+
[Alias('CX')]
25+
[double]
26+
$CenterX = 1,
27+
28+
# The center Y coordinate for the polygon.
29+
[Alias('CY')]
30+
[double]
31+
$CenterY = 1,
32+
33+
# The radius of the polygon.
34+
[Alias('R')]
35+
[double]
36+
$Radius = 1
37+
)
38+
39+
process {
40+
# We can construct a regular polygon by creating N points along a unit circle
41+
$anglePerPoint = 360 / $SideCount
42+
$r = $Radius
43+
$angle = $Rotate
44+
$points = @(
45+
foreach ($sideNumber in 1..$SideCount) {
46+
$pointY = $centerY + $r * [math]::round([math]::cos($angle * [Math]::PI/180),15)
47+
$pointX = $centerX + $r * [math]::round([math]::sin($angle * [Math]::PI/180),15)
48+
"$pointX, $pointY"
49+
$angle += $anglePerPoint
50+
}) -join ' '
51+
$myParams = @{} + $PSBoundParameters
52+
$myParams["Points"] = $points
53+
$myParams.Remove('SideCount')
54+
$myParams.Remove('Rotate')
55+
$myParams.Remove('Radius')
56+
$myParams.Remove('CenterX')
57+
$myParams.Remove('CenterY')
58+
59+
svg.Polygon @myParams
60+
}
61+
}
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
function SVG.RegularPolygon {
2+
<#
3+
.SYNOPSIS
4+
SVG Regular Polygon
5+
.DESCRIPTION
6+
Creates a Regular Polygon of an number of sides.
7+
.LINK
8+
SVG.Polygon
9+
10+
#>
11+
12+
[CmdletBinding(PositionalBinding=$false)]
13+
param(
14+
# The number of sides in the polygon
15+
[Parameter(ValueFromPipelineByPropertyName)]
16+
[Alias('NumberOfSides','SC','Sides','NumSides')]
17+
[int]
18+
$SideCount,
19+
# The initial rotation of the polygon.
20+
[Alias('Rotation')]
21+
[double]
22+
$Rotate = 0,
23+
# The center X coordinate for the polygon.
24+
[Alias('CX')]
25+
[double]
26+
$CenterX = 1,
27+
# The center Y coordinate for the polygon.
28+
[Alias('CY')]
29+
[double]
30+
$CenterY = 1,
31+
# The radius of the polygon.
32+
[Alias('R')]
33+
[double]
34+
$Radius = 1
35+
)
36+
dynamicParam {
37+
$baseCommand =
38+
if (-not $script:SVGPolygon) {
39+
$script:SVGPolygon =
40+
$executionContext.SessionState.InvokeCommand.GetCommand('SVG.Polygon','Function')
41+
$script:SVGPolygon
42+
} else {
43+
$script:SVGPolygon
44+
}
45+
$IncludeParameter = @()
46+
$ExcludeParameter = 'Points'
47+
$DynamicParameters = [Management.Automation.RuntimeDefinedParameterDictionary]::new()
48+
:nextInputParameter foreach ($paramName in ([Management.Automation.CommandMetaData]$baseCommand).Parameters.Keys) {
49+
if ($ExcludeParameter) {
50+
foreach ($exclude in $ExcludeParameter) {
51+
if ($paramName -like $exclude) { continue nextInputParameter}
52+
}
53+
}
54+
if ($IncludeParameter) {
55+
$shouldInclude =
56+
foreach ($include in $IncludeParameter) {
57+
if ($paramName -like $include) { $true;break}
58+
}
59+
if (-not $shouldInclude) { continue nextInputParameter }
60+
}
61+
62+
$DynamicParameters.Add($paramName, [Management.Automation.RuntimeDefinedParameter]::new(
63+
$baseCommand.Parameters[$paramName].Name,
64+
$baseCommand.Parameters[$paramName].ParameterType,
65+
$baseCommand.Parameters[$paramName].Attributes
66+
))
67+
}
68+
$DynamicParameters
69+
}
70+
process {
71+
# We can construct a regular polygon by creating N points along a unit circle
72+
$anglePerPoint = 360 / $SideCount
73+
$r = $Radius
74+
$angle = $Rotate
75+
$points = @(
76+
foreach ($sideNumber in 1..$SideCount) {
77+
$pointY = $centerY + $r * [math]::round([math]::cos($angle * [Math]::PI/180),15)
78+
$pointX = $centerX + $r * [math]::round([math]::sin($angle * [Math]::PI/180),15)
79+
"$pointX, $pointY"
80+
$angle += $anglePerPoint
81+
}) -join ' '
82+
$myParams = @{} + $PSBoundParameters
83+
$myParams["Points"] = $points
84+
$myParams.Remove('SideCount')
85+
$myParams.Remove('Rotate')
86+
$myParams.Remove('Radius')
87+
$myParams.Remove('CenterX')
88+
$myParams.Remove('CenterY')
89+
90+
svg.Polygon @myParams
91+
92+
}
93+
}

Examples/BPMAnimate.svg

Lines changed: 24 additions & 24 deletions
Loading

Examples/BPMMorph.svg

Lines changed: 1 addition & 1 deletion
Loading

Examples/StarRating.svg

Lines changed: 5 additions & 5 deletions
Loading

PSSVG.format.ps1xml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="utf-16"?>
2-
<!-- Generated with EZOut 1.9.6: Install-Module EZOut or https://github.com/StartAutomating/EZOut -->
2+
<!-- Generated with EZOut 1.9.7: Install-Module EZOut or https://github.com/StartAutomating/EZOut -->
33
<Configuration>
44
<Controls>
55
<Control>
@@ -344,7 +344,7 @@ $script:TreeDepth++;</ScriptBlock>
344344

345345
$n =0
346346
$cssClasses = @()
347-
$styleAttributes =
347+
$colorAttributes =
348348
@(:nextColor foreach ($hc in $ForegroundColor,$BackgroundColor) {
349349
$n++
350350
if (-not $hc) { continue }
@@ -476,6 +476,7 @@ $script:TreeDepth++;</ScriptBlock>
476476

477477
})
478478

479+
$styleAttributes = @() + $colorAttributes
479480

480481
$styleAttributes += @(
481482
if ($Bold) {
@@ -550,7 +551,7 @@ $script:TreeDepth++;</ScriptBlock>
550551
"&lt;/span&gt;"
551552
}
552553
elseif ($canUseANSI) {
553-
if ($Bold -or $Faint) {
554+
if ($Bold -or $Faint -or $colorAttributes -match '\[1;') {
554555
"$esc[22m"
555556
}
556557
if ($Italic) {

PSSVG.psd1

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
@{
2-
ModuleVersion = '0.2.5'
2+
ModuleVersion = '0.2.6'
33
Guid = '77696e6e-0252-43f2-b914-2dfa63953c60'
44
CompanyName = 'Start-Automating'
55
Copyright = '2022 Start-Automating'
@@ -14,6 +14,11 @@
1414
ProjectURI = 'https://github.com/StartAutomating/PSSVG'
1515
LicenseURI = 'https://github.com/StartAutomating/PSSVG/blob/main/LICENSE'
1616
ReleaseNotes = @'
17+
### 0.2.6:
18+
* Adding SVG.RegularPolygon (Fixes #65)
19+
20+
---
21+
1722
### 0.2.5:
1823
* ConvertTo-PSSVG improvements:
1924
* Better at handling malformed XML (#59)

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ The following elements are supported:
7878
|[polyline](docs/SVG.polyline.md) |[SVG.polyline](SVG.polyline.ps1) |=&lt;svg.polyline&gt; |
7979
|[radialGradient](docs/SVG.radialGradient.md) |[SVG.radialGradient](SVG.radialGradient.ps1) |=&lt;svg.radialGradient&gt; |
8080
|[rect](docs/SVG.rect.md) |[SVG.rect](SVG.rect.ps1) |=&lt;svg.rect&gt; |
81+
|[](docs/SVG.RegularPolygon.md) |[SVG.RegularPolygon](SVG.RegularPolygon.ps1) |=&lt;svg.RegularPolygon&gt; |
8182
|[script](docs/SVG.script.md) |[SVG.script](SVG.script.ps1) |=&lt;svg.script&gt; |
8283
|[set](docs/SVG.set.md) |[SVG.set](SVG.set.ps1) |=&lt;svg.set&gt; |
8384
|[](docs/SVG.Spiral.md) |[SVG.Spiral](SVG.Spiral.ps1) |=&lt;svg.Spiral&gt; |

docs/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
### 0.2.6:
2+
* Adding SVG.RegularPolygon (Fixes #65)
3+
4+
---
5+
6+
17
### 0.2.5:
28
* ConvertTo-PSSVG improvements:
39
* Better at handling malformed XML (#59)

0 commit comments

Comments
 (0)