This commit is contained in:
Ryan Oldenburg 2021-11-22 18:00:51 -06:00
parent f246c1dd15
commit 69eaf60158
2 changed files with 9 additions and 6 deletions

View file

@ -990,6 +990,9 @@ proc superImage*(image: Image, x, y, w, h: int): Image {.raises: [PixieError].}
## Either cuts a sub image or returns a super image with padded transparency.
if x >= 0 and x + w <= image.width and y >= 0 and y + h <= image.height:
result = image.subImage(x, y, w, h)
elif abs(x) >= image.width or abs(y) >= image.height:
# Nothing to copy, just an empty new image
result = newImage(w, h)
else:
result = newImage(w, h)
result.draw(image, translate(vec2(-x.float32, -y.float32)), bmOverwrite)

View file

@ -45,7 +45,7 @@ type
startY, partitionHeight: uint32
const
epsilon = 0.0001 * PI ## Tiny value used for some computations.
epsilon: float64 = 0.0001 * PI ## Tiny value used for some computations. Must be float64 to prevent leaks.
defaultMiterLimit*: float32 = 4
when defined(release):
@ -651,7 +651,7 @@ proc commandsToShapes(
prevCommandKind = Move
prevCtrl, prevCtrl2: Vec2
let errorMargin = pow(0.2.float32 / pixelScale, 2)
let errorMarginSq = pow(0.2.float32 / pixelScale, 2)
proc addSegment(shape: var seq[Vec2], at, to: Vec2) =
# Don't add any 0 length lines
@ -679,7 +679,7 @@ proc commandsToShapes(
let
midpoint = (prev + next) / 2
error = (midpoint - halfway).lengthSq
if error > errorMargin:
if error > errorMarginSq:
next = halfway
halfway = compute(at, ctrl1, ctrl2, to, t + step / 4)
step /= 2
@ -711,7 +711,7 @@ proc commandsToShapes(
let
midpoint = (prev + next) / 2
error = (midpoint - halfway).lengthSq
if error > errorMargin:
if error > errorMarginSq:
next = halfway
halfway = compute(at, ctrl, to, t + step / 4)
step /= 2
@ -831,12 +831,12 @@ proc commandsToShapes(
halfway = arc.compute(aPrev + (a - aPrev) / 2)
midpoint = (prev + next) / 2
error = (midpoint - halfway).lengthSq
if error > errorMargin:
if error > errorMarginSq:
let
quarterway = arc.compute(aPrev + (a - aPrev) / 4)
midpoint = (prev + halfway) / 2
halfwayError = (midpoint - quarterway).lengthSq
if halfwayError < errorMargin:
if halfwayError < errorMarginSq:
shape.addSegment(prev, halfway)
prev = halfway
t += step / 2