olp-cpp-sdk  1.22.0
Size.h
1 /*
2  * Copyright (C) 2019 HERE Europe B.V.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  * SPDX-License-Identifier: Apache-2.0
17  * License-Filename: LICENSE
18  */
19 
20 #pragma once
21 
22 #include <olp/core/math/Vector.h>
23 
24 namespace olp {
25 namespace math {
27 template <typename T>
28 class Size2 {
29  public:
31  using Value = T;
32 
34  Size2();
35 
41  template <typename U>
42  Size2(const Size2<U>& size);
43 
49  template <typename U>
50  explicit Size2(const Vector2<U>& vector);
51 
58  Size2(Value width, Value height);
59 
65  template <typename U>
66  explicit operator Vector2<U>() const;
67 
74  bool empty() const;
75 
81  Value Width() const;
82 
88  Value Height() const;
89 
90  private:
91  Vector2<Value> size_;
92 };
93 
94 using Size2u = Size2<unsigned>;
95 
96 template <typename T>
97 Size2<T>::Size2() : size_(0, 0) {}
98 
99 template <typename T>
100 template <typename U>
101 Size2<T>::Size2(const Size2<U>& size) : size_(size.width(), size.height()) {}
102 
103 template <typename T>
104 template <typename U>
105 Size2<T>::Size2(const Vector2<U>& vector) : size_(vector) {}
106 
107 template <typename T>
108 Size2<T>::Size2(Value width, Value height) : size_(width, height) {}
109 
110 template <typename T>
111 template <typename U>
113  return Vector2<U>(size_.x, size_.y);
114 }
115 
116 template <typename T>
117 bool Size2<T>::empty() const {
118  return size_.x == T() || size_.y == T();
119 }
120 
121 template <typename T>
122 auto Size2<T>::Width() const -> Value {
123  return size_.x;
124 }
125 
126 template <typename T>
127 auto Size2<T>::Height() const -> Value {
128  return size_.y;
129 }
130 
131 template <typename T>
132 bool operator==(const Size2<T>& lhs, const Size2<T>& rhs) {
133  return lhs.width() == rhs.width() && lhs.height() == rhs.height();
134 }
135 
136 template <typename T>
137 bool operator!=(const Size2<T>& lhs, const Size2<T>& rhs) {
138  return !(lhs == rhs);
139 }
140 
141 } // namespace math
142 } // namespace olp
Represents the 2D size.
Definition: Size.h:28
T Value
An alias for the value type.
Definition: Size.h:31
Value Width() const
Gets the width of the Size2 object.
Definition: Size.h:122
Value Height() const
Gets the height of the Size2 object.
Definition: Size.h:127
bool empty() const
Checks whether the size is empty.
Definition: Size.h:117
Size2()
Creates an uninitialized Size2 instance.
Definition: Size.h:97
Rules all the other namespaces.
Definition: AppleSignInProperties.h:24
Represents 2D vectors and points.
Definition: Vector.h:27