Date:2010-05-30 11:04:26 (9 years 2 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
11/*
22 * coord.c - Coordinate representation and basic operations
33 *
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
66 *
77 * This program is free software; you can redistribute it and/or modify
88 * it under the terms of the GNU General Public License as published by
...... 
1313
1414#include <math.h>
1515
16#include "util.h"
1617#include "coord.h"
1718
1819
...... 
153154/* ----- sorting coordinates ----------------------------------------------- */
154155
155156
156void 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
166157void sort_coord(struct coord *min, struct coord *max)
167158{
168159    if (min->x > max->x)
169        swap_coord(&min->x, &max->x);
160        swap(min->x, max->x);
170161    if (min->y > max->y)
171        swap_coord(&min->y, &max->y);
162        swap(min->y, max->y);
172163
173164}
174165
coord.h
11/*
22 * coord.h - Coordinate representation and basic operations
33 *
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
66 *
77 * This program is free software; you can redistribute it and/or modify
88 * it under the terms of the GNU General Public License as published by
...... 
8787double theta_vec(struct coord v);
8888double theta(struct coord c, struct coord p);
8989
90void swap_coord(unit_type *a, unit_type *b);
9190void sort_coord(struct coord *min, struct coord *max);
9291
9392unit_type dist_point(struct coord a, struct coord b);
gui_meas.c
189189
190190struct pix_buf *draw_move_meas(struct inst *inst, struct coord pos, int i)
191191{
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);
193194}
194195
195196
...... 
349350void begin_drag_move_meas(struct inst *inst, int i)
350351{
351352    const struct meas *meas = &inst->obj->u.meas;
353    struct coord a, b;
352354
353355    switch (meas->type) {
354356    case mt_xy_next:
...... 
367369        abort();
368370    }
369371    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);
370382    switch (i) {
371383    case 0:
372384        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);
374386        break;
375387    case 1:
376388        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);
378390        break;
379391    default:
380392        abort();
gui_util.c
6565    int border)
6666{
6767    struct pix_buf *buf;
68    int tmp;
6968    int w, h;
7069
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);
8174    buf = alloc_type(struct pix_buf);
8275    buf->da = da;
8376    buf->x = xa-border;
kicad.c
3030    struct coord *center, struct coord *size)
3131{
3232    struct coord min, max;
33    unit_type tmp;
3433
3534    min.x = units_to_kicad(a.x);
3635    min.y = units_to_kicad(a.y);
3736    max.x = units_to_kicad(b.x);
3837    max.y = units_to_kicad(b.y);
3938
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);
5040
5141    size->x = max.x-min.x;
5242    size->y = max.y-min.y;
util.h
11/*
22 * util.h - Common utility functions
33 *
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
66 *
77 * This program is free software; you can redistribute it and/or modify
88 * it under the terms of the GNU General Public License as published by
...... 
5151    strnalloc_tmp[n] = 0; \
5252    strnalloc_tmp; })
5353
54#define swap(a, b) \
55    ({ typeof(a) swap_tmp = (a); \
56    (a) = (b); \
57    (b) = swap_tmp; })
58
5459
5560char *stralloc_vprintf(const char *fmt, va_list ap);
5661char *stralloc_printf(const char *fmt, ...)

Archive Download the corresponding diff file

Branches:
master



interactive