comparison OrthancStone/Sources/Toolbox/UnionOfRectangles.cpp @ 1906:925aaf49150c

minor fix in UnionOfRectangles
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 31 Jan 2022 22:32:31 +0100
parents e318b524ad3f
children 07964689cb0b
comparison
equal deleted inserted replaced
1905:e318b524ad3f 1906:925aaf49150c
209 size_t x, 209 size_t x,
210 bool isLeft) 210 bool isLeft)
211 { 211 {
212 if (stack.size() % 2 != 0) 212 if (stack.size() % 2 != 0)
213 { 213 {
214 throw std::runtime_error("internal error"); 214 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
215 } 215 }
216 216
217 typedef std::pair<size_t, size_t> Interval; 217 typedef std::pair<size_t, size_t> Interval;
218 218
219 std::list<Interval> intervals; 219 std::list<Interval> intervals;
222 { 222 {
223 size_t high = stack.top(); 223 size_t high = stack.top();
224 stack.pop(); 224 stack.pop();
225 size_t low = stack.top(); 225 size_t low = stack.top();
226 stack.pop(); 226 stack.pop();
227 227
228 if (!intervals.empty() && 228 if (!intervals.empty() &&
229 intervals.back().second == low) 229 intervals.back().second == low)
230 { 230 {
231 // Extend the previous interval 231 // Extend the previous interval
232 intervals.back().second = high; 232 intervals.back().second = high;
238 } 238 }
239 239
240 for (std::list<Interval>::const_iterator 240 for (std::list<Interval>::const_iterator
241 it = intervals.begin(); it != intervals.end(); ++it) 241 it = intervals.begin(); it != intervals.end(); ++it)
242 { 242 {
243 if (it->first == it->second) 243 if (it->first >= it->second)
244 { 244 {
245 throw std::runtime_error("parameter out of range"); 245 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
246 } 246 }
247 247
248 // By convention, the left sides go downward, and the right go upward 248 // By convention, the left sides go downward, and the right go upward
249 if (isLeft) 249 if (isLeft)
250 { 250 {
251 edges.push_back(Internals::OrientedIntegerLine2D(x, it->first, x, it->second)); 251 if (!edges.empty() &&
252 } 252 edges.back().GetX1() == x &&
253 else 253 edges.back().GetX2() == x &&
254 { 254 edges.back().GetY1() == it->second &&
255 edges.push_back(Internals::OrientedIntegerLine2D(x, it->second, x, it->first)); 255 edges.back().GetY2() == it->first)
256 {
257 // The two successive vertical segments cancel each other
258 edges.pop_back();
259 }
260 else
261 {
262 edges.push_back(Internals::OrientedIntegerLine2D(x, it->first, x, it->second));
263 }
264 }
265 else
266 {
267 if (!edges.empty() &&
268 edges.back().GetX1() == x &&
269 edges.back().GetX2() == x &&
270 edges.back().GetY1() == it->first &&
271 edges.back().GetY2() == it->second)
272 {
273 // The two successive vertical segments cancel each other
274 edges.pop_back();
275 }
276 else
277 {
278 edges.push_back(Internals::OrientedIntegerLine2D(x, it->second, x, it->first));
279 }
256 } 280 }
257 } 281 }
258 } 282 }
259 283
260 284