]> git.lizzy.rs Git - nothing.git/blobdiff - src/math/rect.c
(#655) Remove opposing force from rigid_bodies
[nothing.git] / src / math / rect.c
index aa3f053ca4c8baf7327643130299443005550972..776c5d8126fb9e2a11d8e64bfa4198575f2b6e94 100644 (file)
@@ -165,20 +165,22 @@ Vec rect_center(Rect rect)
                rect.y + rect.h * 0.5f);
 }
 
-Rect rect_snap(Rect pivot, Rect r)
+Vec rect_snap(Rect pivot, Rect *r)
 {
     const Vec pivot_c = rect_center(pivot);
-    const Vec r_c = rect_center(r);
+    const Vec r_c = rect_center(*r);
 
     const float sx = r_c.x < pivot_c.x ? -1.0f : 1.0f;
     const float sy = r_c.y < pivot_c.y ? -1.0f : 1.0f;
-    const float x = pivot_c.x + sx * (pivot.w + r.w) * 0.5f - r.w * 0.5f;
-    const float y = pivot_c.y + sy * (pivot.h + r.h) * 0.5f - r.h * 0.5f;
+    const float x = pivot_c.x + sx * (pivot.w + r->w) * 0.5f - r->w * 0.5f;
+    const float y = pivot_c.y + sy * (pivot.h + r->h) * 0.5f - r->h * 0.5f;
 
     if (fabsf(x - r_c.x) < fabsf(y - r_c.y)) {
-        return rect(x, r.y, r.w, r.h);
+        *r = rect(x, r->y, r->w, r->h);
+        return vec(0.0f, 1.0f);
     } else {
-        return rect(r.x, y, r.w, r.h);
+        *r = rect(r->x, y, r->w, r->h);
+        return vec(1.0f, 0.0f);;
     }
 }