From 205f091012eb22dd1325ea95b27ebd1299336898 Mon Sep 17 00:00:00 2001 From: Ryan Oldenburg Date: Fri, 25 Jun 2021 17:07:14 -0500 Subject: [PATCH] shorter --- src/pixie/images.nim | 22 +++++++++------------- src/pixie/masks.nim | 26 +++++++++++++------------- 2 files changed, 22 insertions(+), 26 deletions(-) diff --git a/src/pixie/images.nim b/src/pixie/images.nim index 7097630..68c1bb4 100644 --- a/src/pixie/images.nim +++ b/src/pixie/images.nim @@ -517,16 +517,12 @@ proc getRgbaSmooth*(image: Image, x, y: float32, wrapped = false): ColorRGBX = ## Gets a interpolated color with float point coordinates. ## Pixes outside the image are transparent. let - minX = floor(x) - minY = floor(y) - diffX = x - minX - diffY = y - minY - x = minX.int - y = minY.int - x0 = (x + 0) - y0 = (y + 0) - x1 = (x + 1) - y1 = (y + 1) + x0 = x.int + y0 = y.int + x1 = x0 + 1 + y1 = y0 + 1 + xFractional = x.fractional + yFractional = y.fractional var x0y0, x1y0, x0y1, x1y1: ColorRGBX if wrapped: @@ -541,10 +537,10 @@ proc getRgbaSmooth*(image: Image, x, y: float32, wrapped = false): ColorRGBX = x1y1 = image[x1, y1] let - bottomMix = lerp(x0y0, x1y0, diffX) - topMix = lerp(x0y1, x1y1, diffX) + bottomMix = lerp(x0y0, x1y0, xFractional) + topMix = lerp(x0y1, x1y1, xFractional) - lerp(bottomMix, topMix, diffY) + lerp(bottomMix, topMix, yFractional) proc drawCorrect( a, b: Image | Mask, mat = mat3(), tiled = false, blendMode = bmNormal diff --git a/src/pixie/masks.nim b/src/pixie/masks.nim index 9887e6e..30cafcf 100644 --- a/src/pixie/masks.nim +++ b/src/pixie/masks.nim @@ -159,22 +159,22 @@ proc fill*(mask: Mask, value: uint8) {.inline.} = proc getValueSmooth*(mask: Mask, x, y: float32): uint8 = ## Gets a interpolated value with float point coordinates. let - minX = floor(x) - minY = floor(y) - diffX = x - minX - diffY = y - minY - x = minX.int - y = minY.int + x0 = x.int + y0 = y.int + x1 = x0 + 1 + y1 = y0 + 1 + xFractional = x.fractional + yFractional = y.fractional - x0y0 = mask[x + 0, y + 0] - x1y0 = mask[x + 1, y + 0] - x0y1 = mask[x + 0, y + 1] - x1y1 = mask[x + 1, y + 1] + x0y0 = mask[x0, y0] + x1y0 = mask[x1, y0] + x0y1 = mask[x0, y1] + x1y1 = mask[x1, y1] - bottomMix = lerp(x0y0, x1y0, diffX) - topMix = lerp(x0y1, x1y1, diffX) + bottomMix = lerp(x0y0, x1y0, xFractional) + topMix = lerp(x0y1, x1y1, xFractional) - lerp(bottomMix, topMix, diffY) + lerp(bottomMix, topMix, yFractional) proc spread*(mask: Mask, spread: float32) = ## Grows the mask by spread.