From 2b67d52861f9074bb310433fba4d6f27af28f9ad Mon Sep 17 00:00:00 2001 From: treeform Date: Fri, 27 Nov 2020 21:50:42 -0800 Subject: [PATCH] Move fractional to common. --- src/pixie/common.nim | 6 ++++++ src/pixie/images.nim | 9 ++------- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/pixie/common.nim b/src/pixie/common.nim index 9228e92..437af41 100644 --- a/src/pixie/common.nim +++ b/src/pixie/common.nim @@ -32,3 +32,9 @@ proc intersects*(a, b: Segment, at: var Vec2): bool = at.y = a.at.y + (t * s1y) return true return false + +proc fractional*(v: float32): float32 = + ## Returns unsigned fraction part of the float. + ## -13.7868723 -> 0.7868723 + result = abs(v) + result = result - floor(result) diff --git a/src/pixie/images.nim b/src/pixie/images.nim index 481dcba..1da18b7 100644 --- a/src/pixie/images.nim +++ b/src/pixie/images.nim @@ -41,12 +41,6 @@ proc `$`*(image: Image): string = ## Display the image size and channels. "" -proc fractional(v: float32): float32 = - ## Returns unsigned fraction part of the float. - ## -13.7868723 -> 0.7868723 - result = abs(v) - result = result - floor(result) - proc inside*(image: Image, x, y: int): bool {.inline.} = ## Returns true if (x, y) is inside the image. x >= 0 and x < image.width and @@ -517,7 +511,7 @@ proc draw*(a: Image, b: Image, mat: Mat3, blendMode: BlendMode) = mat[2, 0].fractional == 0.0 and mat[2, 1].fractional == 0.0) if not smooth: - #echo "copy non-smooth" + #echo "draw ", b.width, "x", b.height, " fast" case blendMode of bmNormal: drawUberStatic(a, b, c, start, stepX, stepY, lines, bmNormal, true, false) of bmDarken: drawUberStatic(a, b, c, start, stepX, stepY, lines, bmDarken, true, false) @@ -543,6 +537,7 @@ proc draw*(a: Image, b: Image, mat: Mat3, blendMode: BlendMode) = of bmIntersectMask: drawUberStatic(a, b, c, start, stepX, stepY, lines, bmIntersectMask, true, false) of bmExcludeMask: drawUberStatic(a, b, c, start, stepX, stepY, lines, bmExcludeMask, true, false) else: + #echo "draw ", b.width, "x", b.height, " smooth" case blendMode of bmNormal: drawUberStatic(a, b, c, start, stepX, stepY, lines, bmNormal, true, true) of bmDarken: drawUberStatic(a, b, c, start, stepX, stepY, lines, bmDarken, true, true)