hannobraun/fornjot

It should be possible to assign an optional label to objects

hannobraun opened this issue · 1 comments

The problem

Validation errors are a fact of life, when implementing new functionality. But understanding what's causing them can be very hard, as it's not easy to identify what an object in the error message actually is. The same is probably true when working on non-trivial models.

A solution: labels

I think there is a relatively simple thing that could be done to improve this: Making it possible to assign an optional label to objects, so you can clearly associate what you see in the output with what you defined in the code.

These labels can be created and perpetuated by operations. For examples, if you have a sketch with a half-edge labeled "abc", then sweeping that sketch can create a label for the respective side face, something like "side face swept from abc". But this can be done piecemeal, as required, and doesn't need to fall into the scope of this issue.

Implementation

It might make sense to implement these labels as a separate layer, as to not further complicate the object graph and core data structures. ("Layers" are a concept that doesn't yet exist in the code base, at the time of writing, but see #2116 and #2117 for some thoughts on them.)

One possible hurdle is, that if labels are not part of the core data structures themselves, we need some way to inject them into the code that formats objects for the validation error messages. This can probably be done by creating Debug/Display implementations not for Handle itself, but for another struct that Handle can provide. Something like this: handle.display_with_label(label).

Layers now exist. I've implemented them as part of my work on #2117. It should be relatively straight-forward to implement the layer proposed in the issue description, although the problem with Debug/Display implementations remains.

I've also come to the conclusion that the concept presented here is more widely applicable than just debug output. By assigning labels to objects and amending those in operations, it should be possible to query for those labels. I'm not sure though, if those amended labels should be specific to operations ("side face swept from half-edge a"), or if that should be handled through a generic lineage (#1904), meaning a face can be derived from a half-edge, and the mechanism through which that happened (e.g. sweeping) would be incidental.