progress with refactoring
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
structure Ndc =
|
structure Ndc =
|
||||||
struct
|
struct
|
||||||
(* ndc = normalised device coordinates *)
|
(* ndc = normalised device coordinates *)
|
||||||
|
|
||||||
fun ltrbToVertex (left, top, right, bottom) =
|
fun ltrbToVertex (left, top, right, bottom) =
|
||||||
#[ left, bottom
|
#[ left, bottom
|
||||||
, right, bottom
|
, right, bottom
|
||||||
@@ -20,4 +21,36 @@ struct
|
|||||||
, right, bottom, r, g, b
|
, right, bottom, r, g, b
|
||||||
, right, top, r, g, b
|
, right, top, r, g, b
|
||||||
]
|
]
|
||||||
|
|
||||||
|
fun fromPixelX (xpos, windowWidth, windowHeight) =
|
||||||
|
let
|
||||||
|
val halfWidth = (Real32.fromInt windowWidth) / 2.0
|
||||||
|
val xpos = xpos - halfWidth
|
||||||
|
in
|
||||||
|
if windowWidth > windowHeight then
|
||||||
|
let
|
||||||
|
val difference = windowWidth - windowHeight
|
||||||
|
val offset = Real32.fromInt (difference div 2)
|
||||||
|
in
|
||||||
|
xpos / (halfWidth - offset)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
xpos / halfWidth
|
||||||
|
end
|
||||||
|
|
||||||
|
fun fromPixelY (ypos, windowWidth, windowHeight) =
|
||||||
|
let
|
||||||
|
val halfHeight = (Real32.fromInt windowHeight) / 2.0
|
||||||
|
val ypos = ~(ypos - halfHeight)
|
||||||
|
in
|
||||||
|
if windowHeight > windowWidth then
|
||||||
|
let
|
||||||
|
val difference = windowHeight - windowWidth
|
||||||
|
val offset = Real32.fromInt (difference div 2)
|
||||||
|
in
|
||||||
|
ypos / (halfHeight - offset)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
ypos / halfHeight
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -225,8 +225,15 @@ struct
|
|||||||
foldWithDuplicates (f, br, acc)
|
foldWithDuplicates (f, br, acc)
|
||||||
end
|
end
|
||||||
|
|
||||||
fun insertItemIntoTree (item, acc) =
|
fun insertItemIntoTree ignoreData (item, acc) =
|
||||||
BinTree.insert (item, acc)
|
if #data item = 0 then
|
||||||
|
(* ignore specific data by not inserting it into tree.
|
||||||
|
* May later functorise this quad tree,
|
||||||
|
* and allow different types of data
|
||||||
|
* to be ignored/stored in #data field. *)
|
||||||
|
acc
|
||||||
|
else
|
||||||
|
BinTree.insert (item, acc)
|
||||||
|
|
||||||
fun toList qtree =
|
fun toList qtree =
|
||||||
let
|
let
|
||||||
@@ -234,4 +241,19 @@ struct
|
|||||||
in
|
in
|
||||||
BinTree.toList (tree, [])
|
BinTree.toList (tree, [])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
fun toTriangles (windowWidth, windowHeight, squares, acc) =
|
||||||
|
case squares of
|
||||||
|
{x, y, ex, ey, data = _} :: tl =>
|
||||||
|
let
|
||||||
|
val startX = Ndc.fromPixelX (x, windowWidth, windowHeight)
|
||||||
|
val endX = Ndc.fromPixelX (ex, windowWidth, windowHeight)
|
||||||
|
val startY = Ndc.fromPixelY (y, windowWidth, windowHeight)
|
||||||
|
val endY = Ndc.fromPixelY (ey, windowWidth, windowHeight)
|
||||||
|
|
||||||
|
val acc = Ndc.ltrbToVertex (startX, startY, endX, endY) :: acc
|
||||||
|
in
|
||||||
|
toTriangles (windowWidth, windowHeight, tl, acc)
|
||||||
|
end
|
||||||
|
| [] => Vector.concat acc
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user