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 } |