Date: | 2010-05-30 11:04:26 (9 years 6 months ago) |
---|---|
Author: | werner |
Commit: | 7eb3ac5ba29269662534a6b30b88e2b56996f05d |
Message: | When dragging an endpoint of an inverted measurement, we didn't
consider that inst->base and inst->u.meas.end are swapped,
causing fped to crash in vec_at. Also introduced a universal swap()
function. - util.h (swap): new swap function for arguments of any type - gui_meas.c (begin_drag_move_meas, draw_move_meas): swap the endpoints if moving an inverted measurement - coord.c (sort_coord): use swap() instead of swap_coord - coord.h, coord.c (swap_coord): removed - gui_util.c (save_pix_buf): use swap() instead of open-coding the swap - kicad.c (kicad_centric): use sort_coord instead of "manually" sorting the coordinates git-svn-id: http://svn.openmoko.org/trunk/eda/fped@5968 99fdad57-331a-0410-800a-d7fa5415bdb3 |
Files: |
coord.c (3 diffs) coord.h (2 diffs) gui_meas.c (3 diffs) gui_util.c (1 diff) kicad.c (1 diff) util.h (2 diffs) |
Change Details
coord.c | ||
---|---|---|
1 | 1 | /* |
2 | 2 | * coord.c - Coordinate representation and basic operations |
3 | 3 | * |
4 | * Written 2009 by Werner Almesberger | |
5 | * Copyright 2009 by Werner Almesberger | |
4 | * Written 2009, 2010 by Werner Almesberger | |
5 | * Copyright 2009, 2010 by Werner Almesberger | |
6 | 6 | * |
7 | 7 | * This program is free software; you can redistribute it and/or modify |
8 | 8 | * it under the terms of the GNU General Public License as published by |
... | ... | |
13 | 13 | |
14 | 14 | #include <math.h> |
15 | 15 | |
16 | #include "util.h" | |
16 | 17 | #include "coord.h" |
17 | 18 | |
18 | 19 | |
... | ... | |
153 | 154 | /* ----- sorting coordinates ----------------------------------------------- */ |
154 | 155 | |
155 | 156 | |
156 | void swap_coord(unit_type *a, unit_type *b) | |
157 | { | |
158 | unit_type tmp; | |
159 | ||
160 | tmp = *a; | |
161 | *a = *b; | |
162 | *b = tmp; | |
163 | } | |
164 | ||
165 | ||
166 | 157 | void sort_coord(struct coord *min, struct coord *max) |
167 | 158 | { |
168 | 159 | if (min->x > max->x) |
169 | swap_coord(&min->x, &max->x); | |
160 | swap(min->x, max->x); | |
170 | 161 | if (min->y > max->y) |
171 | swap_coord(&min->y, &max->y); | |
162 | swap(min->y, max->y); | |
172 | 163 | |
173 | 164 | } |
174 | 165 |
coord.h | ||
---|---|---|
1 | 1 | /* |
2 | 2 | * coord.h - Coordinate representation and basic operations |
3 | 3 | * |
4 | * Written 2009 by Werner Almesberger | |
5 | * Copyright 2009 by Werner Almesberger | |
4 | * Written 2009, 2010 by Werner Almesberger | |
5 | * Copyright 2009, 2010 by Werner Almesberger | |
6 | 6 | * |
7 | 7 | * This program is free software; you can redistribute it and/or modify |
8 | 8 | * it under the terms of the GNU General Public License as published by |
... | ... | |
87 | 87 | double theta_vec(struct coord v); |
88 | 88 | double theta(struct coord c, struct coord p); |
89 | 89 | |
90 | void swap_coord(unit_type *a, unit_type *b); | |
91 | 90 | void sort_coord(struct coord *min, struct coord *max); |
92 | 91 | |
93 | 92 | unit_type dist_point(struct coord a, struct coord b); |
gui_meas.c | ||
---|---|---|
189 | 189 | |
190 | 190 | struct pix_buf *draw_move_meas(struct inst *inst, struct coord pos, int i) |
191 | 191 | { |
192 | return draw_move_line_common(inst, inst->u.meas.end, pos, i); | |
192 | return draw_move_line_common(inst, inst->u.meas.end, pos, | |
193 | inst->obj->u.meas.inverted ? 1-i : i); | |
193 | 194 | } |
194 | 195 | |
195 | 196 | |
... | ... | |
349 | 350 | void begin_drag_move_meas(struct inst *inst, int i) |
350 | 351 | { |
351 | 352 | const struct meas *meas = &inst->obj->u.meas; |
353 | struct coord a, b; | |
352 | 354 | |
353 | 355 | switch (meas->type) { |
354 | 356 | case mt_xy_next: |
... | ... | |
367 | 369 | abort(); |
368 | 370 | } |
369 | 371 | highlight = meas_highlight_b; |
372 | ||
373 | /* | |
374 | * We're setting up the same conditions as after picking the first | |
375 | * point when making a new measurement. Thus, we set meas_inst to the | |
376 | * vector to the endpoint we're not moving. | |
377 | */ | |
378 | a = inst->base; | |
379 | b = inst->u.meas.end; | |
380 | if (inst->obj->u.meas.inverted) | |
381 | swap(a, b); | |
370 | 382 | switch (i) { |
371 | 383 | case 0: |
372 | 384 | mode = meas->type < 3 ? next_to_min : max_to_min; |
373 | meas_inst = vec_at(inst->obj->u.meas.high, inst->u.meas.end); | |
385 | meas_inst = vec_at(inst->obj->u.meas.high, b); | |
374 | 386 | break; |
375 | 387 | case 1: |
376 | 388 | mode = min_to_next_or_max; |
377 | meas_inst = vec_at(inst->obj->base, inst->base); | |
389 | meas_inst = vec_at(inst->obj->base, a); | |
378 | 390 | break; |
379 | 391 | default: |
380 | 392 | abort(); |
gui_util.c | ||
---|---|---|
65 | 65 | int border) |
66 | 66 | { |
67 | 67 | struct pix_buf *buf; |
68 | int tmp; | |
69 | 68 | int w, h; |
70 | 69 | |
71 | if (xa > xb) { | |
72 | tmp = xa; | |
73 | xa = xb; | |
74 | xb = tmp; | |
75 | } | |
76 | if (ya > yb) { | |
77 | tmp = ya; | |
78 | ya = yb; | |
79 | yb = tmp; | |
80 | } | |
70 | if (xa > xb) | |
71 | swap(xa, xb); | |
72 | if (ya > yb) | |
73 | swap(ya, yb); | |
81 | 74 | buf = alloc_type(struct pix_buf); |
82 | 75 | buf->da = da; |
83 | 76 | buf->x = xa-border; |
kicad.c | ||
---|---|---|
30 | 30 | struct coord *center, struct coord *size) |
31 | 31 | { |
32 | 32 | struct coord min, max; |
33 | unit_type tmp; | |
34 | 33 | |
35 | 34 | min.x = units_to_kicad(a.x); |
36 | 35 | min.y = units_to_kicad(a.y); |
37 | 36 | max.x = units_to_kicad(b.x); |
38 | 37 | max.y = units_to_kicad(b.y); |
39 | 38 | |
40 | if (min.x > max.x) { | |
41 | tmp = min.x; | |
42 | min.x = max.x; | |
43 | max.x = tmp; | |
44 | } | |
45 | if (min.y > max.y) { | |
46 | tmp = min.y; | |
47 | min.y = max.y; | |
48 | max.y = tmp; | |
49 | } | |
39 | sort_coord(&min, &max); | |
50 | 40 | |
51 | 41 | size->x = max.x-min.x; |
52 | 42 | size->y = max.y-min.y; |
util.h | ||
---|---|---|
1 | 1 | /* |
2 | 2 | * util.h - Common utility functions |
3 | 3 | * |
4 | * Written 2006, 2009 by Werner Almesberger | |
5 | * Copyright 2006, 2009 Werner Almesberger | |
4 | * Written 2006, 2009, 2010 by Werner Almesberger | |
5 | * Copyright 2006, 2009, 2010 Werner Almesberger | |
6 | 6 | * |
7 | 7 | * This program is free software; you can redistribute it and/or modify |
8 | 8 | * it under the terms of the GNU General Public License as published by |
... | ... | |
51 | 51 | strnalloc_tmp[n] = 0; \ |
52 | 52 | strnalloc_tmp; }) |
53 | 53 | |
54 | #define swap(a, b) \ | |
55 | ({ typeof(a) swap_tmp = (a); \ | |
56 | (a) = (b); \ | |
57 | (b) = swap_tmp; }) | |
58 | ||
54 | 59 | |
55 | 60 | char *stralloc_vprintf(const char *fmt, va_list ap); |
56 | 61 | char *stralloc_printf(const char *fmt, ...) |
Branches:
master