summaryrefslogtreecommitdiff
path: root/util.c
diff options
context:
space:
mode:
authorrodri <rgl@antares-labs.eu>2020-02-20 21:56:37 +0000
committerrodri <rgl@antares-labs.eu>2020-02-20 21:56:37 +0000
commite1cb9df9355a6ae67aac76dbcde209b8f70796ee (patch)
tree2a5a01e89fb4b1f9bd497a318fb59e0e34622d60 /util.c
downloadasteroids-e1cb9df9355a6ae67aac76dbcde209b8f70796ee.tar.gz
asteroids-e1cb9df9355a6ae67aac76dbcde209b8f70796ee.tar.bz2
asteroids-e1cb9df9355a6ae67aac76dbcde209b8f70796ee.zip
git release.HEADmaster
Diffstat (limited to 'util.c')
-rw-r--r--util.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/util.c b/util.c
new file mode 100644
index 0000000..ef31bde
--- /dev/null
+++ b/util.c
@@ -0,0 +1,40 @@
+#include <u.h>
+#include <libc.h>
+#include <draw.h>
+#include "dat.h"
+#include "fns.h"
+
+double
+round(double n)
+{
+ return floor(n + 0.5);
+}
+
+Point
+rotatept(Point p, double θ, Point c)
+{
+ Point r;
+
+ p = subpt(p, c);
+ r.x = round(p.x*cos(θ) - p.y*sin(θ));
+ r.y = round(p.x*sin(θ) + p.y*cos(θ));
+ r = addpt(r, c);
+ return r;
+}
+
+int
+ptincircle(Point p, Point c, double r)
+{
+ Point d;
+
+ d = subpt(c, p);
+ return hypot(d.x, d.y) < r;
+}
+
+int
+triangleXcircle(Triangle t, Point c, double r)
+{
+ return ptincircle(t.p0, c, r) ||
+ ptincircle(t.p1, c, r) ||
+ ptincircle(t.p2, c, r);
+}