File: Wm5THPoint.h

package info (click to toggle)
libwildmagic 5.17%2Bcleaned1-7
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 90,124 kB
  • sloc: cpp: 215,940; csh: 637; sh: 91; makefile: 40
file content (181 lines) | stat: -rw-r--r-- 3,566 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
// Geometric Tools, LLC
// Copyright (c) 1998-2017
// Distributed under the Boost Software License, Version 1.0.
// http://www.boost.org/LICENSE_1_0.txt
// http://www.geometrictools.com/License/Boost/LICENSE_1_0.txt
//
// File Version: 5.16.0 (2017/08/24)

#ifndef WM5THPOINT_H
#define WM5THPOINT_H

#include "Wm5MathematicsLIB.h"

namespace Wm5
{

template <typename Real>
class THPoint
{
public:
    // Construction and destruction.  THPoint represents a homogeneous point
    // of the form (x,y,z,w).  Affine points are characterized by w = 1
    // (see class TAPoint) and affine vectors are characterized by w = 0
    // (see class TAVector).  The default constructor does not initialize
    // its members.
    THPoint()
    {
        // uninitialized members
    }

    THPoint(const THPoint& pnt)
    {
        mTuple[0] = pnt.mTuple[0];
        mTuple[1] = pnt.mTuple[1];
        mTuple[2] = pnt.mTuple[2];
        mTuple[3] = pnt.mTuple[3];
    }

    THPoint(Real x, Real y, Real z, Real w)
    {
        mTuple[0] = x;
        mTuple[1] = y;
        mTuple[2] = z;
        mTuple[3] = w;
    }

    ~THPoint()
    {
    }

    // Coordinate access.
    inline operator const Real*() const
    {
        return mTuple;
    }

    inline operator Real*()
    {
        return mTuple;
    }

    inline const Real& operator[] (int i) const
    {
        return mTuple[i];
    }

    inline Real& operator[] (int i)
    {
        return mTuple[i];
    }

    inline Real X() const
    {
        return mTuple[0];
    }

    inline Real& X()
    {
        return mTuple[0];
    }

    inline Real Y() const
    {
        return mTuple[1];
    }

    inline Real& Y()
    {
        return mTuple[1];
    }

    inline Real Z() const
    {
        return mTuple[2];
    }

    inline Real& Z()
    {
        return mTuple[2];
    }

    inline Real W() const
    {
        return mTuple[3];
    }

    inline Real& W()
    {
        return mTuple[3];
    }

    // Assignment.
    THPoint& operator= (const THPoint& pnt)
    {
        mTuple[0] = pnt.mTuple[0];
        mTuple[1] = pnt.mTuple[1];
        mTuple[2] = pnt.mTuple[2];
        mTuple[3] = pnt.mTuple[3];
        return *this;
    }

    // Comparison (for use by STL containers).
    bool operator== (const THPoint& pnt) const
    {
        for (int i = 0; i < 4; ++i)
        {
            if (mTuple[i] != pnt.mTuple[i])
            {
                return false;
            }
        }
        return true;
    }

    bool operator!= (const THPoint& pnt) const
    {
        return !operator==(pnt);
    }

    bool operator< (const THPoint& pnt) const
    {
        // lexicographical ordering
        for (int i = 0; i < 4; ++i)
        {
            if (mTuple[i] < pnt.mTuple[i])
            {
                return true;
            }
            if (mTuple[i] > pnt.mTuple[i])
            {
                return false;
            }
        }
        return false;
    }

    bool operator<= (const THPoint& pnt) const
    {
        // (x <= y) <=> !(y < x)
        return !(pnt.operator<(*this));
    }

    bool operator> (const THPoint& pnt) const
    {
        // (x > y) <=> (y < x)
        return pnt.operator<(*this);
    }

    bool operator>= (const THPoint& pnt) const
    {
        // (x >= y) <=> !(x < y)
        return !operator<(pnt);
    }

protected:
    Real mTuple[4];
};

}

#endif