Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Creating a second rectangle

Like the outer frame, the inner frame is a std::geo2d::Rect too:

test

thickness = 1.2mm;
std::geo2d::Rect(width = 31.8mm - 2 * thickness, height = 15.8mm - 2 * thickness);

Picture

We have defined a new value thickness = 1.2mm to store the frame's wall thickness. Then, we construct a rectangle by taking the original width and height and subtracting twice the thickness from both.

We can now output the inner and outer geometry simultaneously. Similar to the thickness = 1.2mm, we also assign width and height their respective values to shorten the code:

test

thickness = 1.2mm;
width = 31.8mm;
height = 15.8mm;
std::geo2d::Rect(width, height);
std::geo2d::Rect(width = width - 2 * thickness, height = height - 2 * thickness);

Picture

Because the arguments we give to the first std::geo2d::Rect() match exactly the parameter names of it we do not need to write extra parameter names here. This is called auto-matching. It prevents us from having to write the argument names twice:

std::geo2d::Rect(width = width, height = height);

Now, we can execute the export command from the command line tool:

microcad export lego_brick.µcad

The export command will produce a Scalable Vector Graphic (SVG) file named lego_brick.svg next to the lego_brick.µcad file. By default, all 2D geometries are exported to SVG.

Congratulations, you have exported your first 2D geometry with µcad!

Although the measurements of these rectangles are correct, our intention was to create a frame in which the both rectangles define the boundary of the frame. To achieve this, we will use an operation to combine them.