Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define int long long
- #define ld long double
- const ld EPS = 1e-12, PI = 3.1415926535897;
- // geometry primitives
- int sign(int x) {
- if (x > 0) return 1;
- if (x < 0) return -1;
- return 0;
- }
- int sign(ld x) {
- if (x > EPS) return 1;
- if (x < -EPS) return -1;
- return 0;
- }
- ld sq(ld x) { return x * x; }
- #define vec2 point
- struct point {
- ld x, y;
- point() : x(), y() {} // empty constructor
- point(const ld& x_, const ld& y_) : x(x_), y(y_) {} // constructor from coords
- point operator-(const point& oth) const { return point(x - oth.x, y - oth.y); } // various operators
- point operator+(const point& oth) const { return point(x + oth.x, y + oth.y); }
- point operator*(const ld& a) const { return point(x * a, y * a); }
- ld operator^(const point& oth) const { return x * oth.y - y * oth.x; } // scalar multiplication
- bool operator<(const point& oth) const { // check, if point equal
- if (sign(x - oth.x)) return x < oth.x;
- if (sign(y - oth.y)) return y < oth.y;
- return false;
- }
- bool operator==(const point& oth) const { return !sign(x - oth.x) && !sign(y - oth.y); }
- ld len2() const { return sq(x) + sq(y); } // len of the vector squared (if we don't need precision)
- ld len() const { return sqrt(len2()); } // len of the vector
- point norm() const { // norm a vector
- ld d = len();
- assert(sign(d)); // we can't norm a point
- return point(x / d, y / d);
- }
- point ort() const { return point(-y, x); } // orthogonal vector
- void print() { cout << '(' << x << ',' << y << ')' << endl; }
- };
Add Comment
Please, Sign In to add comment