-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPoint2.h
More file actions
124 lines (107 loc) · 3.31 KB
/
Point2.h
File metadata and controls
124 lines (107 loc) · 3.31 KB
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
#ifndef POINT2_H
#define POINT2_H
#include "VmUtil.h"
#include "Tuple2.h"
VM_BEGIN_NS
/**
* A 2 element point that is represented by x,y coordinates.
* @version specification 1.1, implementation $Revision: 1.4 $, $Date: 1999/10/06 02:52:46 $
* @author Kenji hiranabe
*/
template<class T>
class Point2 : public Tuple2<T> {
/*
* $Log: Point2.h,v $
* Revision 1.4 1999/10/06 02:52:46 hiranabe
* Java3D 1.2 and namespace
*
* Revision 1.3 1999/09/10 02:19:20 hiranabe
* distance*() method to const
*
* Revision 1.2 1999/05/26 00:59:37 hiranabe
* support Visual C++
*
* Revision 1.1 1999/03/04 11:07:09 hiranabe
* Initial revision
*
* Revision 1.1 1999/03/04 11:07:09 hiranabe
* Initial revision
*
*/
public:
/**
* Constructs and initializes a Point2 from the specified xy coordinates.
* @param x the x coordinate
* @param y the y coordinate
*/
Point2(T x, T y): Tuple2<T>(x, y) { }
/**
* Constructs and initializes a Point2 from the specified array.
* @param p the array of length 2 containing xy in order
*/
Point2(const T p[]): Tuple2<T>(p) { }
/**
* Constructs and initializes a Point2 from the specified Tuple2.
* @param t1 the Tuple2 containing the initialization x y data
*/
Point2(const Tuple2<T>& t1): Tuple2<T>(t1) { }
/**
* Constructs and initializes a Point2 to (0,0).
*/
Point2(): Tuple2<T>() { }
/**
* Computes the square of the distance between this point and point p1.
* @param p1 the other point
*/
T distanceSquared(const Point2& p1) const {
T dx = this->x - p1.x;
T dy = this->y - p1.y;
return dx*dx + dy*dy;
}
/**
* Computes the distance between this point and point p1.
* @param p1 the other point
*/
T distance(const Point2& p1) const {
return VmUtil<T>::sqrt(distanceSquared(p1));
}
/**
* Computes the L-1 (Manhattan) distance between this point and point p1.
* The L-1 distance is equal to abs(x1-x2) + abs(y1-y2).
* @param p1 the other point
*/
T distanceL1(const Point2& p1) const {
return VmUtil<T>::abs(this->x-p1.x) + VmUtil<T>::abs(this->y-p1.y);
}
/**
* Computes the L-infinite distance between this point and point p1.
* The L-infinite distance is equal to MAX[abs(x1-x2), abs(y1-y2)].
* @param p1 the other point
*/
T distanceLinf(const Point2& p1) const {
return VmUtil<T>::max(VmUtil<T>::abs(this->x-p1.x), VmUtil<T>::abs(this->y-p1.y));
}
// copy constructor and operator = is made by complier
Point2& operator=(const Tuple2<T>& t) {
Tuple2<T>::operator=(t);
return *this;
}
};
#ifdef VM_INCLUDE_IO
template <class T>
inline
std::ostream& operator<<(std::ostream& o, const VM_VECMATH_NS::Point2<T>& t1) {
return operator<<(o, (const VM_VECMATH_NS::Tuple2<T>&)t1);
}
#endif
typedef Point2<double> Point2d;
typedef Point2<float> Point2f;
/*
* 0. value_type typedef added
* 1. copy constructo, oeprator = are delegated to compiler
* 4. typdef value type
* 7. typedefs for <float>, <double>
* removed construction from Vector2f
*/
VM_END_NS
#endif /* POINT2_H */