Skip to content

Working on making my 2D library robust

Posted on:March 23, 2023

Checks!

I have now started to include the assumptions on the data structures as part of their constructor. Typically any kind of stroke should never be self intersecting. Or holes in a figure should be within its contour. It feels obvious is some way, but the different libraries tend to document that this should be the case and not really test it.

I guess that there are some performance costs, but I offer the possibility to disable this at creation. Sometimes you know can assume that your shape is valid, so you can skip it. But the default should be with enforcing it.

I plan to have a more generous higher level drawing API. For instance, it should automatically split strokes that intersect each other. The low level enforces the assumptions about the data model, and the higher level does its best to translate potentially bad input into something that we can work with. I like that it exemplify the robustness principle

This means that I have decided to add a Diagram class that correspond to an array of non intersecting figures.

Tests and bugs

A cut test

I am going through importing all the replicad code into my well defined 2D library. And I plan to have it well tested as well defined. I really don’t like writing tests, but I know I will like have them written.

The bad news is that I find bugs. It is also good news. But it means that the whole awful task is useful in some way.

Especially, I have found that my original algorithm makes an assumption about how split strands behave that is simply wrong. I will need to handle the broken cases at some point - but I want to move forward and ship a first version that have the basics there and then fix this bug.