Skip to content

Commit

Permalink
Added geometry
Browse files Browse the repository at this point in the history
  • Loading branch information
dothething1DA committed Oct 17, 2024
1 parent ecd4f50 commit e5a3a0c
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 1 deletion.
8 changes: 8 additions & 0 deletions content/geometry/angle.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* Author: me
* Description: rad - deg converter.
* Time: $O(1)$
*/

long double deg_to_rad(long double d) {return d*M_PI/180.0;}
long double rad_to_deg(long double r) {return r*180.0/M_PI;}
4 changes: 4 additions & 0 deletions content/geometry/chapter.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
\chapter{Geometry}

\kactlimport{angle.cpp}
\kactlimport{point.cpp}
54 changes: 54 additions & 0 deletions content/geometry/point.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/**
* Author: me
* Description: Point and Vector.
* Time: N/A
*/

#define Vector Point /** keep-include */

template<class T>
struct Point {
// CAREFUL
static constexpr T eps = 1e-9;

T x, y;
Point() {}
Point(T _x, T _y) {x = _x; y = _y;}

// Comparison
bool operator<(Point p) const {
if (abs(x - p.x) > eps) return x < p.x;
return y < p.y;
}

bool operator==(Point p) const {
return (abs(x-p.x) < eps) && (abs(y-p.y) < eps);
}

// Calculation
T operator&(Vector v) const {return x*v.y - y*v.x;}
T operator*(Vector v) const {return x*v.x + y*v.y;}
Vector operator*(T d) const {return Vector(x*d, y*d);}
Vector operator/(T d) const {return Vector(x/d, y/d);}
Vector operator+(Vector v) const {return Vector(x+v.x,y+v.y);}
Vector operator-(Vector v) const {return Vector(x-v.x,y-v.y);}

void operator*=(T d) {x *= d; y *= d;}
void operator/=(T d) {x /= d; y /= d;}
void operator+=(Vector v) {x += v.x; y += v.y;}
void operator-=(Vector v) {x -= v.x; y -= v.y;}

T len2() {return x*x + y*y;}
long double len() {return sqrt((long double)(len2()));}
T dist2(Point p) {return (x-p.x)*(x-p.x) + (y-p.y)*(y-p.y);}
long double dist(Point p) {return sqrt(dist2(p));}

// Rotate to the left
Point rotated(long double a)
{return Point(x*cos(a)-y*sin(a),x*sin(a)+y*cos(a));}
void rotate(long double a) {
T cx = x*cos(a) - y*sin(a);
T cy = x*sin(a) + y*cos(a);
x = cx; y = cy;
}
};
1 change: 1 addition & 0 deletions content/kactl.tex
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@
\kactlchapter{data-structures}
\kactlchapter{graph}
\kactlchapter{number-theory}
\kactlchapter{geometry}
\end{multicols*}
\end{document}
2 changes: 1 addition & 1 deletion content/number-theory/chapter.tex
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
\chapter{number-theory}
\chapter{Number Theory}
\kactlimport{modInverse.cpp}
Binary file modified kactl.pdf
Binary file not shown.
Binary file added test-session.pdf
Binary file not shown.

0 comments on commit e5a3a0c

Please sign in to comment.