fix bug in not properly updating squares vector
This commit is contained in:
@@ -2,6 +2,24 @@ structure AppWith =
|
||||
struct
|
||||
open AppType
|
||||
|
||||
fun toList vec = Vector.foldr (fn (el, acc) => el :: acc) [] vec
|
||||
|
||||
fun squaresToString squares =
|
||||
let
|
||||
val vec =
|
||||
Vector.map (fn vec =>
|
||||
let
|
||||
val vec = Vector.map (fn num => Int.toString num) vec
|
||||
val vec: string list = toList vec
|
||||
in
|
||||
String.concat vec
|
||||
end
|
||||
) squares
|
||||
val vec = toList vec
|
||||
in
|
||||
String.concatWith "\n" vec
|
||||
end
|
||||
|
||||
fun addSquare (app, newX, newY, arrowX, arrowY) : app_type =
|
||||
let
|
||||
val
|
||||
@@ -28,6 +46,7 @@ struct
|
||||
, modalNum
|
||||
} = app
|
||||
|
||||
val () = print "adding new square\n"
|
||||
val squares =
|
||||
Vector.mapi
|
||||
(fn (idx, el) =>
|
||||
@@ -35,6 +54,9 @@ struct
|
||||
Vector.mapi (fn (iidx, iel) => if iidx = newY then 1 else iel) el
|
||||
else
|
||||
el) squares
|
||||
|
||||
val msg = squaresToString squares
|
||||
val () = print (msg ^ "\n")
|
||||
in
|
||||
{ mode = mode
|
||||
, squares = squares
|
||||
|
||||
@@ -150,7 +150,7 @@ struct
|
||||
val ypos = Vector.sub (yClickPoints, vIdx)
|
||||
|
||||
val model = AppWith.addSquare
|
||||
(model, realToInt xpos, realToInt ypos, hIdx, vIdx)
|
||||
(model, hIdx, vIdx, hIdx, vIdx)
|
||||
val squares = #squares model
|
||||
|
||||
val dotVec = getDotVecFromIndices (model, hIdx, vIdx)
|
||||
|
||||
@@ -226,14 +226,9 @@ struct
|
||||
end
|
||||
|
||||
fun insertItemIntoTree (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
|
||||
if #data item <> 0 then
|
||||
BinTree.insert (item, acc)
|
||||
else acc
|
||||
|
||||
fun toList qtree =
|
||||
let val tree = foldWithDuplicates (insertItemIntoTree, qtree, BinTree.empty)
|
||||
@@ -255,7 +250,9 @@ struct
|
||||
val startY = Ndc.fromPixelY (y, windowWidth, windowHeight)
|
||||
val endY = Ndc.fromPixelY (ey, windowWidth, windowHeight)
|
||||
|
||||
val acc = Ndc.ltrbToVertex (startX, startY, endX, endY) :: acc
|
||||
val vec =
|
||||
Ndc.ltrbToVertexRgb (startX, startY, endX, endY, 0.0, 0.0, 0.0)
|
||||
val acc = vec :: acc
|
||||
in
|
||||
loop (windowWidth, windowHeight, tl, acc)
|
||||
end
|
||||
@@ -265,6 +262,8 @@ struct
|
||||
let
|
||||
val qtree = build (0, 0, size, squares)
|
||||
val squares = toList qtree
|
||||
val msg = List.length squares
|
||||
val () = print (Int.toString msg ^ "\n")
|
||||
in
|
||||
loop (windowWidth, windowHeight, squares, [])
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user