1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
#include "cad.h"
void draw_from_constraints(struct constraints *c, struct topology *t, struct canvas *cv) {
struct drawing drawing = {};
struct subassembly assemblies[16] = {};
size_t assemblies_num;
bool rc = solve_constraints(c, &drawing, assemblies, &assemblies_num);
assert(rc);
// Copy over all the parameter values to a new array
// @PERF: Maybe we should just store them in a separate array to start with
double *params = malloc(sizeof(double) * (c->length));
for(size_t i = 0; i < c->length; i++) {
params[i] = c->elements[i].v;
}
place_points(&drawing, params);
free(params);
reconstruct_drawing(c, assemblies, &assemblies_num);
begin_drawing(cv);
draw_topology(cv, t);
draw_constraints(cv, c);
end_drawing(cv);
free_drawing(&drawing);
}
int main(int argc, char *argv[]) {
struct constraints constraints = {};
struct topology topo = {};
struct component mid_bot = {.type = COM_POINT};
struct component pseudo = {.type = COM_POINT};
struct component bot = {.type = COM_LINE};
struct component symmetry = {.type = COM_LINE};
struct component right_lower = {.type = COM_LINE};
struct component left_lower = {.type = COM_LINE};
struct component right_under_hole_mid = {.type = COM_POINT};
struct component right_hole_bot_tan = {.type = COM_LINE};
struct component left_hole_bot_tan = {.type = COM_LINE};
struct component right_hole_top_tan = {.type = COM_LINE};
struct component left_hole_top_tan = {.type = COM_LINE};
struct component right_hole_mid = {.type = COM_POINT};
struct component left_hole_mid = {.type = COM_POINT};
struct component swoop_mid = {.type = COM_POINT};
struct component swoop_top_tan = {.type = COM_POINT};
struct component left_bend = {.type = COM_POINT};
struct component lb2 = {.type = COM_POINT};
struct component l1 = {.type = COM_LINE};
add_constraint(&constraints, (struct constraint[]){
PP_DISTANCE(&mid_bot, &pseudo, 10),
POINT_ON_LINE(&mid_bot, &bot),
POINT_ON_LINE(&pseudo, &bot),
LL_ANGLE(&bot, &symmetry, DEG(90)),
POINT_ON_LINE(&mid_bot, &symmetry),
// @HACK This is going in the wrong direction?
PL_DISTANCE(&mid_bot, &right_lower, 35),
LL_ANGLE(&bot, &right_lower, DEG(-90)),
PL_DISTANCE(&left_lower, &mid_bot, 35),
LL_ANGLE(&bot, &left_lower, DEG(90)),
PL_DISTANCE(&right_hole_mid, &bot, 80),
PL_DISTANCE(&left_hole_mid, &bot, 80),
PL_DISTANCE(&right_hole_mid, &symmetry, -60),
PL_DISTANCE(&left_hole_mid, &symmetry, 60),
PL_DISTANCE(&right_under_hole_mid, &right_lower, 20),
PL_DISTANCE(&right_under_hole_mid, &right_hole_bot_tan, 20),
LL_ANGLE(&right_hole_bot_tan, &symmetry, DEG(270)),
PL_DISTANCE(&right_hole_mid, &right_hole_bot_tan, -28),
// PL_DISTANCE(&left_hole_mid, &left_hole_bot_tan, 56),
PL_DISTANCE(&right_hole_mid, &right_hole_top_tan, 28),
// PL_DISTANCE(&left_hole_mid, &left_hole_top_tan, 56),
POINT_ON_LINE(&swoop_mid, &symmetry),
PP_DISTANCE(&swoop_mid, &right_hole_mid, 120 - 28),
// PL_DISTANCE(&swoop_mid, &swoop_top_tan, 120),
PL_DISTANCE(&swoop_mid, &right_hole_top_tan, 120),
// Make a triangle
CEND(),
});
add_fragment(&topo, (struct topology_elem[]){
TOPO_MOVETO(&mid_bot),
TOPO_LINETO(&right_hole_mid),
TOPO_MOVETO(&mid_bot),
// TOPO_LINETO(&p2),
// TOPO_LINETO(&p3),
TOPO_END(),
});
struct canvas canvas = {
.state = CANVAS_INIT,
.f = stdout,
};
draw_from_constraints(&constraints, &topo, &canvas);
free_constraints(&constraints);
return 0;
}
|