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

Subtract

Until now, we have two rectangles which are generated within the same file but to build a frame, we have to combine them.

Grouping statements

The first step is to bundle the rectangles into a group with curly brackets {}. So let's put some around the frame's rectangles.

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

As you can see, there is no ; after the braces.

The visual output did not change by using the group braces. However, now we can combine both rectangles by using an operation.

Manipulate geometry with Operations

In µcad, the operation to subtract a geometry from one another is called subtract. In our case, we want to subtract the outer part by the inner part in our frame group:

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);
}.std::ops::subtract();   // Apply the operation.

Picture

Now the semicolon is back, because we added the operation.