Skip to content

Commit 8febc93

Browse files
feat: Turtle.get_ViewBox rounding to precision ( Fixes #225 )
Unrounded viewboxes with floating points can be a bit misleading
1 parent 4d0e626 commit 8febc93

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

Types/Turtle/get_ViewBox.ps1

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,23 @@ $viewBox = ($this.Maximum - $this.Minimum)
2020
$precision = $this.Precision
2121
filter roundToPrecision { [Math]::Round($_, $precision)}
2222

23+
24+
$viewX = [Math]::Round($viewBox.X, 10)
25+
$viewY = [Math]::Round($viewBox.Y, 10)
26+
27+
if ($viewX -and -not $viewY) {
28+
$viewY = $viewX
29+
}
30+
if ($viewY -and -not $viewX) {
31+
$viewX = $viewY
32+
}
33+
34+
2335
# and return the viewbox
2436
if ($precision) {
25-
return 0, 0, $viewBox.X, $viewBox.Y | roundToPrecision
37+
return 0, 0, $viewX, $viewY | roundToPrecision
2638
} else {
27-
return 0, 0, $viewBox.X, $viewBox.Y
39+
return 0, 0, $viewX, $viewY
2840
}
2941

3042

0 commit comments

Comments
 (0)