Skip to content

Commit d4718dd

Browse files
feat: Turtle.get_Marker ( Fixes #227 )
1 parent 6c758ba commit d4718dd

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

Types/Turtle/get_Marker.ps1

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<#
2+
.SYNOPSIS
3+
Gets the turtle as a Marker
4+
.DESCRIPTION
5+
Gets the Turtle as a `<marker>`, which can mark points on another shape.
6+
.EXAMPLE
7+
turtle viewbox 200 teleport 0 100 forward 100 markerEnd (
8+
turtle viewbox 10 rotate -90 polygon 10 3 fill context-fill stroke context-stroke
9+
) strokewidth '3%' save ./marker.svg
10+
.LINK
11+
https://developer.mozilla.org/en-US/docs/Web/SVG/Reference/Element/marker
12+
#>
13+
param()
14+
15+
# The default settings for markers
16+
$markerAttributes = [Ordered]@{
17+
id="$($this.id)-marker"
18+
viewBox="$($this.ViewBox)"
19+
orient='auto-start-reverse'
20+
refX=0
21+
refY=$this.Height/2
22+
markerWidth=5
23+
marketHeight=5
24+
}
25+
# Marker attributes can exist in .Attribute or .SVGAttribute
26+
$prefix = [Regex]::new('^/?marker/', 'IgnoreCase')
27+
foreach ($collection in $this.Attribute, $this.SVGAttribute) {
28+
foreach ($key in $collection.Keys) {
29+
if ($key -notmatch $prefix) { continue }
30+
$markerAttributes[$key -replace $prefix] = $collection[$key]
31+
}
32+
}
33+
34+
# Create a marker XML.
35+
[xml]@(
36+
"<marker$(
37+
foreach ($key in $markerAttributes.Keys) {
38+
" $key='$($markerAttributes[$key])'"
39+
}
40+
)>"
41+
$this.SVG.SVG.InnerXML
42+
"</marker>"
43+
)

0 commit comments

Comments
 (0)