progress fixing bugs in generated export string

This commit is contained in:
2025-07-13 01:40:57 +01:00
parent 31bc8485f3
commit 0e141174b2
5 changed files with 133 additions and 58 deletions

BIN
dotscape

Binary file not shown.

View File

@@ -25,16 +25,14 @@ struct
fun fromPixelX (xpos, windowWidth, windowHeight) =
let
val halfWidth = Real32.fromInt windowWidth / 2.0
val xpos = xpos - halfWidth
in
xpos / halfWidth
(xpos - halfWidth) / halfWidth
end
fun fromPixelY (ypos, windowWidth, windowHeight) =
let
val halfHeight = Real32.fromInt windowHeight / 2.0
val ypos = ~(ypos - halfHeight)
in
ypos / halfHeight
~((ypos - halfHeight) / halfHeight)
end
end

View File

@@ -500,67 +500,55 @@ struct
fun intToRealString num =
let
val result = Real32.fromInt num
val result = Real32.toString result
val result = Real.fromInt num
val result = Real.toString result
in
if String.isSubstring "." result then result else result ^ ".0"
end
fun colToRealString col =
let
val result = Real32.fromInt col / 255.0
val result = Real32.toString result
val result = Real.fromInt col / 255.0
val result = Real.toString result
in
if String.isSubstring "." result then result else result ^ ".0"
end
fun makeXString x =
let val x = intToRealString x
in "xToNdc (xOffset, " ^ x ^ ", scale, halfWidth)"
end
fun makeEndXString (startX, endX) =
let val endX = intToRealString endX
in "endXToNdc (xOffset, " ^ startX ^ ", " ^ endX ^ ", scale, halfWidth)"
end
fun makeYString y =
let val y = intToRealString y
in "yToNdc (yOffset, " ^ y ^ ", scale, halfHeight)"
end
fun makeEndYString (startY, endY) =
let val endY = intToRealString endY
in "endYToNdc (yOffset, " ^ startY ^ ", " ^ endY ^ ", scale, halfHeight)"
end
fun toExportStringFolder ({x, ex, y, ey, data = {r, g, b, a}}, acc) =
let
val x = intToRealString x
val y = intToRealString y
val ex = intToRealString ex
val ey = intToRealString ey
val x = makeXString x
val y = makeYString y
val ex = makeEndXString (x, ex)
val ey = makeYString ey
val r = colToRealString r
val g = colToRealString g
val b = colToRealString b
val x = String.concat ["(((x + ", x, ") - halfWidth) / halfWidth)"]
val y = String.concat ["((~(y + ", y, ") - halfHeight) / halfHeight)"]
val ex = String.concat
[ "((((("
, "("
, ex
, "+ x)"
, " - "
, x
, ") "
, "* scale) + "
, x
, ") - halfWidth) / halfWidth)"
]
val ey = String.concat
[ "("
, "("
, "("
, "("
, "("
, "("
, ey
, "+ y)"
, " - "
, y
, ")"
, "* scale) + "
, y
, ") - halfHeight) / halfHeight)"
]
in
(* based on triangle order formed by `Ndc.ltrbToVertexRgb` function *)
x :: ey :: r :: g :: b :: ex :: ey :: r :: g :: b :: x :: y :: r :: g :: b
:: x :: y :: r :: g :: b :: ex :: ey :: r :: g :: b :: ex :: y :: r :: g
:: b :: acc
val item = String.concatWith ",\n"
[x, ey, ex, ey, x, y, x, y, ex, ey, ex, y]
in
item :: acc
end
fun toExportString (squares, canvasWidth, canvasHeight) =
@@ -571,19 +559,35 @@ struct
val coords = BinTree.foldr (toExportStringFolder, bintree, [])
val coords = String.concatWith ",\n" coords
val header = String.concat
in
String.concat
[ "structure AAA = \nstruct\n"
, " fun lerp (x, y, scale, windowWidth, windowHeight) =\n"
, " fun xToNdc (xOffset, xpos, scale, halfWidth) =\n"
, " ((xpos * scale + xOffset) - halfWidth) / halfWidth\n\n"
, " fun endXToNdc (xOffset, startX, endX, scale, halfWidth) =\n"
, " (((endX - startX) * scale + xOffset) - halfWidth) / halfWidth\n\n"
, " fun yToNdc (yOffset, ypos, scale, halfHeight) =\n"
, " ~(((ypos * scale + yOffset) - halfHeight) / halfHeight)\n\n"
, " fun endYToNdc (yOffset, startY, endY, scale, halfHeight) =\n"
, " ~((((endY - startY) * scale + yOffset) - halfHeight) / halfHeight)\n\n"
, " fun lerp (xOffset, yOffset, scale, windowWidth, windowHeight) =\n"
, " let\n"
, " val halfWidth = Real32.fromInt windowWidth / 2.0\n"
, " val halfHeight = Real32.fromInt windowHeight / 2.0\n"
, " val windowWidth = Real32.fromInt windowWidth\n"
, " val halfWidth = windowWidth / 2.0\n"
, " val windowHeight = Real32.fromInt windowHeight\n"
, " val halfHeight = windowHeight / 2.0\n"
, " in\n"
, " #[\n"
, coords
, "\n"
, " ]\n"
, " end\n"
, "end\n"
]
val footer = String.concat ["\n ]\n", " end\n", "end\n"]
in
String.concat [header, coords, footer]
end
end

