If you have a lot of this code, you can consider a way to help:
bool distanceLE (Point p1, Point p2, double threshold) { return (p1.distanceFrom (p2) <= threshold) } bool Circle2::contains (Line2 l) { return distanceLE (p1, l.p1, r) && distanceLE (p1, l.p2, r); }
If you sometimes have <, sometimes <=,>,> =, etc., perhaps you should pass the operator also as a function.
In some cases, your intentions are by writing this:
if ((a || b) == 0) return 1; return 0;
can be expressed bitwise or:
if ((a | b) == 0) return 1; return 0;
and simplified to
return ! (a | b);
But read the bitwise operations and carefully check it. I use them rarely, and especially I have not used C ++ for some time.
Note that you flipped the value between examples 1 and 2, returning true and false in reverse order.
And bitwise less equal does not make any sense, of course. :)
source share