-
Notifications
You must be signed in to change notification settings - Fork 0
/
library.h
177 lines (152 loc) · 6.97 KB
/
library.h
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
#ifndef MATHLIB_LIBRARY_H
#define MATHLIB_LIBRARY_H
#include <cmath>
#include <vector>
#include <cstddef>
#include <algorithm>
namespace Math
{
using std::sin;
using std::cos;
using std::tan;
using std::asin;
using std::acos;
using std::atan;
using std::atan2;
using std::sinh;
using std::cosh;
using std::tanh;
using std::asinh;
using std::acosh;
using std::atanh;
using std::exp;
using std::logb;
using std::log2;
using std::log10;
using std::pow;
using std::sqrt;
using std::abs;
using std::fabs;
struct Point;
struct Vector;
struct Line;
struct Circle;
struct Point
{
double x, y;
inline explicit Point(double = 0, double = 0);
Point& operator +=(const Vector&);
};
struct Vector
{
double x, y;
inline explicit Vector(double = 0, double = 0);
Vector& operator +=(const Vector&);
Vector& operator *=(double);
Vector& operator /=(double);
};
struct Line
{
Point P;
Vector v;
inline explicit Line(const Point& = Point(), const Vector& = Vector());
const Point GetPoint(double) const;
};
struct Circle
{
Point C;
double r;
inline explicit Circle(const Point& = Point(), double = 0);
const Point GetPoint(double) const;
};
typedef std::vector<Point> Polygon;
inline const Vector operator +(Vector, const Vector&);
inline const Point operator +(Point, const Vector&);
const Point operator +(const Vector&, const Point&);
const Vector operator -(const Point&, const Point&);
inline const Vector operator *(Vector, double);
inline const Vector operator /(Vector, double);
const bool operator <(const Point&, const Point&);
const bool operator <(const Vector&, const Vector&);
const bool operator <(const Line&, const Line&);
const bool operator ==(const Point&, const Point&);
const bool operator ==(const Vector&, const Vector&);
const bool operator ==(const Line&, const Line&);
const bool operator ==(const Circle&, const Circle&);
inline const bool operator <=(const Point&, const Point&);
inline const bool operator <=(const Vector&, const Vector&);
inline const bool operator <=(const Line&, const Line&);
inline const bool operator >(const Point&, const Point&);
inline const bool operator >(const Vector&, const Vector&);
inline const bool operator >(const Line&, const Line&);
inline const bool operator >=(const Point&, const Point&);
inline const bool operator >=(const Vector&, const Vector&);
inline const bool operator >=(const Line&, const Line&);
inline const bool operator !=(const Point&, const Point&);
inline const bool operator !=(const Vector&, const Vector&);
inline const bool operator !=(const Line&, const Line&);
inline const bool operator !=(const Circle&, const Circle&);
const double eps = 1e-10;
const double E = exp(1);
const double PI = acos(-1);
const int dcmp(double);
inline const double Dot(const Vector&, const Vector&);
inline const double Length(const Vector&);
inline const double Angle(const Vector&, const Vector&);
inline const double Angle(const Vector&);
inline const double Cross(const Vector&, const Vector&);
inline const double Area2(const Point&, const Point&, const Point&);
inline const Vector Rotate(const Vector&, double);
inline const Vector Normal(const Vector&); // Please ensure Vector is not zero vector
const int Intersection(const Line&, const Line&, std::vector<Point>&);
const int Intersection(const Line&, const Point&, const Point&, std::vector<Point>&);
inline const int Intersection(const Point&, const Point&, const Line&, std::vector<Point>&);
const int Intersection(const Point&, const Point&, const Point&, const Point&, std::vector<Point>&);
const int Intersection(const Circle&, const Point&, const Point&, std::vector<Point>&);
inline const int Intersection(const Point&, const Point&, const Circle&, std::vector<Point>&);
const int Intersection(const Line&, const Circle&, std::vector<Point>&);
inline const int Intersection(const Circle&, const Line&, std::vector<Point>&);
const int Intersection(const Circle&, const Circle&, std::vector<Point>&);
const int Intersection(const Line&, const Polygon&, std::vector<Point>&);
inline const int Intersection(const Polygon&, const Line&, std::vector<Point>&);
const int Intersection(const Polygon&, const Point&, const Point&, std::vector<Point>&);
inline const int Intersection(const Point&, const Point&, const Polygon&, std::vector<Point>&);
const int Intersection(const Polygon&, const Circle&, std::vector<Point>&);
inline const int Intersection(const Circle&, const Polygon&, std::vector<Point>&);
const int Intersection(const Polygon&, const Polygon&, std::vector<Point>&);
const int Intersection(std::vector<Line>, Polygon&);
const bool ProperIntersection(const Line&, const Line&);
const bool ProperIntersection(const Point&, const Point&, const Line&);
inline const bool ProperIntersection(const Line&, const Point&, const Point&);
const bool ProperIntersection(const Point&, const Point&, const Point&, const Point&);
inline const double Distance(const Point&, const Point&);
const double Distance(const Point&, const Line&);
inline const double Distance(const Line&, const Point&);
const double Distance(const Point&, const Point&, const Point&);
const Point Project(const Point&, const Line&);
inline const Point Project(const Line&, const Point&);
inline const bool On(const Point&, const Line&);
inline const bool On(const Line&, const Point&);
const bool On(const Point&, const Point&, const Point&);
inline const bool On(const Point&, const Circle&);
inline const bool On(const Circle&, const Point&);
const bool On(const Point&, const Polygon&);
inline const bool On(const Polygon&, const Point&);
inline const bool In(const Point&, const Line&);
inline const bool In(const Line&, const Point&);
inline const bool In(const Point&, const Circle&);
inline const bool In(const Circle&, const Point&);
const bool In(const Point&, const Polygon&);
inline const bool In(const Polygon&, const Point&);
const double Area(const Polygon&);
inline const double Area(const Circle&);
const int Tangents(const Point&, const Circle&, std::vector<Line>&);
inline const int Tangents(const Circle&, const Point&, std::vector<Line>&);
const int Tangents(Circle, Circle, std::vector<Line>&);
const Circle CircumscribedCircle(const Point&, const Point&, const Point&);
const Circle InscribedCircle(const Point&, const Point&, const Point&);
const int ConvexHull(std::vector<Point>, Polygon&);
const Polygon Cut(const Polygon&, const Line&);
inline const Polygon Cut(const Line&, const Polygon&);
}
#endif