summaryrefslogtreecommitdiffstats
path: root/vec.c
diff options
context:
space:
mode:
authorSam Anthony <sam@samanthony.xyz>2024-09-19 20:11:32 -0400
committerSam Anthony <sam@samanthony.xyz>2024-09-19 20:11:32 -0400
commitd439ed77546a00929ddd55bf44d65b448d9d520c (patch)
treecf1070d32e766c0fe5d753aebee840f0be67756f /vec.c
parent8944ad075c6b12bbda1273ec31efade801892c19 (diff)
downloadballs-d439ed77546a00929ddd55bf44d65b448d9d520c.zip
pretty good collisions
Diffstat (limited to 'vec.c')
-rw-r--r--vec.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/vec.c b/vec.c
index ba8edfa..b03a03f 100644
--- a/vec.c
+++ b/vec.c
@@ -6,23 +6,23 @@ vsub(Vec v1, Vec v2) {
}
Vec
-vmuls(Vec v, int a) {
+vmuls(Vec v, double a) {
return V(v.x*a, v.y*a);
}
Vec
-vdivs(Vec v, int a) {
+vdivs(Vec v, double a) {
if (a == 0)
return V(0, 0);
return V(v.x/a, v.y/a);
}
-int
+double
vdot(Vec v1, Vec v2) {
return v1.x*v2.x + v1.y*v2.y;
}
-int
+double
vlen(Vec v) {
return sqrt(v.x*v.x + v.y*v.y);
}
@@ -40,12 +40,16 @@ ptaddv(Point p, Vec v) {
}
Vec
-V(int x, int y) {
+V(double x, double y) {
Vec v = {x, y};
return v;
}
Vec
Vpt(Point p, Point q) {
- return V(p.x-q.x, p.y-q.y);
+ double dx, dy;
+
+ dx = (double) q.x - (double) p.x;
+ dy = (double) q.y - (double) p.y;
+ return V(dx, dy);
}