improve creation of click points, so that we can have a pixel be a perfect square, even if the canvas isn't

This commit is contained in:
2025-07-11 00:57:29 +01:00
parent 8e8947379a
commit d5fda8b488
4 changed files with 23 additions and 36 deletions

View File

@@ -1,12 +1,23 @@
structure ClickPoints =
struct
fun generate (start, finish, numPoints) =
fun generate (windowWidth, windowHeight, canvasWidth, canvasHeight) =
let
val difference = finish - start
val increment = Real32.fromInt difference / Real32.fromInt numPoints
val realWindowWidth = Real32.fromInt windowWidth
val realCanvasWidth = Real32.fromInt canvasWidth
val realWindowHeight = Real32.fromInt windowHeight
val realCanvasHeight = Real32.fromInt canvasHeight
val xPixelSize = realWindowWidth / realCanvasWidth
val yPixelSize = realWindowHeight / realCanvasHeight
val pixelSize = Real32.min (xPixelSize, yPixelSize)
val xClickPoints = Vector.tabulate (canvasWidth + 1, fn i =>
Real32.fromInt i * pixelSize)
val yClickPoints = Vector.tabulate (canvasHeight + 1, fn i =>
Real32.fromInt i * pixelSize)
in
Vector.tabulate (numPoints + 1, fn idx =>
(Real32.fromInt idx * increment))
(xClickPoints, yClickPoints)
end
fun getClickPos (clickPoints, mousePos, idx) =