Advertisement
Guest User

Untitled

a guest
Mar 21st, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.07 KB | None | 0 0
  1. Interval Interval::operator- (const Interval& inter) {
  2.  
  3. assert (
  4. !contains(inter) || // второй интервал не входит в первый, или
  5. (
  6. (
  7. abs(_left - inter._left) < EPSILON && // они совпадают хотя бы одной из границ,
  8. (
  9. !contains(_left) || // которая не входит в первый интервал
  10. inter.contains(_left) // или входит во второй
  11. )
  12. ) ||
  13. (
  14. abs(_right - inter._right) < EPSILON && // они совпадают хотя бы одной из границ,
  15. (
  16. !contains(_right) || // которая не входит в первый интервал
  17. inter.contains(_right) // или входит во второй
  18. )
  19. )
  20. )
  21. )
  22.  
  23. Interval intersection = intersects(inter);
  24.  
  25. if (!intersection) {
  26. return *this;
  27. } else {
  28. if (
  29. abs(_left - intersection._left) < EPSILON &&
  30. _includes_left == intersection._includes_left
  31. ) {
  32. if (
  33. abs(_right - intersection._right) < EPSILON &&
  34. _includes_right == intersection._includes_right
  35. ) {
  36. return {0, 0, 0, 0}
  37. } else {
  38. return {
  39. intersection._right,
  40. _right,
  41. !intersection._includes_right,
  42. _includes_right
  43. }
  44. }
  45. } else {
  46. return {
  47. _left,
  48. intersection._left,
  49. _includes_left,
  50. !intersection._includes_left
  51. }
  52. }
  53. }
  54.  
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement