-#include <assert.h>
+#include "system/stacktrace.h"
#include <math.h>
#include "point.h"
return result;
}
+Vec vec_sub(Vec v1, Vec v2)
+{
+ Vec result = {
+ .x = v1.x - v2.x,
+ .y = v1.y - v2.y
+ };
+ return result;
+}
+
Vec vec_neg(Vec v)
{
Vec result = {
Vec vec_norm(Vec v)
{
+ // TODO(#657): math/point/vec_norm: using vec_length is too expensive
+ // It involves multiplication and sqrt. We can just check if its components are close to 0.0f.
+
const float l = vec_length(v);
if (l < 1e-6) {
return vec(v.x / l, v.y / l);
}
+
+float vec_sqr_norm(Vec v)
+{
+ return v.x * v.x + v.y * v.y;
+}