View File

@@ -1 +1 @@
4 4 { {0 0 1 0 0 0 0 1 } {1 0 1 1 0 0 0 1 } {2 1 2 4 0 0 0 1 } {2 3 3 4 0 0 0 1 } }
50 50 { {0 0 4 4 0 0 0 1 } {0 45 4 50 0 0 0 1 } {45 0 49 4 0 0 0 1 } {45 45 49 50 0 0 0 1 } }

73
green.sml Normal file
View File

@@ -0,0 +1,73 @@
structure AAA =
struct
fun xToNdc (xOffset, xpos, scale, halfWidth) =
((xpos * scale + xOffset) - halfWidth) / halfWidth
fun endXToNdc (xOffset, startX, endX, scale, halfWidth) =
(((endX - startX) * scale + xOffset) - halfWidth) / halfWidth
fun yToNdc (yOffset, ypos, scale, halfHeight) =
~(((ypos * scale + yOffset) - halfHeight) / halfHeight)
fun endYToNdc (yOffset, startY, endY, scale, halfHeight) =
~((((endY - startY) * scale + yOffset) - halfHeight) / halfHeight)
fun lerp (xOffset, yOffset, scale, windowWidth, windowHeight) =
let
val windowWidth = Real32.fromInt windowWidth
val windowHeight = Real32.fromInt windowHeight
val halfWidth = windowWidth / 2.0
val halfHeight = windowHeight / 2.0
in
#[
xToNdc (xOffset, 0.0, scale, halfWidth),
yToNdc (yOffset, 4.0, scale, halfHeight),
endXToNdc (xOffset, xToNdc (xOffset, 0.0, scale, halfWidth), 4.0, scale, halfWidth),
yToNdc (yOffset, 4.0, scale, halfHeight),
xToNdc (xOffset, 0.0, scale, halfWidth),
yToNdc (yOffset, 0.0, scale, halfHeight),
xToNdc (xOffset, 0.0, scale, halfWidth),
yToNdc (yOffset, 0.0, scale, halfHeight),
endXToNdc (xOffset, xToNdc (xOffset, 0.0, scale, halfWidth), 4.0, scale, halfWidth),
yToNdc (yOffset, 4.0, scale, halfHeight),
endXToNdc (xOffset, xToNdc (xOffset, 0.0, scale, halfWidth), 4.0, scale, halfWidth),
yToNdc (yOffset, 0.0, scale, halfHeight),
xToNdc (xOffset, 0.0, scale, halfWidth),
yToNdc (yOffset, 50.0, scale, halfHeight),
endXToNdc (xOffset, xToNdc (xOffset, 0.0, scale, halfWidth), 4.0, scale, halfWidth),
yToNdc (yOffset, 50.0, scale, halfHeight),
xToNdc (xOffset, 0.0, scale, halfWidth),
yToNdc (yOffset, 45.0, scale, halfHeight),
xToNdc (xOffset, 0.0, scale, halfWidth),
yToNdc (yOffset, 45.0, scale, halfHeight),
endXToNdc (xOffset, xToNdc (xOffset, 0.0, scale, halfWidth), 4.0, scale, halfWidth),
yToNdc (yOffset, 50.0, scale, halfHeight),
endXToNdc (xOffset, xToNdc (xOffset, 0.0, scale, halfWidth), 4.0, scale, halfWidth),
yToNdc (yOffset, 45.0, scale, halfHeight),
xToNdc (xOffset, 45.0, scale, halfWidth),
yToNdc (yOffset, 4.0, scale, halfHeight),
endXToNdc (xOffset, xToNdc (xOffset, 45.0, scale, halfWidth), 49.0, scale, halfWidth),
yToNdc (yOffset, 4.0, scale, halfHeight),
xToNdc (xOffset, 45.0, scale, halfWidth),
yToNdc (yOffset, 0.0, scale, halfHeight),
xToNdc (xOffset, 45.0, scale, halfWidth),
yToNdc (yOffset, 0.0, scale, halfHeight),
endXToNdc (xOffset, xToNdc (xOffset, 45.0, scale, halfWidth), 49.0, scale, halfWidth),
yToNdc (yOffset, 4.0, scale, halfHeight),
endXToNdc (xOffset, xToNdc (xOffset, 45.0, scale, halfWidth), 49.0, scale, halfWidth),
yToNdc (yOffset, 0.0, scale, halfHeight),
xToNdc (xOffset, 45.0, scale, halfWidth),
yToNdc (yOffset, 50.0, scale, halfHeight),
endXToNdc (xOffset, xToNdc (xOffset, 45.0, scale, halfWidth), 49.0, scale, halfWidth),
yToNdc (yOffset, 50.0, scale, halfHeight),
xToNdc (xOffset, 45.0, scale, halfWidth),
yToNdc (yOffset, 45.0, scale, halfHeight),
xToNdc (xOffset, 45.0, scale, halfWidth),
yToNdc (yOffset, 45.0, scale, halfHeight),
endXToNdc (xOffset, xToNdc (xOffset, 45.0, scale, halfWidth), 49.0, scale, halfWidth),
yToNdc (yOffset, 50.0, scale, halfHeight),
endXToNdc (xOffset, xToNdc (xOffset, 45.0, scale, halfWidth), 49.0, scale, halfWidth),
yToNdc (yOffset, 45.0, scale, halfHeight)
]
end
end