Skip to content

Commit 535c124

Browse files
fix: Turtle.get/set_ViewBox negative bounds ( Fixes #286 )
Resetting PathDatato older calculations and adjusting pie graphs
1 parent 6adee38 commit 535c124

File tree

2 files changed

+26
-25
lines changed

2 files changed

+26
-25
lines changed

Types/Turtle/PieGraph.ps1

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,12 @@
9595
Add-Member ScriptProperty Fill {
9696
"#{0:x6}" -f (Get-Random -Maximum 0xffffff)
9797
} -Force -PassThru |
98-
Add-Member ScriptProperty Link {
99-
"https://learn.microsoft.com/en-us/dotnet/api/$($this.Name.ToLower())"
100-
} -Force -PassThru
98+
Add-Member ScriptProperty Title {
99+
$this.Name
100+
} -Force -PassThru |
101+
Add-Member ScriptProperty Link {
102+
"https://learn.microsoft.com/en-us/dotnet/api/$($this.Name.ToLower())?wt.mc_id=MVP_321542"
103+
} -Force -PassThru
101104
) save ./TurtleDotNetTypesPieGraph.svg
102105
.EXAMPLE
103106
$n = Get-Random -Min 5 -Max 10
@@ -263,13 +266,11 @@ else {
263266
$heading = $this.Heading
264267
if (-not $heading) { $heading = 0.0 }
265268
# Calulate the midpoint of the circle
266-
$midX = $this.X + ($dx - $this.X)/2
267-
$midY = $this.Y + ($dy - $this.Y)/2
268269
for ($sliceNumber =0 ; $sliceNumber -lt $Slices.Length; $sliceNumber++) {
269270
$Angle = $relativeSlices[$sliceNumber] * 360
270-
$sliceName = "slice$sliceNumber"
271+
$sliceName = "slice$sliceNumber"
271272
# created a nested turtle at the midpoint
272-
$nestedTurtles["slice$sliceNumber"] = turtle teleport $this.X $this.Y
273+
$nestedTurtles["slice$sliceNumber"] = turtle start $dx $dy
273274
# with the current heading
274275
$nestedTurtles["slice$sliceNumber"].Heading = $this.Heading
275276
# and arc by the angle
@@ -303,6 +304,7 @@ else {
303304
}
304305
# and set our nested turtles.
305306
$this.Turtles = $nestedTurtles
307+
# $null = $this.ResizeViewBox($Radius)
306308
}
307309

308310
return $this

Types/Turtle/get_PathData.ps1

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,41 +30,40 @@
3030
# This is a much less common request than moving the turtle forward.
3131
$precision = $this.Precision
3232
filter roundToPrecision { [Math]::Round($_, $precision)}
33-
$viewBox = $this.'.Viewbox'
3433

3534
if ($null -ne $this.Start.X -and $null -ne $this.Start.Y) {
3635
if ($precision) {
3736
"m $($this.Start.x | roundToPrecision) $($this.Start.y | roundToPrecision)"
3837
} else {
3938
"m $($this.Start.x) $($this.Start.y)"
40-
}
41-
}
39+
}
40+
41+
}
4242
else {
4343
@("m"
4444
# If the viewbox has been manually set
45-
if ($viewBox) {
45+
if ($this.'.ViewBox') {
4646
0, 0 # do not adjust our starting position
4747
} else {
48-
$viewBox = $this.ViewBox
49-
if ([Math]::Round($this.Mimimum.X) -lt 0) {
48+
# otherwise, translate by the minimum point.
49+
if ($this.Minimum.X -lt 0) {
5050
if ($precision) {
51-
$viewBox[-2] | roundToPrecision
51+
-1 * $this.Minimum.X | roundToPrecision
5252
} else {
53-
$viewBox[-2]
54-
}
55-
56-
} else {
57-
0
53+
-1 * $this.Minimum.X
54+
}
5855
}
59-
if ([Math]::Round($this.Minimum.Y) -lt 0) {
56+
else { 0 }
57+
58+
if ($this.Minimum.Y -lt 0) {
6059
if ($precision) {
61-
$viewBox[-1] | roundToPrecision
60+
-1 * $this.Minimum.Y | roundToPrecision
6261
} else {
63-
$viewBox[-1]
62+
-1 * $this.Minimum.Y
6463
}
65-
} else {
66-
0
67-
}
64+
65+
}
66+
else { 0 }
6867
}) -join ' '
6968
}
7069

0 commit comments

Comments
 (0)