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:
@@ -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) =
|
||||
|
||||
Reference in New Issue
Block a user