Cheat Sheet For Converting to 2geom

If you are just starting I suggest you pick a header file and convert just one function at a time. That will give you a feel for the process as you get more comfortable do more at one time.

Lets talk about emptiness.

In Inkscape and in 2geom there are two types of emptiness for rectangles.

Rectangles with no coordinates.
Rectangles with zero area.

What is the difference?

A Rect that has the coordinates of (1,2) - (2,6) contains points and has a non-zero area.
A Rect that has the coordinates of (0,0) - (0,0) contains one point but has zero area.
A Rect that has the coordinates of (0,0) - (10,0) contains points but has zero area.
A Geom::OptRect that has not been defined with coordinates has neither points or area.

If you need to define a rectangle, but are not sure whether it is always a valid rectangle, please use Geom::OptRect. It means "Optional Rect". A bounding box of a path could be an "invalid" rectangle for example, when the path has no fill or stroke.

optrect.isEmpty() checks if optrect contains a valid rectangle NOT if the rect has zero area. rect.hasZeroArea() does that.

Items That you Can Switch NR:: for Geom::

NR::Matrix

NR::Rect

NR::Dim2

NR::L2

NR::Y

NR::X

NR::identity

NR::Coord

Things that need small adjustments or complete replacement

Error looks like

NR Function or Code

2geom Replacement

NR::scale

Geom::Scale (note the capital letter S)

NR::translate

Geom::Translate (capital)

nrrect.extent(NR::X)

geomrect.dimensions()[Geom::X]OR

geomRect[X].extent()

height = r->extent(NR::Y);

height = r->dimensions()[Geom::Y];

NR::expansion(nrmatrix)

geommatrix.descrim()

desktop.cpp:754: error: 'expand' is not a member of 'Geom'

NR::Rect const viewbox = NR::expand(canvas->getViewbox(), border);

Geom::Rect viewbox = canvas->getViewbox();

viewbox.expandBy(border);

desktop.cpp:162: error: 'class Geom::Matrix' has no member named 'set_identity'

sorry for the very brief text here. feel free to improve it and add things. ask in the jabber channel if you have difficulties.

Most of the conversions of NR::Rect and NRRect to 2Geom needs careful thought.

2Geom makes a very important distinction between rectangles and optional rectangles. Libnr is most vague about this, so you often have to find out how a certain rectangle is used: whether it always contains valid data, or whether it can contain wrong data. For example, an NRRect that is defined as (a,b)-(a,b) often means it is an "invalid" rectangle, i.e. the data is invalid and the rectangle coordinates should not be trusted. In this case NRRect::upgrade() returns an empty boost::optional<NR::Rect>. So probably, an NRRect should be replaced with Geom::OptRect. A what? OptRect. Optional Rectangle. This means 2geom knows the data in it can not always be trusted. So when one unifies an OptRect with another OptRect, 2geom checks first whether the coordinates in both can be trusted. An Geom::Rect is always considered as a valid rectangle: