OSDN Git Service

first
[psychlops/cpp.git] / psychlops / core / graphic / psychlops_g_fundamental.cpp
1 /*
2  *  psychlops_g_fundamental.cpp
3  *  Psychlops Standard Library (Universal)
4  *
5  *  Last Modified 2005/10/05 by Kenchi HOSOKAWA
6  *  (C) 2005 Kenchi HOSOKAWA, Kazushi MARUYA, Takao SATO
7  */
8
9 #include <Math.h>
10
11 #include "../math/psychlops_math.h"
12 #include "psychlops_g_fundamental.h"
13 #include "psychlops_g_module.h"
14
15
16 namespace Psychlops {
17
18
19
20
21 /*      Point::Point() : x(0.0), y(0.0), z(0.0) {}
22
23         Point::Point(const double ix, const double iy, const double iz) : x(ix), y(iy), z(iz) {}
24         Point& Point::set(const double ix, const double iy, const double iz) {
25                 setbypix(ix,iy,iz);
26                 return *this;
27         }
28         Point& Point::shift(const double h, const double v, const double d) {
29                 setbypix(x+h,y+v,z+d);
30                 return *this;
31         }
32 */
33         Point& Point::centering() {
34                 *this = Drawable::prime->getCenter();
35                 return *this;
36         }
37         Point& Point::centering(const Figure &fig) {
38                 *this = fig.getDatum();
39                 return *this;
40         }
41 /*      Point& Point::centering(const double h, const double v, const double d) {
42                 setbypix(h, v, d);
43                 return *this;
44         }
45
46         Point& Point::setX(const double val) { x = val; return *this; }
47         Point& Point::setY(const double val) { y = val; return *this; }
48
49         double Point::getX() const { return x; }
50         double Point::getY() const { return y; }
51         double Point::getZ() const { return z; }
52
53         Point Point::dup() {
54                 return *this;
55         }
56
57         Point Point::operator+(const Point& rhs) {
58                 return Point(x+rhs.x, y+rhs.y, z+rhs.z);
59         }
60         Point Point::operator-(const Point& rhs) {
61                 return Point(x-rhs.x, y-rhs.y, z-rhs.z);
62         }
63 */
64 \r
65         double Point::length() const {\r
66                 return sqrt((x*x)+(y*y)+(z*z));\r
67         }
68
69 }       /*      <- namespace Psycholops         */
70
71
72
73
74
75
76
77
78
79
80 namespace Psychlops {
81
82
83         Length::Length() : px_(0.0) {}
84         Length::Length(const int val) : px_((double)val) {}
85         Length::Length(const double val) : px_(val) {}
86         Length::Length(const Length &val) : px_(val.px_) {}
87
88         Length::operator double() const {
89                 return px_;
90         }
91         Length & Length::operator =(const double val) {
92                 px_ = val;
93                 return *this;
94         }
95
96
97         LENGTH_ARCDEG arcdeg;
98         LENGTH_PIXEL pixel;
99         Length operator *(double pixels, LENGTH_PIXEL &unit) {
100                 return Length(pixels);
101         }
102
103
104
105         ANGLE_DEGREE degree;
106         Angle operator *(double degrees, ANGLE_DEGREE &unit) {
107                 return Angle(degrees, degree);
108         }
109         ANGLE_RADIAN radian;
110         Angle operator *(double radians, ANGLE_RADIAN &unit) {
111                 return Angle(radians, radian);
112         }
113
114         Angle::Angle(double decadegree, int dummy) : decadegree_(decadegree) {
115         }
116         Angle::Angle() {
117         }
118         Angle::Angle(const int degrees) {
119                 set_as_degree((double)degrees);
120         }
121         Angle::Angle(const double degrees) {
122                 set_as_degree(degrees);
123         }
124         Angle::Angle(const double degrees, ANGLE_DEGREE &unit) {
125                 set_as_degree(degrees);
126         }
127         Angle::Angle(const double radians, ANGLE_RADIAN &unit) {
128                 set_as_radian(radians);
129         }
130         Angle::Angle(const Angle &init) : decadegree_(init.decadegree_) {
131         }
132         Angle::operator double() const {
133                 return decadegree_/SCALE_TO_DEGREE;
134         }
135         Angle Angle::operator =(const double rhs) {
136                 set_as_degree(rhs);
137                 return *this;
138         }
139         Angle Angle::operator +(Angle rhs) const {
140                 return Angle(decadegree_+rhs.decadegree_, 0);
141         }
142         Angle Angle::operator -(Angle rhs) const {
143                 return Angle(decadegree_-rhs.decadegree_, 0);
144         }
145         Angle & Angle::operator +=(Angle rhs) {
146                 decadegree_ += rhs.decadegree_;
147                 return *this;
148         }
149         Angle & Angle::operator -=(Angle rhs) {
150                 decadegree_ -= rhs.decadegree_;
151                 return *this;
152         }
153         double Angle::clip() const {
154                 return Math::mod(decadegree_, PERIOD)/SCALE_TO_DEGREE;
155         }
156         double Angle::at_degree() const {
157                 return decadegree_/SCALE_TO_DEGREE;
158         }
159         double Angle::at_radian() const {
160                 return PI * decadegree_ / HALF_PERIOD;
161         }
162         double Angle::sin() const {
163                 return ::sin(this->at_radian());
164         }
165         double Angle::cos() const {
166                 return ::cos(this->at_radian());
167         }
168         double Angle::tan() const {
169                 return ::tan(this->at_radian());
170         }
171         void Angle::set_as_degree(double degrees) {
172                 decadegree_ = degrees * SCALE_TO_DEGREE;
173         }
174         void Angle::set_as_decadegree(double decadegree) {
175                 decadegree_ = decadegree;
176         }
177         void Angle::set_as_radian(double radians) {
178                 decadegree_ = HALF_PERIOD * radians / PI;
179         }
180
181         const double Angle::HALF_PERIOD = PERIOD/2;
182         const double Angle::SCALE_TO_DEGREE = PERIOD/360;
183
184         const double Angle::PERIOD = 3600;
185
186
187
188 }       /*      <- namespace Psycholops         */
189
190