diff options
| -rw-r--r-- | src/construction.c | 29 |
1 files changed, 7 insertions, 22 deletions
diff --git a/src/construction.c b/src/construction.c index 6b55c23..2177fba 100644 --- a/src/construction.c +++ b/src/construction.c @@ -105,12 +105,6 @@ static void affine_transform_vec2(mat3 m, vec2 in, vec2 out) { } static void transform_part(struct command *cmd, const struct command *last_cmd, mat3 transform) { - mat3 rotate; - glm_mat3_copy(transform, rotate); - rotate[2][0] = 0.0; - rotate[2][1] = 0.0; - rotate[2][2] = 0.0; - while(cmd != NULL) { switch(cmd->op) { case CMD_VALUE_INPUT: @@ -123,25 +117,16 @@ static void transform_part(struct command *cmd, const struct command *last_cmd, case CMD_LINE_POINT_LINE_ANGLE: case CMD_LINE_CIRCLE_CIRCLE_TANGENT: case CMD_LINE_LINE_DISTANCE_PARALLEL: - // Find a point on the line, what point doesn't matter - // since the whole line is moving struct line *line = &cmd->result.line; - vec2 p; - glm_vec2_zero(p); - - // Point closest to the origin - glm_vec2_scale(line->norm, -line->C / glm_vec2_norm2(line->norm), p); - - // Rotate the line to the new orientation - affine_transform_vec2(rotate, line->norm, line->norm); - - // Transform the fixed point - affine_transform_vec2(transform, p, p); + vec2 n = { + transform[1][1] * line->norm[0] - transform[0][1] * line->norm[1], + -transform[1][0] * line->norm[0] + transform[0][0] * line->norm[1], + }; + float det = transform[0][0] * transform[1][1] - transform[0][1] * transform[1][0]; - // Calculate a C to follow the new point - glm_vec2_negate(p); - line->C = glm_vec2_dot(line->norm, p); + line->C = det * line->C - (n[0] * transform[2][0] + n[1] * transform[2][1]); + glm_vec2_copy(n, line->norm); break; case CMD_CIRCLE_CENTER_RADIUS: case CMD_CIRCLE_CENTER_POINT: |
