When displaying an object on the display box it can happen that a part of the displayed does not
fit in the display box, it lies outside the display box. So, in the course of displaying we are **clipping** this part.
Now, we will be interested in clipping the elements: a point, an abscissa, a text, a polygon. Clipping is in fact a special
case of the **conjunction** of two objects: the display box and the graphics elements.

Clipping looks trivial in the case of a dot, we just have to add a few comparisons checking if the coordinates are in the display box range and proceed only if that is the case:

The question is whether a point B with coordinates (mx, my) belongs to the display box or not. Let us take a display box given by coordinates of the lower left corner xmin, ymin and the right upper corner xmax, ymax. The question is whether a point B with coordinates (mx, my) belongs to the display box or not.

The answer is: If it is valid that xmin =< mx =< xmax and ymin =< my =< ymax , then the point belongs in the display box.

A simple algorithm on testing whether the given point [mx, my] is in the display box [x1, y1], [x2, y2]:

And of course if we are always clipping to a rectangular with a
diagonal (0, 0-something_x, something_y) we can do it with just 2
comparisons instead of 4, just making sure x and y passed are
considered by unsigned comparisons, (negative numbers after all
would be thought of just very large positive numbers).

if ((mx>=x1)&&(mx=<x2)&&(my>=y1)&&(my=<y2))
{
// point is in window
}
else
{
// point is out of the window
} |

Copyright (c) 1999-2019 Juraj Štugel. www.netgraphics.sk