allow loading of files with or without rgb colour data

This commit is contained in:
2024-12-29 20:22:11 +00:00
parent 43eb5f4448
commit 7c2cc66b5a
2 changed files with 42 additions and 1 deletions

BIN
dotscape

Binary file not shown.

View File

@@ -5,7 +5,7 @@ end
structure ParseFile :> PARSE_FILE =
struct
datatype triangle_token = X | Y | COORD of Real32.real | UNKNOWN of string
datatype triangle_token = X | Y | R | G | B | COORD of Real32.real | UNKNOWN of string
val zero: Real32.real = 0.0
@@ -26,6 +26,7 @@ struct
, Y
, COORD y3
] =>
(* file format not specifying any colours *)
SOME
{ x1 = x1
, y1 = y1
@@ -37,6 +38,40 @@ struct
, g = zero
, b = zero
}
| [ X
, COORD x1
, Y
, COORD y1
, X
, COORD x2
, Y
, COORD y2
, X
, COORD x3
, Y
, COORD y3
, R
, COORD r
, G
, COORD g
, B
, COORD b
] =>
(* file format specifying rgb *)
SOME
{ x1 = x1
, y1 = y1
, x2 = x2
, y2 = y2
, x3 = x3
, y3 = y3
, r = r
, g = g
, b = b
}
| _ => NONE
fun tokeniseString str =
@@ -44,6 +79,12 @@ struct
X
else if str = "y" then
Y
else if str = "r" then
R
else if str = "g" then
G
else if str = "B" then
B
else
case Real32.fromString str of
SOME num => COORD num