comparison Sources/Extent2D.cpp @ 32:976da5476810

reorganization
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 04 Apr 2024 18:35:54 +0200
parents
children
comparison
equal deleted inserted replaced
31:ab231760799d 32:976da5476810
1 /**
2 * SPDX-FileCopyrightText: 2023-2024 Sebastien Jodogne, UCLouvain, Belgium
3 * SPDX-License-Identifier: GPL-3.0-or-later
4 */
5
6 /**
7 * STL plugin for Orthanc
8 * Copyright (C) 2023-2024 Sebastien Jodogne, UCLouvain, Belgium
9 *
10 * This program is free software: you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License as
12 * published by the Free Software Foundation, either version 3 of the
13 * License, or (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 **/
23
24
25 #include "Extent2D.h"
26
27 #include <OrthancException.h>
28
29
30 void Extent2D::CheckNotEmpty() const
31 {
32 if (isEmpty_)
33 {
34 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
35 }
36 }
37
38
39 Extent2D::Extent2D() :
40 isEmpty_(true),
41 x1_(0),
42 y1_(0),
43 x2_(0),
44 y2_(0)
45 {
46 }
47
48
49 double Extent2D::GetMinX() const
50 {
51 CheckNotEmpty();
52 return x1_;
53 }
54
55
56 double Extent2D::GetMaxX() const
57 {
58 CheckNotEmpty();
59 return x2_;
60 }
61
62
63 double Extent2D::GetMinY() const
64 {
65 CheckNotEmpty();
66 return y1_;
67 }
68
69
70 double Extent2D::GetMaxY() const
71 {
72 CheckNotEmpty();
73 return y2_;
74 }
75
76
77 double Extent2D::GetWidth() const
78 {
79 CheckNotEmpty();
80 return x2_ - x1_;
81 }
82
83
84 double Extent2D::GetHeight() const
85 {
86 CheckNotEmpty();
87 return y2_ - y1_;
88 }
89
90
91 void Extent2D::Add(double x,
92 double y)
93 {
94 if (isEmpty_)
95 {
96 x1_ = x2_ = x;
97 y1_ = y2_ = y;
98 isEmpty_ = false;
99 }
100 else
101 {
102 x1_ = std::min(x1_, x);
103 x2_ = std::max(x2_, x);
104 y1_ = std::min(y1_, y);
105 y2_ = std::max(y2_, y);
106 }
107 }