Mercurial > hg > orthanc-stone
comparison Framework/Toolbox/Extent.cpp @ 97:d18dcc963930 wasm
separation of the renderers vs. viewport slice
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 30 May 2017 14:09:11 +0200 |
parents | |
children | efd9ef2b67f1 |
comparison
equal
deleted
inserted
replaced
96:f8bce1bebe01 | 97:d18dcc963930 |
---|---|
1 /** | |
2 * Stone of Orthanc | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
5 * Copyright (C) 2017 Osimis, Belgium | |
6 * | |
7 * This program is free software: you can redistribute it and/or | |
8 * modify it under the terms of the GNU Affero General Public License | |
9 * as published by the Free Software Foundation, either version 3 of | |
10 * the License, or (at your option) any later version. | |
11 * | |
12 * This program is distributed in the hope that it will be useful, but | |
13 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 * Affero General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU Affero General Public License | |
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 **/ | |
20 | |
21 | |
22 #include "Extent.h" | |
23 | |
24 #include <algorithm> | |
25 #include <cassert> | |
26 | |
27 namespace OrthancStone | |
28 { | |
29 void Extent::Reset() | |
30 { | |
31 empty_ = true; | |
32 x1_ = 0; | |
33 y1_ = 0; | |
34 x2_ = 0; | |
35 y2_ = 0; | |
36 } | |
37 | |
38 void Extent::AddPoint(double x, | |
39 double y) | |
40 { | |
41 if (empty_) | |
42 { | |
43 x1_ = x; | |
44 y1_ = y; | |
45 x2_ = x; | |
46 y2_ = y; | |
47 empty_ = false; | |
48 } | |
49 else | |
50 { | |
51 x1_ = std::min(x1_, x); | |
52 y1_ = std::min(y1_, y); | |
53 x2_ = std::max(x2_, x); | |
54 y2_ = std::max(y2_, y); | |
55 } | |
56 | |
57 assert(x1_ <= x2_ && | |
58 y1_ <= y2_); // This is the invariant of the structure | |
59 } | |
60 | |
61 | |
62 void Extent::Union(const Extent& other) | |
63 { | |
64 if (other.IsEmpty()) | |
65 { | |
66 return; | |
67 } | |
68 | |
69 if (IsEmpty()) | |
70 { | |
71 *this = other; | |
72 return; | |
73 } | |
74 | |
75 assert(!IsEmpty()); | |
76 | |
77 x1_ = std::min(x1_, other.x1_); | |
78 y1_ = std::min(y1_, other.y1_); | |
79 x2_ = std::min(x2_, other.x2_); | |
80 y2_ = std::min(y2_, other.y2_); | |
81 | |
82 assert(x1_ <= x2_ && | |
83 y1_ <= y2_); // This is the invariant of the structure | |
84 } | |
85 | |
86 } |