Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Interval Interval::operator- (const Interval& inter) {
- assert (
- !contains(inter) || // второй интервал не входит в первый, или
- (
- (
- abs(_left - inter._left) < EPSILON && // они совпадают хотя бы одной из границ,
- (
- !contains(_left) || // которая не входит в первый интервал
- inter.contains(_left) // или входит во второй
- )
- ) ||
- (
- abs(_right - inter._right) < EPSILON && // они совпадают хотя бы одной из границ,
- (
- !contains(_right) || // которая не входит в первый интервал
- inter.contains(_right) // или входит во второй
- )
- )
- )
- )
- Interval intersection = intersects(inter);
- if (!intersection) {
- return *this;
- } else {
- if (
- abs(_left - intersection._left) < EPSILON &&
- _includes_left == intersection._includes_left
- ) {
- if (
- abs(_right - intersection._right) < EPSILON &&
- _includes_right == intersection._includes_right
- ) {
- return {0, 0, 0, 0}
- } else {
- return {
- intersection._right,
- _right,
- !intersection._includes_right,
- _includes_right
- }
- }
- } else {
- return {
- _left,
- intersection._left,
- _includes_left,
- !intersection._includes_left
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement