add signature to quad-tree.sml, making it an opaque module

This commit is contained in:
2024-12-09 00:23:00 +00:00
parent 068f0277b9
commit 244640c1d6

View File

@@ -1,4 +1,17 @@
structure QuadTree = signature QUAD_TREE =
sig
type t
val insert : int * int * int * int *
int * int * int * int *
int * t -> t
val getCollisions : int * int * int * int *
int * int * int * int *
int * t -> int list
end
structure QuadTree : QUAD_TREE =
struct struct
type item = {itemID: int, startX: int, startY: int, width: int, height: int} type item = {itemID: int, startX: int, startY: int, width: int, height: int}
@@ -302,7 +315,7 @@ struct
val item = Vector.sub (elements, pos) val item = Vector.sub (elements, pos)
val acc = val acc =
if isColliding (iX, iY, iW, iH, itemID, item) if isColliding (iX, iY, iW, iH, itemID, item)
then item :: acc then #itemID item :: acc
else acc else acc
in in
getCollisionsVec (iX, iY, iW, iH, itemID, pos + 1, elements, acc) getCollisionsVec (iX, iY, iW, iH, itemID, pos + 1, elements, acc)
@@ -346,7 +359,7 @@ struct
| LEAF elements => | LEAF elements =>
getCollisionsVec (iX, iY, iW, iH, itemID, 0, elements, acc) getCollisionsVec (iX, iY, iW, iH, itemID, 0, elements, acc)
fun getCollisions fun helpGetCollisions
( itemX, itemY, itemWidth, itemHeight ( itemX, itemY, itemWidth, itemHeight
, quadX, quadY, quadWidth, quadHeight , quadX, quadY, quadWidth, quadHeight
, itemID, acc, tree: t , itemID, acc, tree: t
@@ -369,25 +382,25 @@ struct
) )
of of
TOP_LEFT => TOP_LEFT =>
getCollisions helpGetCollisions
( itemX, itemY, itemWidth, itemHeight ( itemX, itemY, itemWidth, itemHeight
, quadX, quadY, halfWidth, halfHeight , quadX, quadY, halfWidth, halfHeight
, itemID, acc, topLeft , itemID, acc, topLeft
) )
| TOP_RIGHT => | TOP_RIGHT =>
getCollisions helpGetCollisions
( itemX, itemY, itemWidth, itemHeight ( itemX, itemY, itemWidth, itemHeight
, quadX + halfWidth, quadY, halfWidth, halfHeight , quadX + halfWidth, quadY, halfWidth, halfHeight
, itemID, acc, topRight , itemID, acc, topRight
) )
| BOTTOM_LEFT => | BOTTOM_LEFT =>
getCollisions helpGetCollisions
( itemX, itemY, itemWidth, itemHeight ( itemX, itemY, itemWidth, itemHeight
, quadX, quadY + halfHeight, halfWidth, halfHeight , quadX, quadY + halfHeight, halfWidth, halfHeight
, itemID, acc, bottomLeft , itemID, acc, bottomLeft
) )
| BOTTOM_RIGHT => | BOTTOM_RIGHT =>
getCollisions helpGetCollisions
( itemX, itemY, itemWidth, itemHeight ( itemX, itemY, itemWidth, itemHeight
, quadX + halfWidth, quadY + halfHeight , quadX + halfWidth, quadY + halfHeight
, halfWidth, halfHeight , halfWidth, halfHeight
@@ -435,13 +448,14 @@ struct
, itemID, 0, elements, acc , itemID, 0, elements, acc
) )
datatype t = fun getCollisions
NODE of ( itemX, itemY, itemWidth, itemHeight
{ topLeft: t , quadX, quadY, quadWidth, quadHeight
, topRight: t , itemID, tree
, bottomLeft: t ) =
, bottomRight: t helpGetCollisions
, elements: item vector ( itemX, itemY, itemWidth, itemHeight
} , quadX, quadY, quadWidth, quadHeight
| LEAF of item vector , itemID, [], tree
)
end end