r5968 - trunk/eda/fped
werner at docs.openmoko.org
werner at docs.openmoko.org
Sun May 30 11:04:26 CEST 2010
Author: werner
Date: 2010-05-30 11:04:26 +0200 (Sun, 30 May 2010)
New Revision: 5968
Modified:
trunk/eda/fped/coord.c
trunk/eda/fped/coord.h
trunk/eda/fped/gui_meas.c
trunk/eda/fped/gui_util.c
trunk/eda/fped/kicad.c
trunk/eda/fped/util.h
Log:
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
Modified: trunk/eda/fped/coord.c
===================================================================
--- trunk/eda/fped/coord.c 2010-05-29 21:13:48 UTC (rev 5967)
+++ trunk/eda/fped/coord.c 2010-05-30 09:04:26 UTC (rev 5968)
@@ -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 @@
/* ----- 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);
}
Modified: trunk/eda/fped/coord.h
===================================================================
--- trunk/eda/fped/coord.h 2010-05-29 21:13:48 UTC (rev 5967)
+++ trunk/eda/fped/coord.h 2010-05-30 09:04:26 UTC (rev 5968)
@@ -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 @@
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);
Modified: trunk/eda/fped/gui_meas.c
===================================================================
--- trunk/eda/fped/gui_meas.c 2010-05-29 21:13:48 UTC (rev 5967)
+++ trunk/eda/fped/gui_meas.c 2010-05-30 09:04:26 UTC (rev 5968)
@@ -189,7 +189,8 @@
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 @@
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 @@
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();
Modified: trunk/eda/fped/gui_util.c
===================================================================
--- trunk/eda/fped/gui_util.c 2010-05-29 21:13:48 UTC (rev 5967)
+++ trunk/eda/fped/gui_util.c 2010-05-30 09:04:26 UTC (rev 5968)
@@ -65,19 +65,12 @@
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;
Modified: trunk/eda/fped/kicad.c
===================================================================
--- trunk/eda/fped/kicad.c 2010-05-29 21:13:48 UTC (rev 5967)
+++ trunk/eda/fped/kicad.c 2010-05-30 09:04:26 UTC (rev 5968)
@@ -30,23 +30,13 @@
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;
Modified: trunk/eda/fped/util.h
===================================================================
--- trunk/eda/fped/util.h 2010-05-29 21:13:48 UTC (rev 5967)
+++ trunk/eda/fped/util.h 2010-05-30 09:04:26 UTC (rev 5968)
@@ -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,7 +51,12 @@
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, ...)
__attribute__((format(printf, 1, 2)));
More information about the commitlog
mailing list