/* * vector3.cpp * Copyright (C) Andrew Tridgell 2012 * * This file is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This file is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ #pragma GCC optimize("O2") #include "AP_Math.h" #define HALF_SQRT_2 0.70710678118654757f template float Vector4::length(void) const { return norm(M0, M1, M2, M3); } // dot product template T Vector4::operator *(const Vector4 &v) const { return M0*v.M0 + M1*v.M1 + M2*v.M2 +M3*v.M3; } template Vector4 Vector4::operator *(const T num) const { return Vector4(M0*num, M1*num, M2*num,M3*num); } template Vector4 &Vector4::operator *=(const T num) { M0*=num; M1*=num; M2*=num;M3*=num; return *this; } template Vector4 &Vector4::operator /=(const T num) { M0 /= num; M1 /= num; M2 /= num;M3 /= num; return *this; } template Vector4 Vector4::operator /(const T num) const { return Vector4(M0/num, M1/num, M2/num, M3/num); } template Vector4 &Vector4::operator -=(const Vector4 &v) { M0 -= v.M0; M1 -= v.M1; M2 -= v.M2;M3 -= v.M3; return *this; } template Vector4 Vector4::operator -(const Vector4 &v) const { return Vector4(M0-v.M0, M1-v.M1, M2-v.M2, M3-v.M3); } template Vector4 Vector4::operator -(void) const { return Vector4(-M0,-M1,-M2,-M3); } template bool Vector4::is_nan(void) const { return isnan(M0) || isnan(M1) || isnan(M2)|| isnan(M3); } template bool Vector4::is_inf(void) const { return isinf(M0) || isinf(M1) || isinf(M2)|| isinf(M3); } template Vector4 &Vector4::operator +=(const Vector4 &v) { M0+=v.M0; M1+=v.M1; M2+=v.M2;M3+=v.M3; return *this; } template Vector4 Vector4::operator +(const Vector4 &v) const { return Vector4(M0+v.M0, M1+v.M1, M2+v.M2, M3+v.M3); } template bool Vector4::operator ==(const Vector4 &v) const { return (is_equal(M0,v.M0) && is_equal(M1,v.M1) && is_equal(M2,v.M2) && is_equal(M3,v.M3)); } template bool Vector4::operator !=(const Vector4 &v) const { return (!is_equal(M0,v.M0) || !is_equal(M1,v.M1) || !is_equal(M2,v.M2)||!is_equal(M3,v.M3)); } // define for float template float Vector4::length(void) const; template float Vector4::operator *(const Vector4 &v) const; template Vector4 Vector4::operator *(const float num) const; template Vector4 &Vector4::operator *=(const float num); template Vector4 &Vector4::operator /=(const float num); template Vector4 Vector4::operator /(const float num) const; template Vector4 &Vector4::operator -=(const Vector4 &v); template Vector4 Vector4::operator -(const Vector4 &v) const; template Vector4 Vector4::operator -(void) const; template bool Vector4::is_nan(void) const; template bool Vector4::is_inf(void) const; template Vector4 &Vector4::operator +=(const Vector4 &v); template Vector4 Vector4::operator +(const Vector4 &v) const; template bool Vector4::operator ==(const Vector4 &v) const; template bool Vector4::operator !=(const Vector4 &v) const;