summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJesper Jensen <jesper@jnsn.dev>2026-03-29 12:07:19 +0200
committerJesper Jensen <jesper@jnsn.dev>2026-03-29 12:07:19 +0200
commite49c0ac340da53f3460a2aa02b514340ab0866e0 (patch)
treef96fd5ec9fb085e0f4a55554bebcd8e5fc7e626c /src
parent770216abb4bde565f824eb9010ae641ae118bb2d (diff)
Start testing as a cad tool
Diffstat (limited to 'src')
-rw-r--r--src/solve.c18
-rw-r--r--src/svg.c2
2 files changed, 10 insertions, 10 deletions
diff --git a/src/solve.c b/src/solve.c
index 5b3cdce..66cbb7f 100644
--- a/src/solve.c
+++ b/src/solve.c
@@ -810,8 +810,8 @@ constraint_matches_j:
// Here we have two assemblies, one fixed and the other not,
// that share a single point and each one other point that
- // share a constraint. We can hopefully place the rest of the
- // assembly from that information
+ // share a constraint. Try place the rigid body based on that
+ // information
float theta = atan2(constraint->c1->e->line.norm[1], constraint->c1->e->line.norm[0]) - atan2(constraint->c2->e->line.norm[1], constraint->c2->e->line.norm[0]);
theta = forward ? -theta : theta;
@@ -865,22 +865,22 @@ constraint_matches_j:
// Find a point on the line, what point doesn't matter
// since the whole line is moving
struct line line = c->e->line;
- double a = line.norm[0];
- double b = line.norm[1];
- double rec = pow(a, 2) + pow(b, 2);
- double x0 = -a*line.C / rec;
- double y0 = -b*line.C / rec;
- vec2 p = {x0, y0};
+ vec2 p;
+ glm_vec2_zero(p);
+
+ glm_vec2_muladds(line.norm, line.C, p);
+ double rec = glm_vec2_norm2(line.norm);
+ glm_vec2_divs(p, rec, p);
// Rotate the line to the new orientation
glm_vec2_rotate(line.norm, theta, line.norm);
// Transform the fixed point
affine_transform_vec2(transform, p, p);
- glm_vec2_negate(p);
// Calculate a C to follow the new point
+ glm_vec2_negate(p);
line.C = glm_vec2_dot(line.norm, p);
c->e->line = line;
diff --git a/src/svg.c b/src/svg.c
index 7480e4f..a59f57b 100644
--- a/src/svg.c
+++ b/src/svg.c
@@ -369,7 +369,7 @@ void begin_drawing(struct canvas *canvas) {
assert(canvas->f != NULL);
assert(canvas->state == CANVAS_INIT);
- fprintf(canvas->f, "<svg version=\"1.1\" viewBox=\"-50 -50 100 100\" width=\"1200\" height=\"1200\" xmlns=\"http://www.w3.org/2000/svg\">\n");
+ fprintf(canvas->f, "<svg version=\"1.1\" viewBox=\"-100 -100 200 200\" width=\"1200\" height=\"1200\" xmlns=\"http://www.w3.org/2000/svg\">\n");
fprintf(canvas->f, "<defs>\n");
fprintf(canvas->f, "\t<marker id=\"triangle\" viewBox=\"0 0 10 10\" refX=\"10\" refY=\"5\" markerUnits=\"strokeWidth\" markerWidth=\"6\" markerHeight=\"6\" orient=\"auto-start-reverse\">\n");
fprintf(canvas->f, "\t\t<path d=\"M 0 0 L 10 5 L 0 10 z\" fill=\"blue\" opacity=\"0.3\" />\n");