summaryrefslogtreecommitdiffstats
path: root/point.cpp
diff options
context:
space:
mode:
authorSam Anthony <sam@samanthony.xyz>2024-10-02 16:31:31 -0400
committerSam Anthony <sam@samanthony.xyz>2024-10-02 16:31:31 -0400
commitbaef318193316fc365ba4b0a559c387d96b4305a (patch)
tree771d8d32b5e3a85c418b0d23307bd3d14094c12c /point.cpp
parent26ce765feb702c6d40f89a8cf50274869cdc35b4 (diff)
downloadballs-baef318193316fc365ba4b0a559c387d96b4305a.zip
refactor
Diffstat (limited to 'point.cpp')
-rw-r--r--point.cpp63
1 files changed, 63 insertions, 0 deletions
diff --git a/point.cpp b/point.cpp
new file mode 100644
index 0000000..099165d
--- /dev/null
+++ b/point.cpp
@@ -0,0 +1,63 @@
+#include "balls.h"
+
+Point
+addPt(Point p, Point q) {
+ p.x += q.x;
+ p.y += q.y;
+ return p;
+}
+
+Point
+subPt(Point p, Point q) {
+ p.x -= q.x;
+ p.y -=q.y;
+ return p;
+}
+
+Point
+ptAddVec(Point p, Vector v) {
+ p.x += v.x;
+ p.y += v.y;
+ return p;
+}
+
+Point
+ptSubVec(Point p, Vector v) {
+ p.x -= v.x;
+ p.y -= v.y;
+ return p;
+}
+
+Point
+ptMulS(Point p, double s) {
+ p.x *= s;
+ p.y *= s;
+ return p;
+}
+
+Point
+ptDivS(Point p, double s) {
+ p.x /= s;
+ p.y /=s;
+ return p;
+}
+
+Point
+Pt(double x, double y) {
+ Point p = {x, y};
+ return p;
+}
+
+Rectangle
+insetRect(Rectangle r, double n) {
+ r.min.x += n;
+ r.min.y += n;
+ r.max.x -= n;
+ r.max.y -= n;
+ return r;
+}
+
+Point
+randPtInRect(Rectangle r) {
+ return Pt(randDouble(r.min.x, r.max.x), randDouble(r.min.y, r.max.y));
+}