1
0
mirror of git://projects.qi-hardware.com/fped.git synced 2024-12-22 23:55:30 +02:00

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
This commit is contained in:
werner 2010-05-30 09:04:26 +00:00
parent c9af8cd0fe
commit 7eb3ac5ba2
6 changed files with 34 additions and 44 deletions

19
coord.c
View File

@ -1,8 +1,8 @@
/*
* coord.c - Coordinate representation and basic operations
*
* Written 2009 by Werner Almesberger
* Copyright 2009 by Werner Almesberger
* Written 2009, 2010 by Werner Almesberger
* Copyright 2009, 2010 by Werner Almesberger
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -13,6 +13,7 @@
#include <math.h>
#include "util.h"
#include "coord.h"
@ -153,22 +154,12 @@ double theta(struct coord c, struct coord p)
/* ----- sorting coordinates ----------------------------------------------- */
void swap_coord(unit_type *a, unit_type *b)
{
unit_type tmp;
tmp = *a;
*a = *b;
*b = tmp;
}
void sort_coord(struct coord *min, struct coord *max)
{
if (min->x > max->x)
swap_coord(&min->x, &max->x);
swap(min->x, max->x);
if (min->y > max->y)
swap_coord(&min->y, &max->y);
swap(min->y, max->y);
}

View File

@ -1,8 +1,8 @@
/*
* coord.h - Coordinate representation and basic operations
*
* Written 2009 by Werner Almesberger
* Copyright 2009 by Werner Almesberger
* Written 2009, 2010 by Werner Almesberger
* Copyright 2009, 2010 by Werner Almesberger
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -87,7 +87,6 @@ struct coord rotate_r(struct coord c, unit_type r, double angle);
double theta_vec(struct coord v);
double theta(struct coord c, struct coord p);
void swap_coord(unit_type *a, unit_type *b);
void sort_coord(struct coord *min, struct coord *max);
unit_type dist_point(struct coord a, struct coord b);

View File

@ -189,7 +189,8 @@ static void meas_highlight_b(void)
struct pix_buf *draw_move_meas(struct inst *inst, struct coord pos, int i)
{
return draw_move_line_common(inst, inst->u.meas.end, pos, i);
return draw_move_line_common(inst, inst->u.meas.end, pos,
inst->obj->u.meas.inverted ? 1-i : i);
}
@ -349,6 +350,7 @@ static struct inst *vec_at(const struct vec *vec, struct coord pos)
void begin_drag_move_meas(struct inst *inst, int i)
{
const struct meas *meas = &inst->obj->u.meas;
struct coord a, b;
switch (meas->type) {
case mt_xy_next:
@ -367,14 +369,24 @@ void begin_drag_move_meas(struct inst *inst, int i)
abort();
}
highlight = meas_highlight_b;
/*
* We're setting up the same conditions as after picking the first
* point when making a new measurement. Thus, we set meas_inst to the
* vector to the endpoint we're not moving.
*/
a = inst->base;
b = inst->u.meas.end;
if (inst->obj->u.meas.inverted)
swap(a, b);
switch (i) {
case 0:
mode = meas->type < 3 ? next_to_min : max_to_min;
meas_inst = vec_at(inst->obj->u.meas.high, inst->u.meas.end);
meas_inst = vec_at(inst->obj->u.meas.high, b);
break;
case 1:
mode = min_to_next_or_max;
meas_inst = vec_at(inst->obj->base, inst->base);
meas_inst = vec_at(inst->obj->base, a);
break;
default:
abort();

View File

@ -65,19 +65,12 @@ struct pix_buf *save_pix_buf(GdkDrawable *da, int xa, int ya, int xb, int yb,
int border)
{
struct pix_buf *buf;
int tmp;
int w, h;
if (xa > xb) {
tmp = xa;
xa = xb;
xb = tmp;
}
if (ya > yb) {
tmp = ya;
ya = yb;
yb = tmp;
}
if (xa > xb)
swap(xa, xb);
if (ya > yb)
swap(ya, yb);
buf = alloc_type(struct pix_buf);
buf->da = da;
buf->x = xa-border;

12
kicad.c
View File

@ -30,23 +30,13 @@ static void kicad_centric(struct coord a, struct coord b,
struct coord *center, struct coord *size)
{
struct coord min, max;
unit_type tmp;
min.x = units_to_kicad(a.x);
min.y = units_to_kicad(a.y);
max.x = units_to_kicad(b.x);
max.y = units_to_kicad(b.y);
if (min.x > max.x) {
tmp = min.x;
min.x = max.x;
max.x = tmp;
}
if (min.y > max.y) {
tmp = min.y;
min.y = max.y;
max.y = tmp;
}
sort_coord(&min, &max);
size->x = max.x-min.x;
size->y = max.y-min.y;

9
util.h
View File

@ -1,8 +1,8 @@
/*
* util.h - Common utility functions
*
* Written 2006, 2009 by Werner Almesberger
* Copyright 2006, 2009 Werner Almesberger
* Written 2006, 2009, 2010 by Werner Almesberger
* Copyright 2006, 2009, 2010 Werner Almesberger
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -51,6 +51,11 @@
strnalloc_tmp[n] = 0; \
strnalloc_tmp; })
#define swap(a, b) \
({ typeof(a) swap_tmp = (a); \
(a) = (b); \
(b) = swap_tmp; })
char *stralloc_vprintf(const char *fmt, va_list ap);
char *stralloc_printf(const char *fmt, ...)