cucapra / gator

Geometry types
https://capra.cs.cornell.edu/research/gator/
26 stars 11 forks source link

Fix Support for Canonical Functions #77

Open pauljoo28 opened 4 years ago

pauljoo28 commented 4 years ago

Canonical functions are currently not being supported at all. Currently in /test-u/basics.lgl the following code results in the error: Fatal error: exception Gatorl.CheckUtil.TypeException("Line: 7 -- Invalid canonical function canon b _ab(a v)").

canon b _ab(a v) {
    return (v + [1., 1.]) as! b;
}

In fact if we change the code to the following,

canon b _ab(b v) {
    return (v);
}

we still get the same error indicating the the problem is not only in the casting as!.

Checkmate50 commented 4 years ago

Ah, fortunately, this is not an error but a feature! We now require in Gator that canonical functions map between two geometric objects. To fix this code, simply change the function to act on reference frames a and b rather than the raw types a and b.

For example, we might write:

canon cart3<b>.point _ab(cart3<a>.point v) {
    return (v + [1., 1.]) as! cart3<b>.point;
}

And we get the original intended behavior!

However, I will leave this issue open, since clearly the current error message is not helpful for debugging. Also, I should update the documentation to illustrate this updated behavior.