diff --git a/geometry/2DDefinition.cpp b/geometry/2DDefinition.cpp index 55ca9f6..662f598 100644 --- a/geometry/2DDefinition.cpp +++ b/geometry/2DDefinition.cpp @@ -4,29 +4,19 @@ int dcmp(ld x){if(fabs(x)(const Pt &a) const { - return x > a.x || (x == a.x && y > a.y); } + bool operator>(const Pt &a) const {return x > a.x || (x == a.x && y > a.y);} //return dcmp(x-a.x) > 0 || (dcmp(x-a.x) == 0 && dcmp(y-a.y) > 0); } - bool operator==(const Pt &a) const { - return dcmp(x-a.x) == 0 && dcmp(y-a.y) == 0; } + bool operator==(const Pt &a) const {return dcmp(x-a.x) == 0 && dcmp(y-a.y) == 0;} // return x == other.x && y == other.y; - bool operator!=(const Pt &a) const { - return !(*this == a); } + bool operator!=(const Pt &a) const {return !(*this == a);} }; typedef Pt Vec; ld Dot(Vec a,Vec b){return a.x*b.x+a.y*b.y;} diff --git a/geometry/3DDefinition.cpp b/geometry/3DDefinition.cpp index 36b7d04..47286c2 100644 --- a/geometry/3DDefinition.cpp +++ b/geometry/3DDefinition.cpp @@ -1,29 +1,13 @@ struct Pt { ld x, y, z; Pt(ld _x = 0, ld _y = 0, ld _z = 0) : x(_x), y(_y), z(_z) {} - Pt operator+(const Pt &a) const { - return Pt(x + a.x, y + a.y, z + a.z); - } - Pt operator-(const Pt &a) const { - return Pt(x - a.x, y - a.y, z - a.z); - } - Pt operator*(const ld &a) const { - return Pt(x * a, y * a, z * a); - } - Pt operator/(const ld &a) const { - return Pt(x / a, y / a, z / a); - } - ld operator*(const Pt &a) const { - return x * a.x + y * a.y + z * a.z; - } - Pt operator^(const Pt &a) const { - return Pt(y * a.z - z * a.y, z * a.x - x * a.z, x * a.y - y * a.x); - } - bool operator<(const Pt &a) const { - return x < a.x || (x == a.x && (y < a.y || (y == a.y && z < a.z))); - } - bool operator==(const Pt &a) const { - return dcmp(x - a.x) == 0 && dcmp(y - a.y) == 0 && dcmp(z - a.z) == 0; - } + Pt operator+(const Pt &a) const {return Pt(x + a.x, y + a.y, z + a.z);} + Pt operator-(const Pt &a) const {return Pt(x - a.x, y - a.y, z - a.z);} + Pt operator*(const ld &a) const {return Pt(x * a, y * a, z * a);} + Pt operator/(const ld &a) const {return Pt(x / a, y / a, z / a);} + ld operator*(const Pt &a) const {return x * a.x + y * a.y + z * a.z;} + Pt operator^(const Pt &a) const {return Pt(y * a.z - z * a.y, z * a.x - x * a.z, x * a.y - y * a.x);} + bool operator<(const Pt &a) const {return x < a.x || (x == a.x && (y < a.y || (y == a.y && z < a.z)));} + bool operator==(const Pt &a) const {return dcmp(x - a.x) == 0 && dcmp(y - a.y) == 0 && dcmp(z - a.z) == 0;} }; ld norm2(const Pt &a,const Pt &b) {return (a-b)*(a-b);}