Skip to content

Commit

Permalink
style \n
Browse files Browse the repository at this point in the history
  • Loading branch information
Part-time-Ray committed Sep 6, 2024
1 parent 1492e82 commit 6e1fb78
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 44 deletions.
30 changes: 10 additions & 20 deletions geometry/2DDefinition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,19 @@ int dcmp(ld x){if(fabs(x)<eps) return 0;else return x<0?-1:1;}
struct Pt{
ld x,y;
Pt(ld x=0,ld y=0):x(x),y(y){}
Pt operator+(const Pt &a) const {
return Pt(x+a.x, y+a.y); }
Pt operator-(const Pt &a) const {
return Pt(x-a.x, y-a.y); }
Pt operator*(const ld &a) const {
return Pt(x*a, y*a); }
Pt operator/(const ld &a) const {
return Pt(x/a, y/a); }
ld operator*(const Pt &a) const {//dot
return x*a.x + y*a.y; }
ld operator^(const Pt &a) const {//cross
return x*a.y - y*a.x; }
bool operator<(const Pt &a) const {
return x < a.x || (x == a.x && y < a.y); }
Pt operator+(const Pt &a) const {return Pt(x+a.x, y+a.y);}
Pt operator-(const Pt &a) const {return Pt(x-a.x, y-a.y);}
Pt operator*(const ld &a) const {return Pt(x*a, y*a);}
Pt operator/(const ld &a) const {return Pt(x/a, y/a);}
ld operator*(const Pt &a) const {return x*a.x + y*a.y;} //dot
ld operator^(const Pt &a) const {return x*a.y - y*a.x;} //cross
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 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;}
Expand Down
32 changes: 8 additions & 24 deletions geometry/3DDefinition.cpp
Original file line number Diff line number Diff line change
@@ -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);}

0 comments on commit 6e1fb78

Please sign in to comment.