1 // Copyright 2016 The SwiftShader Authors. All Rights Reserved. 2 // 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 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 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. 14 15 #include "Point.hpp" 16 17 #include "Matrix.hpp" 18 19 namespace sw 20 { operator +=(const Vector & v)21 Point &Point::operator+=(const Vector &v) 22 { 23 x += v.x; 24 y += v.y; 25 z += v.z; 26 27 return *this; 28 } 29 operator -=(const Vector & v)30 Point &Point::operator-=(const Vector &v) 31 { 32 x -= v.x; 33 y -= v.y; 34 z -= v.z; 35 36 return *this; 37 } 38 operator +(const Point & P,const Vector & v)39 Point operator+(const Point &P, const Vector &v) 40 { 41 return Point(P.x + v.x, P.y + v.y, P.z + v.z); 42 } 43 operator -(const Point & P,const Vector & v)44 Point operator-(const Point &P, const Vector &v) 45 { 46 return Point(P.x - v.x, P.y - v.y, P.z - v.z); 47 } 48 operator -(const Point & P,const Point & Q)49 Vector operator-(const Point &P, const Point &Q) 50 { 51 return Vector(P.x - Q.x, P.y - Q.y, P.z - Q.z); 52 } 53 operator *(const Matrix & M,const Point & P)54 Point operator*(const Matrix &M, const Point &P) 55 { 56 return Point(M(1, 1) * P.x + M(1, 2) * P.y + M(1, 3) * P.z + M(1, 4), 57 M(2, 1) * P.x + M(2, 2) * P.y + M(2, 3) * P.z + M(2, 4), 58 M(3, 1) * P.x + M(3, 2) * P.y + M(3, 3) * P.z + M(3, 4)); 59 } 60 operator *(const Point & P,const Matrix & M)61 Point operator*(const Point &P, const Matrix &M) 62 { 63 return Point(P.x * M(1, 1) + P.y * M(2, 1) + P.z * M(3, 1), 64 P.x * M(1, 2) + P.y * M(2, 2) + P.z * M(3, 2), 65 P.x * M(1, 3) + P.y * M(2, 3) + P.z * M(3, 3)); 66 } 67 operator *=(Point & P,const Matrix & M)68 Point &operator*=(Point &P, const Matrix &M) 69 { 70 return P = P * M; 71 } 72 d(const Point & P) const73 float Point::d(const Point &P) const 74 { 75 return Vector::N(*this - P); 76 } 77 d2(const Point & P) const78 float Point::d2(const Point &P) const 79 { 80 return Vector::N2(*this - P); 81 } 82 d(const Point & P,const Point & Q)83 float Point::d(const Point &P, const Point &Q) 84 { 85 return Vector::N(P - Q); 86 } 87 d2(const Point & P,const Point & Q)88 float Point::d2(const Point &P, const Point &Q) 89 { 90 return Vector::N2(P - Q); 91 } 92 } 93