comparison Framework/Toolbox/Extent.cpp @ 109:53bd9277b025 wasm

using the Extent class
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 14 Jun 2017 15:34:08 +0200
parents efd9ef2b67f1
children
comparison
equal deleted inserted replaced
108:37d4ae7052a5 109:53bd9277b025
24 #include <algorithm> 24 #include <algorithm>
25 #include <cassert> 25 #include <cassert>
26 26
27 namespace OrthancStone 27 namespace OrthancStone
28 { 28 {
29 Extent::Extent(double x1,
30 double y1,
31 double x2,
32 double y2) :
33 empty_(false),
34 x1_(x1),
35 y1_(y1),
36 x2_(x2),
37 y2_(y2)
38 {
39 if (x1_ > x2_)
40 {
41 std::swap(x1_, x2_);
42 }
43
44 if (y1_ > y2_)
45 {
46 std::swap(y1_, y2_);
47 }
48 }
49
50
29 void Extent::Reset() 51 void Extent::Reset()
30 { 52 {
31 empty_ = true; 53 empty_ = true;
32 x1_ = 0; 54 x1_ = 0;
33 y1_ = 0; 55 y1_ = 0;
59 } 81 }
60 82
61 83
62 void Extent::Union(const Extent& other) 84 void Extent::Union(const Extent& other)
63 { 85 {
64 if (other.IsEmpty()) 86 if (other.empty_)
65 { 87 {
66 return; 88 return;
67 } 89 }
68 90
69 if (IsEmpty()) 91 if (empty_)
70 { 92 {
71 *this = other; 93 *this = other;
72 return; 94 return;
73 } 95 }
74 96
75 assert(!IsEmpty()); 97 assert(!empty_);
76 98
77 x1_ = std::min(x1_, other.x1_); 99 x1_ = std::min(x1_, other.x1_);
78 y1_ = std::min(y1_, other.y1_); 100 y1_ = std::min(y1_, other.y1_);
79 x2_ = std::max(x2_, other.x2_); 101 x2_ = std::max(x2_, other.x2_);
80 y2_ = std::max(y2_, other.y2_); 102 y2_ = std::max(y2_, other.y2_);
81 103
82 assert(x1_ <= x2_ && 104 assert(x1_ <= x2_ &&
83 y1_ <= y2_); // This is the invariant of the structure 105 y1_ <= y2_); // This is the invariant of the structure
84 } 106 }
85 107
108
109 bool Extent::IsEmpty() const
110 {
111 if (empty_)
112 {
113 return true;
114 }
115 else
116 {
117 assert(x1_ <= x2_ &&
118 y1_ <= y2_);
119 return (x2_ <= x1_ + 10 * std::numeric_limits<double>::epsilon() ||
120 y2_ <= y1_ + 10 * std::numeric_limits<double>::epsilon());
121 }
122 }
86 } 123 }