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