# Kstars

vect.h
1/*
3
4 Modified by Jasem Mutlaq <mutlaqja@ikarustech.com> for KStars:
5 SPDX-FileCopyrightText: 2012 Jasem Mutlaq <mutlaqja@ikarustech.com>
6
8*/
9
10#pragma once
11
12#include <cmath>
13
14namespace GuiderUtils
15{
16class Vector
17{
18 public:
19 double x, y, z;
20 Vector()
21 {
22 x = y = z = 0.0;
23 };
24 explicit Vector(double v)
25 {
26 x = y = z = v;
27 };
28 Vector(const Vector &v)
29 {
30 x = v.x;
31 y = v.y;
32 z = v.z;
33 };
34 Vector(double vx, double vy, double vz)
35 {
36 x = vx;
37 y = vy;
38 z = vz;
39 };
40 ~Vector() = default;
41
42 Vector &operator=(const Vector &v)
43 {
44 x = v.x;
45 y = v.y;
46 z = v.z;
47 return *this;
48 };
49 Vector &operator=(double f)
50 {
51 x = y = z = f;
52 return *this;
53 };
54 Vector operator-() const;
55 Vector &operator+=(const Vector &);
56 Vector &operator-=(const Vector &);
57 Vector &operator*=(const Vector &);
58 Vector &operator*=(double);
59 Vector &operator/=(double);
60
61 friend Vector operator+(const Vector &, const Vector &);
62 friend Vector operator-(const Vector &, const Vector &);
63 friend Vector operator*(const Vector &, const Vector &);
64 friend Vector operator*(double, const Vector &);
65 friend Vector operator*(const Vector &, double);
66 friend Vector operator/(const Vector &, double);
67 friend Vector operator/(const Vector &, const Vector &);
68 friend double operator&(const Vector &u, const Vector &v)
69 {
70 return u.x * v.x + u.y * v.y + u.z * v.z;
71 };
72 friend Vector operator^(const Vector &, const Vector &);
73 double operator!() const
74 {
75 return (double)sqrt(x * x + y * y + z * z);
76 };
77 double &operator[](int n)
78 {
79 return *(&x + n);
80 };
81 int operator<(double v)
82 {
83 return x < v && y < v && z < v;
84 };
85 int operator>(double v)
86 {
87 return x > v && y > v && z > v;
88 };
89};
90
91inline Vector Vector ::operator-() const
92{
93 return Vector(-x, -y, -z);
94}
95
96inline Vector operator+(const Vector &u, const Vector &v)
97{
98 return Vector(u.x + v.x, u.y + v.y, u.z + v.z);
99}
100
101inline Vector operator-(const Vector &u, const Vector &v)
102{
103 return Vector(u.x - v.x, u.y - v.y, u.z - v.z);
104}
105
106inline Vector operator*(const Vector &u, const Vector &v)
107{
108 return Vector(u.x * v.x, u.y * v.y, u.z * v.z);
109}
110
111inline Vector operator*(const Vector &u, double f)
112{
113 return Vector(u.x * f, u.y * f, u.z * f);
114}
115
116inline Vector operator*(double f, const Vector &v)
117{
118 return Vector(f * v.x, f * v.y, f * v.z);
119}
120
121inline Vector operator/(const Vector &v, double f)
122{
123 return Vector(v.x / f, v.y / f, v.z / f);
124}
125
126inline Vector operator/(const Vector &u, const Vector &v)
127{
128 return Vector(u.x / v.x, u.y / v.y, u.z / v.z);
129}
130
131inline Vector &Vector ::operator+=(const Vector &v)
132{
133 x += v.x;
134 y += v.y;
135 z += v.z;
136 return *this;
137}
138
139inline Vector &Vector ::operator-=(const Vector &v)
140{
141 x -= v.x;
142 y -= v.y;
143 z -= v.z;
144 return *this;
145}
146
147inline Vector &Vector ::operator*=(double v)
148{
149 x *= v;
150 y *= v;
151 z *= v;
152 return *this;
153}
154
155inline Vector &Vector ::operator*=(const Vector &v)
156{
157 x *= v.x;
158 y *= v.y;
159 z *= v.z;
160 return *this;
161}
162
163inline Vector &Vector ::operator/=(double v)
164{
165 x /= v;
166 y /= v;
167 z /= v;
168 return *this;
169}
170
171inline Vector Normalize(const Vector &v)
172{
173 return v / !v;
174};
175Vector RndVector();
176Vector &Clip(Vector &);
177
178} // namespace GuiderUtils
QCA_EXPORT const SecureArray operator+(const SecureArray &a, const SecureArray &b)
This file is part of the KDE documentation.