-
Notifications
You must be signed in to change notification settings - Fork 0
/
xy.cpp
144 lines (124 loc) · 2.49 KB
/
xy.cpp
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
/******************************************************/
/* */
/* xy.cpp - 2D points */
/* */
/******************************************************/
/* Copyright 2018 Pierre Abbat.
* This file is part of the Quadlods program.
*
* The Quadlods program is free software: you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* Quadlods is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License and Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License
* and Lesser General Public License along with Quadlods. If not, see
* <http://www.gnu.org/licenses/>.
*/
#include "xy.h"
#include <cstdlib>
#include <cmath>
#include "ldecimal.h"
xy::xy(double e,double n)
{
x=e;
y=n;
}
xy::xy()
{
x=0;
y=0;
}
double xy::getx() const
{
return x;
}
double xy::gety() const
{
return y;
}
double xy::length() const
{
return hypot(x,y);
}
bool xy::isfinite() const
{
return std::isfinite(x) && std::isfinite(y);
}
bool xy::isnan() const
{
return std::isnan(x) || std::isnan(y);
}
xy operator+(const xy &l,const xy &r)
{
xy sum(l.x+r.x,l.y+r.y);
return sum;
}
xy operator+=(xy &l,const xy &r)
{
l.x+=r.x;
l.y+=r.y;
return l;
}
xy operator-=(xy &l,const xy &r)
{
l.x-=r.x;
l.y-=r.y;
return l;
}
xy operator*(double l,const xy &r)
{
xy prod(l*r.x,l*r.y);
return prod;
}
xy operator*(const xy &l,double r)
{
xy prod(l.x*r,l.y*r);
return prod;
}
xy operator-(const xy &l,const xy &r)
{
xy sum(l.x-r.x,l.y-r.y);
return sum;
}
xy operator-(const xy &r)
{
xy sum(-r.x,-r.y);
return sum;
}
xy operator/(const xy &l,double r)
{
xy prod(l.x/r,l.y/r);
return prod;
}
xy operator/=(xy &l,double r)
{
l.x/=r;
l.y/=r;
return l;
}
bool operator!=(const xy &l,const xy &r)
{
return l.x!=r.x || l.y!=r.y;
}
bool operator==(const xy &l,const xy &r)
{
return l.x==r.x && l.y==r.y;
}
double dist(xy a,xy b)
{
return hypot(a.x-b.x,a.y-b.y);
}
xy turn(xy a,int angle)
{
double s,c;
s=sin(angle*M_PI/128);
c=cos(angle*M_PI/128);
return xy(c*a.x-s*a.y,s*a.x+c*a.y);
}