source: golgotha/src/maxtool/sdk_inc/point2.h @ 80

Last change on this file since 80 was 80, checked in by Sam Hocevar, 12 years ago
  • Adding the Golgotha source code. Not sure what's going to be interesting in there, but since it's all public domain, there's certainly stuff to pick up.
  • Property svn:keywords set to Id
File size: 3.3 KB
Line 
1/**********************************************************************
2 *<
3        FILE: point2.h
4
5        DESCRIPTION: Class definition for Point2
6
7        CREATED BY: Dan Silva
8
9        HISTORY:
10
11 *>     Copyright (c) 1994, All Rights Reserved.
12 **********************************************************************/
13
14#ifndef __POINT2__
15
16#define __POINT2__
17
18class ostream;
19
20class Point2 {
21public:
22        float x,y;
23
24        // Constructors
25        Point2(){}
26        Point2(float X, float Y)  { x = X; y = Y;  }
27        Point2(double X, double Y)  { x = (float)X; y = (float)Y;  }
28        Point2(const Point2& a) { x = a.x; y = a.y; }
29        Point2(float af[2]) { x = af[0]; y = af[1]; }
30
31        // Access operators
32        float& operator[](int i) { return (&x)[i]; }     
33        const float& operator[](int i) const { return (&x)[i]; } 
34       
35        // Conversion function
36        operator float*() { return(&x); }
37
38        // Unary operators
39        Point2 operator-() const { return(Point2(-x,-y)); }
40        Point2 operator+() const { return *this; }
41
42        // Assignment operators
43        DllExport Point2& operator-=(const Point2&);
44        DllExport Point2& operator+=(const Point2&);
45        DllExport Point2& operator*=(float);
46        DllExport Point2& operator/=(float);
47
48        // Binary operators
49        DllExport Point2 operator-(const Point2&) const;
50        DllExport Point2 operator+(const Point2&) const;
51        DllExport float DotProd(const Point2&) const;           // DOT PRODUCT
52        DllExport float operator*(const Point2&) const; // DOT PRODUCT
53
54        // Relational operators
55        int operator==(const Point2& p) const { return (x == p.x && y == p.y); }
56        };
57
58
59float DllExport Length(const Point2&);
60int DllExport MaxComponent(const Point2&);  // the component with the maximum abs value
61int DllExport MinComponent(const Point2&);  // the component with the minimum abs value
62Point2 DllExport Normalize(const Point2&); // Return a unit vector.
63         
64Point2 DllExport operator*(float, const Point2&);       // multiply by scalar
65Point2 DllExport operator*(const Point2&, float);       // multiply by scalar
66Point2 DllExport operator/(const Point2&, float);       // divide by scalar
67
68ostream DllExport &operator<<(ostream&, const Point2&);
69         
70// Inlines:
71
72inline float Length(const Point2& v) { 
73        return (float)sqrt(v.x*v.x+v.y*v.y);
74        }
75
76inline Point2& Point2::operator-=(const Point2& a) {   
77        x -= a.x;       y -= a.y; 
78        return *this;
79        }
80
81inline Point2& Point2::operator+=(const Point2& a) {
82        x += a.x;       y += a.y; 
83        return *this;
84        }
85
86inline Point2& Point2::operator*=(float f) {
87        x *= f;   y *= f;       
88        return *this;
89        }
90
91inline Point2& Point2::operator/=(float f) {
92        x /= f; y /= f;         
93        return *this;
94        }
95
96inline Point2 Point2::operator-(const Point2& b) const{
97        return(Point2(x-b.x,y-b.y));
98        }
99
100inline Point2 Point2::operator+(const Point2& b) const {
101        return(Point2(x+b.x,y+b.y));
102        }
103
104inline float Point2::DotProd(const Point2& b) const{
105        return(x*b.x+y*b.y);
106        }
107
108inline float Point2::operator*(const Point2& b)const {
109        return(x*b.x+y*b.y);
110        }
111
112inline Point2 operator*(float f, const Point2& a) {
113        return(Point2(a.x*f, a.y*f));
114        }
115
116inline Point2 operator*(const Point2& a, float f) {
117        return(Point2(a.x*f, a.y*f));
118        }
119
120inline Point2 operator/(const Point2& a, float f) {
121        return(Point2(a.x/f, a.y/f));
122        }
123
124#endif
125
Note: See TracBrowser for help on using the repository browser.