Box improvements
Transforms that map boxes to boxes e.g. for Box2. Need to find a name and location though.
let map_box ~src ~dst =
M3.mul (M3.move2 (Box2.o dst)) @@
M3.mul (M3.scale2 (V2.div (Box2.size dst) (Box2.size src))) @@
M3.move2 (V2.neg (Box2.o src))
Also functions that extend boxes by their side (better names to be found):
let rebox_minx minx r = Box2.of_pts (V2.v minx (Box2.miny r)) (Box2.max r)
let rebox_maxx maxx r = Box2.of_pts (Box2.min r) (V2.v maxx (Box2.maxy r))
let rebox_miny miny r = Box2.of_pts (V2.v (Box2.minx r) miny) (Box2.max r)
let rebox_maxy maxy r = Box2.of_pts (Box2.min r) (V2.v (Box2.maxx r) maxy)
Also review the Invalid_arg on empty boxes. It's unclear whether it was a good to have a distinguished element. Try to make the operations total (and/or allow them to specify what happens on empty)
Also review the
Invalid_argon empty boxes. It's unclear whether it was a good to have a distinguished element. Try to make the operations total (and/or allow them to specify what happens onempty)
Three years later and after turning the problem all ways round, it's not exactly clear it is such a bad idea to have the distinguished empty box nor making the function total.
However going back to a code base where this turned out to be footgunish, it seems that every problematic occurence was because of Box.inset yielding empty boxes when the inset becomes too large.
A better semantics seems to be to degenerate to the coordinate of the mid point of the box in this case. Returning the empty box loses all spatial information which is usually not what you want (an analogy is to not zero the color components of a color when the alpha hits 0).
Commit 9300572306ddbae45df235130 implements that new semantics.