olp-cpp-sdk 1.24.0
Loading...
Searching...
No Matches
Vector.h
1/*
2 * Copyright (C) 2019-2021 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
22namespace olp {
23namespace math {
24
25template <typename T>
27struct Vector2 {
28 Vector2() {}
36 x = a;
37 y = b;
38 }
39
46 this->x = static_cast<T>(v.x);
47 this->y = static_cast<T>(v.y);
48 return *this;
49 }
50
56 Vector2<T> operator*(T const& s) const { return Vector2<T>(x * s, y * s); }
58 Vector2<T> operator-() { return Vector2<T>(-x, -y); }
59
66 return Vector2<T>(x - v.x, y - v.y);
67 }
68
75 return Vector2<T>(x + v.x, y + v.y);
76 }
77
82};
83
84template <typename T>
86struct Vector3 {
87 Vector3() {}
95 Vector3(T a, T b, T c) {
96 x = a;
97 y = b;
98 z = c;
99 }
105 explicit Vector3(T const& s) : x(s), y(s), z(s) {}
106
112 Vector3<T> operator*(T const& s) const {
113 return Vector3<T>(x * s, y * s, z * s);
114 }
116 Vector3<T> operator-() const { return Vector3<T>(-x, -y, -z); }
117
124 return Vector3<T>(x - v.x, y - v.y, z - v.z);
125 }
126
133 return Vector3<T>(x + v.x, y + v.y, z + v.z);
134 }
135
143 return Vector3<bool>(x < v.x, y < v.y, z < v.z);
144 }
145
152};
153
154template <typename T, unsigned int N>
157
158template <typename T>
160struct VectorImpl<T, 2> {
163};
164
165template <typename T>
167struct VectorImpl<T, 3> {
170};
171
172template <typename T, unsigned int N>
173using Vector = typename VectorImpl<T, N>::type;
174
175} // namespace math
176} // namespace olp
Rules all the other namespaces.
Definition AppleSignInProperties.h:24
Represents 2D vectors and points.
Definition Vector.h:27
T x
The X component of the vector.
Definition Vector.h:79
Vector2< T > operator*(T const &s) const
Multiplies each vector component by a number.
Definition Vector.h:56
Vector2< T > & operator=(Vector2< T > const &v)
Assigns components of one vector to another vector.
Definition Vector.h:45
Vector2< T > operator-(Vector2< T > const &v) const
Subtracts one vector from another.
Definition Vector.h:65
Vector2< T > operator-()
Negates the vector.
Definition Vector.h:58
T y
The Y component of the vector.
Definition Vector.h:81
Vector2(T a, T b)
Creates a Vector2 instance with the given X and Y components.
Definition Vector.h:35
Vector2< T > operator+(Vector2< T > const &v) const
Adds corresponding components of two vectors.
Definition Vector.h:74
Represents 3D vectors and points.
Definition Vector.h:86
Vector3< T > operator*(T const &s) const
Multiplies each vector component by a number.
Definition Vector.h:112
Vector3< T > operator-() const
Negates the vector.
Definition Vector.h:116
Vector3< T > operator+(Vector3< T > const &v) const
Adds corresponding components of two vectors.
Definition Vector.h:132
Vector3(T a, T b, T c)
Creates a Vector3 instance with the given X, Y, and Z components.
Definition Vector.h:95
Vector3< bool > LessThan(Vector3< T > const &v) const
Checks whether the parameters of one vector are less than the parameters of the other vector.
Definition Vector.h:142
T z
The Z component of the vector.
Definition Vector.h:151
T y
The Y component of the vector.
Definition Vector.h:149
T x
The X component of the vector.
Definition Vector.h:147
Vector3< T > operator-(Vector3< T > const &v) const
Subtracts one vector from another.
Definition Vector.h:123
Vector3(T const &s)
Creates a Vector3 instance.
Definition Vector.h:105
The implementation structure of a vector.
Definition Vector.h:156