Skip to content

Instantly share code, notes, and snippets.

@GoBigorGoHome
Last active December 16, 2018 13:30
Show Gist options
  • Save GoBigorGoHome/403d57a31b438ce144d81271242510a2 to your computer and use it in GitHub Desktop.
Save GoBigorGoHome/403d57a31b438ce144d81271242510a2 to your computer and use it in GitHub Desktop.
计算几何模板(建设中)
template <typename T>
T sq(const T &a){return a * a;}
using ldb = long double;
struct pnt{
ldb x, y;
ldb len()const{
return std::sqrt(x * x + y * y);
}
ldb len2()const{
return x * x + y * y;
}
pnt operator-(const pnt &other)const{
return {x - other.x, y - other.y};
}
void read(){cin >> x >> y;}
};
struct rect{
pnt p[2];
void read(){p[0].read(), p[1].read();}
bool cover(const pnt &a)const{
return p[0].x <= a.x && a.x <= p[1].x && p[0].y <= a.y && a.y <= p[1].y;
}
};
struct seg{
pnt a, b;
void read(){a.read(), b.read();}
};
struct circ{
pnt c;
ldb r;
void read(){c.read(); cin >> r;}
bool cover(const pnt &p)const{
return (p - c).len2() <= r * r;
}
bool is_cross(const seg &a, pnt *res = nullptr)const { //未完成
if(cover(a.a) && cover(a.b)) return true;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment