#pragma once
#include "linevec.hpp"
#include "point.hpp"
#include "vec.hpp"
struct Line{
//ax+by+c=0 (required: a*a+b*b != 0)
long double a,b,c;
Line(long double a, long double b, long double c): a(a), b(b), c(c){}
Line(LineVec lv){
a = -lv.vec.y;
b = lv.vec.x;
c = -(a*lv.base.x + b*lv.base.y);
}
Line operator/(long double v){
return {a/v, b/v, c/v};
}
Line(LineSegment ls){
(*this) = (LineVec)(ls);
}
Line(Point a, Point b){
LineSegment ls({a,b});
(*this) = (LineSegment)(ls);
}
};
Line standardize(Line l){
return l/sqrt(l.a*l.a+l.b*l.b);
}
long double distance(Line l, Point p){
Line nl = standardize(l);
return nl.a*p.x + nl.b*p.y + nl.c;
}
Vec normal(Line l){
Vec v = {-l.a, -l.b};
return standardize(v);
}
#line 2 "cpp/geometry/vec.hpp"
struct Vec{
long double x,y;
Vec operator*(long double a){
return {x*a, y*a};
}
Vec operator/(long double a){
return {x/a, y/a};
}
friend ostream &operator<<(ostream &os, const Vec &p){
return os << p.x << " " << p.y;
}
};
long double magnitude(Vec v){
return sqrt(v.x*v.x+v.y*v.y);
}
Vec standardize(Vec v){
return v/magnitude(v);
}
#line 3 "cpp/geometry/point.hpp"
struct Point{
long double x,y;
Vec operator-(Point b){
return {x-b.x, y-b.y};
}
Point operator+(long double a){
return {x+a, y+a};
}
Point operator+(Vec v){
return {x+v.x, y+v.y};
}
friend istream &operator>>(istream &is, Point &p){
long double a,b;
cin>>a>>b;
p = Point({a,b});
return (is);
}
friend ostream &operator<<(ostream &os, const Point &p){
return os << p.x << " " << p.y;
}
};
#line 2 "cpp/geometry/line-segment.hpp"
#line 4 "cpp/geometry/line-segment.hpp"
struct LineSegment{
Point first, second;
LineSegment(Point a, Point b):first(a),second(b){}
};
#line 5 "cpp/geometry/linevec.hpp"
struct LineVec{
Point base;
Vec vec;
LineVec(LineSegment ls){
base = ls.first;
vec = ls.second - ls.first;
}
};
#line 5 "cpp/geometry/line.hpp"
struct Line{
//ax+by+c=0 (required: a*a+b*b != 0)
long double a,b,c;
Line(long double a, long double b, long double c): a(a), b(b), c(c){}
Line(LineVec lv){
a = -lv.vec.y;
b = lv.vec.x;
c = -(a*lv.base.x + b*lv.base.y);
}
Line operator/(long double v){
return {a/v, b/v, c/v};
}
Line(LineSegment ls){
(*this) = (LineVec)(ls);
}
Line(Point a, Point b){
LineSegment ls({a,b});
(*this) = (LineSegment)(ls);
}
};
Line standardize(Line l){
return l/sqrt(l.a*l.a+l.b*l.b);
}
long double distance(Line l, Point p){
Line nl = standardize(l);
return nl.a*p.x + nl.b*p.y + nl.c;
}
Vec normal(Line l){
Vec v = {-l.a, -l.b};
return standardize(v);
}