From af77530a17b7d986addc247fb2775f05057f4f61 Mon Sep 17 00:00:00 2001 From: treeform Date: Mon, 4 Oct 2021 12:16:10 -0700 Subject: [PATCH] Fix draw correct. --- src/pixie/images.nim | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/src/pixie/images.nim b/src/pixie/images.nim index d63f347..e263dba 100644 --- a/src/pixie/images.nim +++ b/src/pixie/images.nim @@ -588,21 +588,28 @@ proc drawCorrect( var matInv = mat.inverse() + # Compute movement vectors + p = matInv * vec2(0 + h, 0 + h) + dx = matInv * vec2(1 + h, 0 + h) - p + dy = matInv * vec2(0 + h, 1 + h) - p + filterBy2 = max(dx.length, dy.length) b = b - block: # Shrink by 2 as needed - var - p = matInv * vec2(0 + h, 0 + h) - dx = matInv * vec2(1 + h, 0 + h) - p - dy = matInv * vec2(0 + h, 1 + h) - p - minFilterBy2 = max(dx.length, dy.length) + while filterBy2 >= 2.0: + b = b.minifyBy2() + p /= 2 + dx /= 2 + dy /= 2 + filterBy2 /= 2 + matInv = scale(vec2(1/2, 1/2)) * matInv - while minFilterBy2 >= 2: - b = b.minifyBy2() - dx /= 2 - dy /= 2 - minFilterBy2 /= 2 - matInv = matInv * scale(vec2(0.5, 0.5)) + while filterBy2 <= 0.5: + b = b.magnifyBy2() + p *= 2 + dx *= 2 + dy *= 2 + filterBy2 *= 2 + matInv = scale(vec2(2, 2)) * matInv for y in 0 ..< a.height: for x in 0 ..< a.width: