source: git/src/vector3.h @ 91c9bea

RELEASE/1.1RELEASE/1.2debug-cidebug-ci-sanitisersfaster-cavernloglog-selectstereostereo-2025walls-datawalls-data-hanging-as-warningwarn-only-for-hanging-survey
Last change on this file since 91c9bea was 9b30732, checked in by Olly Betts <olly@…>, 21 years ago

Add operator< so we can use Vector3 as the key to a map

git-svn-id: file:///home/survex-svn/survex/branches/survex-1_1@2758 4b37db11-9a0c-4f06-9ece-9ab7cdaee568

  • Property mode set to 100644
File size: 2.4 KB
RevLine 
[5809313]1//
2//  vector3.h
3//
4//  C++ class for 3-element vectors
5//
[f8e4c56]6//  Copyright (C) 2000-2002, Mark R. Shinwell.
[6acee34]7//  Copyright (C) 2002-2004 Olly Betts
[5809313]8//
9//  This program is free software; you can redistribute it and/or modify
10//  it under the terms of the GNU General Public License as published by
11//  the Free Software Foundation; either version 2 of the License, or
12//  (at your option) any later version.
13//
14//  This program is distributed in the hope that it will be useful,
15//  but WITHOUT ANY WARRANTY; without even the implied warranty of
16//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17//  GNU General Public License for more details.
18//
19//  You should have received a copy of the GNU General Public License
20//  along with this program; if not, write to the Free Software
21//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22//
23
24#ifndef Vector3_h
25#define Vector3_h
26
[27b8b59]27#include <math.h>
[156dc16]28
[5809313]29class Vector3 {
[156dc16]30    double x; //--FIXME
[5809313]31    double y;
32    double z;
33
34public:
35    Vector3();
36    Vector3(double, double, double);
37    ~Vector3();
38
[97d93e1]39    double getX() const { return x; }
40    double getY() const { return y; }
41    double getZ() const { return z; }
[5809313]42
[27b8b59]43    double magnitude() const {
44        return sqrt(x*x + y*y + z*z);
45    }
46
[5809313]47    void normalise();
48
49    void set(double, double, double);
50
[156dc16]51    friend Vector3 operator-(const Vector3& v) {
[421b7d2]52        Vector3 o;
[156dc16]53        o.x = -v.x;
54        o.y = -v.y;
55        o.z = -v.z;
56        return o;
57    }
[5809313]58    Vector3& operator*=(const double);
59    Vector3& operator/=(const double);
[e4ec4b4]60    Vector3& operator+=(const Vector3&);
61    Vector3& operator-=(const Vector3&);
[5809313]62    Vector3& operator=(const Vector3&);
63
64    friend Vector3 operator*(const double, const Vector3&);
[446e096]65    friend Vector3 operator*(const Vector3& v, const double f) {
66        return f * v;
67    }
[156dc16]68    friend Vector3 operator*(const Vector3&, const Vector3&); // cross product
[5809313]69    friend Vector3 operator+(const Vector3&, const Vector3&);
[f8e4c56]70    friend Vector3 operator-(const Vector3&, const Vector3&);
[e4ec4b4]71    friend bool operator==(const Vector3&, const Vector3&);
[9b30732]72    friend bool operator<(const Vector3&, const Vector3&);
[5809313]73    friend double dot(const Vector3&, const Vector3&);
74};
75
[e4ec4b4]76inline bool operator==(const Vector3& a, const Vector3& b) {
77    return a.x == b.x && a.y == b.y && a.z == b.z;
78}
79
[9b30732]80// So we can use Vector3 as a key in a map...
81inline bool operator<(const Vector3& a, const Vector3& b) {
82    if (a.x != b.x) return a.x < b.x;
83    if (a.y != b.y) return a.y < b.y;
84    return a.z < b.z;
85}
86
[5809313]87#endif
Note: See TracBrowser for help on using the repository browser.