Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 1 | // Copyright 2016 The SwiftShader Authors. All Rights Reserved. |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2 | // |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6 | // |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 8 | // |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 14 | |
| 15 | #ifndef Point_hpp |
| 16 | #define Point_hpp |
| 17 | |
| 18 | namespace sw |
| 19 | { |
| 20 | struct Vector; |
| 21 | struct Matrix; |
| 22 | |
| 23 | struct Point |
| 24 | { |
| 25 | Point(); |
| 26 | Point(const int i); |
| 27 | Point(const Point &P); |
| 28 | Point(const Vector &v); |
| 29 | Point(float Px, float Py, float Pz); |
| 30 | |
| 31 | Point &operator=(const Point &P); |
| 32 | |
| 33 | union |
| 34 | { |
| 35 | float p[3]; |
| 36 | |
| 37 | struct |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 38 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 39 | float x; |
| 40 | float y; |
| 41 | float z; |
| 42 | }; |
| 43 | }; |
| 44 | |
| 45 | float &operator[](int i); |
| 46 | float &operator()(int i); |
| 47 | |
| 48 | const float &operator[](int i) const; |
| 49 | const float &operator()(int i) const; |
| 50 | |
| 51 | Point &operator+=(const Vector &v); |
| 52 | Point &operator-=(const Vector &v); |
| 53 | |
| 54 | friend Point operator+(const Point &P, const Vector &v); |
| 55 | friend Point operator-(const Point &P, const Vector &v); |
| 56 | |
| 57 | friend Vector operator-(const Point &P, const Point &Q); |
| 58 | |
| 59 | friend Point operator*(const Matrix &M, const Point& P); |
| 60 | friend Point operator*(const Point &P, const Matrix &M); |
| 61 | friend Point &operator*=(Point &P, const Matrix &M); |
| 62 | |
| 63 | float d(const Point &P) const; // Distance between two points |
| 64 | float d2(const Point &P) const; // Squared distance between two points |
| 65 | |
| 66 | static float d(const Point &P, const Point &Q); // Distance between two points |
| 67 | static float d2(const Point &P, const Point &Q); // Squared distance between two points |
| 68 | }; |
| 69 | } |
| 70 | |
| 71 | #include "Vector.hpp" |
| 72 | |
| 73 | namespace sw |
| 74 | { |
| 75 | inline Point::Point() |
| 76 | { |
| 77 | } |
| 78 | |
| 79 | inline Point::Point(const int i) |
| 80 | { |
| 81 | const float s = (float)i; |
| 82 | |
| 83 | x = s; |
| 84 | y = s; |
| 85 | z = s; |
| 86 | } |
| 87 | |
| 88 | inline Point::Point(const Point &P) |
| 89 | { |
| 90 | x = P.x; |
| 91 | y = P.y; |
| 92 | z = P.z; |
| 93 | } |
| 94 | |
| 95 | inline Point::Point(const Vector &v) |
| 96 | { |
| 97 | x = v.x; |
| 98 | y = v.y; |
| 99 | z = v.z; |
| 100 | } |
| 101 | |
| 102 | inline Point::Point(float P_x, float P_y, float P_z) |
| 103 | { |
| 104 | x = P_x; |
| 105 | y = P_y; |
| 106 | z = P_z; |
| 107 | } |
| 108 | |
| 109 | inline Point &Point::operator=(const Point &P) |
| 110 | { |
| 111 | x = P.x; |
| 112 | y = P.y; |
| 113 | z = P.z; |
| 114 | |
| 115 | return *this; |
| 116 | } |
| 117 | |
| 118 | inline float &Point::operator()(int i) |
| 119 | { |
| 120 | return p[i]; |
| 121 | } |
| 122 | |
| 123 | inline float &Point::operator[](int i) |
| 124 | { |
| 125 | return p[i]; |
| 126 | } |
| 127 | |
| 128 | inline const float &Point::operator()(int i) const |
| 129 | { |
| 130 | return p[i]; |
| 131 | } |
| 132 | |
| 133 | inline const float &Point::operator[](int i) const |
| 134 | { |
| 135 | return p[i]; |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | #endif // Point_hpp |