[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

gEDA-cvs: gaf.git: branch: master updated (1.5.0-20080706-385-g1a38d36)



The branch, master has been updated
       via  1a38d368b89110372d311ddcd22a515b88d87ca0 (commit)
       via  abb681ddca37e729c3f17c48ca6d8d46e2f3dd2b (commit)
      from  822d04bc29291979b91dd3222a27bbcb295e7b56 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.


=========
 Summary
=========

 libgeda/include/prototype.h      |    2 +-
 libgeda/include/prototype_priv.h |   16 ++++----
 libgeda/src/o_arc_basic.c        |   66 +++++++++++++++++-------------------
 libgeda/src/o_basic.c            |   69 ++++++++++++-------------------------
 libgeda/src/o_box_basic.c        |   60 ++++++++++++++-------------------
 libgeda/src/o_circle_basic.c     |   30 +++++++---------
 libgeda/src/o_complex_basic.c    |   20 +++++------
 libgeda/src/o_line_basic.c       |   45 +++++++++---------------
 libgeda/src/o_path_basic.c       |   18 +++++-----
 libgeda/src/o_picture.c          |   42 +++++++++--------------
 libgeda/src/o_text_basic.c       |   39 +++++++++++++--------
 11 files changed, 176 insertions(+), 231 deletions(-)


=================
 Commit Messages
=================

commit 1a38d368b89110372d311ddcd22a515b88d87ca0
Author: Peter Clifton <pcjc2@xxxxxxxxx>
Date:   Wed Dec 17 01:09:05 2008 +0000

    libgeda: Select text using the OBJECT's bounding box, not prim_objs
    
    Makes selection of text objects much easier, and will be needed when
    we use an external text rendering API rather than our own internal font.

:100644 100644 a95d5d9... c6b1395... M	libgeda/src/o_text_basic.c

commit abb681ddca37e729c3f17c48ca6d8d46e2f3dd2b
Author: Peter Clifton <pcjc2@xxxxxxxxx>
Date:   Wed Dec 17 00:29:41 2008 +0000

    libgeda: Clean up o_*_shortest_distance() functions
    
    Make all functions take an OBJECT * as their first argument, rather
    than a BOX, CIRCLE etc.. This keeps the function signature uniform
    and allows the routines full access to the whole OBJECT state.
    
    Also use g_return_val_if_fail() as elsewhere in the code. Favour
    primitive types such as double and int, rather than gdouble and gint
    to be consistent with the majority of the gEDA codebase.

:100644 100644 092e87f... 05672d6... M	libgeda/include/prototype.h
:100644 100644 9dd3bf7... 7807cef... M	libgeda/include/prototype_priv.h
:100644 100644 18a0ead... 0800e02... M	libgeda/src/o_arc_basic.c
:100644 100644 973a822... c7c88c8... M	libgeda/src/o_basic.c
:100644 100644 0851a2a... 48236a5... M	libgeda/src/o_box_basic.c
:100644 100644 53d5e6b... ceeaa92... M	libgeda/src/o_circle_basic.c
:100644 100644 09e6bc1... 37f580e... M	libgeda/src/o_complex_basic.c
:100644 100644 afcf684... 6abd97e... M	libgeda/src/o_line_basic.c
:100644 100644 d592e8e... 172da4f... M	libgeda/src/o_path_basic.c
:100644 100644 adeac52... aa15b46... M	libgeda/src/o_picture.c
:100644 100644 2d771b4... a95d5d9... M	libgeda/src/o_text_basic.c

=========
 Changes
=========

commit 1a38d368b89110372d311ddcd22a515b88d87ca0
Author: Peter Clifton <pcjc2@xxxxxxxxx>
Date:   Wed Dec 17 01:09:05 2008 +0000

    libgeda: Select text using the OBJECT's bounding box, not prim_objs
    
    Makes selection of text objects much easier, and will be needed when
    we use an external text rendering API rather than our own internal font.

diff --git a/libgeda/src/o_text_basic.c b/libgeda/src/o_text_basic.c
index a95d5d9..c6b1395 100644
--- a/libgeda/src/o_text_basic.c
+++ b/libgeda/src/o_text_basic.c
@@ -1812,18 +1812,29 @@ void o_text_mirror_world(TOPLEVEL *toplevel,
  */
 double o_text_shortest_distance (OBJECT *object, int x, int y)
 {
-  double shortest_distance = G_MAXDOUBLE;
-  double distance;
-  GList *iter;
+  double shortest_distance;
+  double dx, dy;
 
   g_return_val_if_fail (object->text != NULL, G_MAXDOUBLE);
 
-  for (iter = object->text->prim_objs;
-       iter != NULL; iter = g_list_next (iter)) {
-    OBJECT *obj = iter->data;
+  dx = min (x - object->w_left, object->w_right - x);
+  dy = min (y - object->w_top, object->w_bottom - y);
+
+  dx = min (dx, 0);
+  dy = min (dy, 0);
 
-    distance = o_shortest_distance (obj, x, y);
-    shortest_distance = min (shortest_distance, distance);
+  if (dx < 0) {
+    if (dy < 0) {
+      shortest_distance = sqrt ((dx * dx) + (dy * dy));
+    } else {
+      shortest_distance = fabs (dx);
+    }
+  } else {
+    if (dy < 0) {
+      shortest_distance = fabs (dy);
+    } else {
+      shortest_distance = min (dx, dy);
+    }
   }
 
   return shortest_distance;

commit abb681ddca37e729c3f17c48ca6d8d46e2f3dd2b
Author: Peter Clifton <pcjc2@xxxxxxxxx>
Date:   Wed Dec 17 00:29:41 2008 +0000

    libgeda: Clean up o_*_shortest_distance() functions
    
    Make all functions take an OBJECT * as their first argument, rather
    than a BOX, CIRCLE etc.. This keeps the function signature uniform
    and allows the routines full access to the whole OBJECT state.
    
    Also use g_return_val_if_fail() as elsewhere in the code. Favour
    primitive types such as double and int, rather than gdouble and gint
    to be consistent with the majority of the gEDA codebase.

diff --git a/libgeda/include/prototype.h b/libgeda/include/prototype.h
index 092e87f..05672d6 100644
--- a/libgeda/include/prototype.h
+++ b/libgeda/include/prototype.h
@@ -147,7 +147,7 @@ void o_set_fill_options(TOPLEVEL *toplevel, OBJECT *o_current, OBJECT_FILLING ty
 void o_translate_world (TOPLEVEL *toplevel, gint dx, gint dy, OBJECT *object);
 void o_rotate_world(TOPLEVEL *toplevel, int world_centerx, int world_centery, int angle, OBJECT *object);
 void o_mirror_world(TOPLEVEL *toplevel, int world_centerx, int world_centery, OBJECT *object);
-gdouble o_shortest_distance(OBJECT *object, gint x, gint y);
+double o_shortest_distance(OBJECT *object, int x, int y);
 
 /* o_box_basic.c */
 OBJECT *o_box_new(TOPLEVEL *toplevel, char type, int color, int x1, int y1, int x2, int y2);
diff --git a/libgeda/include/prototype_priv.h b/libgeda/include/prototype_priv.h
index 9dd3bf7..7807cef 100644
--- a/libgeda/include/prototype_priv.h
+++ b/libgeda/include/prototype_priv.h
@@ -83,7 +83,7 @@ void o_arc_print_dotted(TOPLEVEL *toplevel, FILE *fp, int x, int y, int radius,
 void o_arc_print_dashed(TOPLEVEL *toplevel, FILE *fp, int x, int y, int radius, int angle1, int angle2, int color, int arc_width, int length, int space, int origin_x, int origin_y);
 void o_arc_print_center(TOPLEVEL *toplevel, FILE *fp, int x, int y, int radius, int angle1, int angle2, int color, int arc_width, int length, int space, int origin_x, int origin_y);
 void o_arc_print_phantom(TOPLEVEL *toplevel, FILE *fp, int x, int y, int radius, int angle1, int angle2, int color, int arc_width, int length, int space, int origin_x, int origin_y);
-gdouble o_arc_shortest_distance(ARC *arc, gint x, gint y);
+double o_arc_shortest_distance(OBJECT *object, int x, int y);
 gboolean o_arc_within_sweep(ARC *arc, gint x, gint y);
 void world_get_arc_bounds(TOPLEVEL *toplevel, OBJECT *object, int *left, int *top, int *right, int *bottom);
 void o_arc_recalc(TOPLEVEL *toplevel, OBJECT *o_current);
@@ -111,7 +111,7 @@ void o_box_print_phantom(TOPLEVEL *toplevel, FILE *fp, int x, int y, int width,
 void o_box_print_filled(TOPLEVEL *toplevel, FILE *fp, int x, int y, int width, int height, int color, int fill_width, int angle1, int pitch1, int angle2, int pitch2, int origin_x, int origin_y);
 void o_box_print_mesh(TOPLEVEL *toplevel, FILE *fp, int x, int y, int width, int height, int color, int fill_width, int angle1, int pitch1, int angle2, int pitch2, int origin_x, int origin_y);
 void o_box_print_hatch(TOPLEVEL *toplevel, FILE *fp, int x, int y, int width, int height, int color, int fill_width, int angle1, int pitch1, int angle2, int pitch2, int origin_x, int origin_y);
-gdouble o_box_shortest_distance(BOX *box, gint x, gint y);
+double o_box_shortest_distance(OBJECT *object, int x, int y);
 void world_get_box_bounds(TOPLEVEL *toplevel, OBJECT *object, int *left, int *top, int *right, int *bottom);
 void o_box_recalc(TOPLEVEL *toplevel, OBJECT *o_current);
 
@@ -134,14 +134,14 @@ void o_circle_print_phantom(TOPLEVEL *toplevel, FILE *fp, int x, int y, int radi
 void o_circle_print_filled(TOPLEVEL *toplevel, FILE *fp, int x, int y, int radius, int color, int fill_width, int angle1, int pitch1, int angle2, int pitch2, int origin_x, int origin_y);
 void o_circle_print_mesh(TOPLEVEL *toplevel, FILE *fp, int x, int y, int radius, int color, int fill_width, int angle1, int pitch1, int angle2, int pitch2, int origin_x, int origin_y);
 void o_circle_print_hatch(TOPLEVEL *toplevel, FILE *fp, int x, int y, int radius, int color, int fill_width, int angle1, int pitch1, int angle2, int pitch2, int origin_x, int origin_y);
-gdouble o_circle_shortest_distance(CIRCLE *circle, gint x, gint y);
+double o_circle_shortest_distance(OBJECT *object, int x, int y);
 void world_get_circle_bounds(TOPLEVEL *toplevel, OBJECT *object, int *left, int *top, int *right, int *bottom);
 void o_circle_recalc(TOPLEVEL *toplevel, OBJECT *o_current);
 
 /* o_complex_basic.c */
 OBJECT *o_complex_read(TOPLEVEL *toplevel, char buf[], unsigned int release_ver, unsigned int fileformat_ver);
 char *o_complex_save(OBJECT *object);
-gdouble o_complex_shortest_distance(COMPLEX *complex, gint x, gint y);
+double o_complex_shortest_distance(OBJECT *object, int x, int y);
 void world_get_complex_bounds(TOPLEVEL *toplevel, OBJECT *complex, int *left, int *top, int *right, int *bottom);
 void o_complex_recalc(TOPLEVEL *toplevel, OBJECT *o_current);
 
@@ -154,7 +154,7 @@ void o_line_print_dotted(TOPLEVEL *toplevel, FILE *fp, int x1, int y1, int x2, i
 void o_line_print_dashed(TOPLEVEL *toplevel, FILE *fp, int x1, int y1, int x2, int y2, int color, int line_width, int length, int space, int origin_x, int origin_y);
 void o_line_print_center(TOPLEVEL *toplevel, FILE *fp, int x1, int y1, int x2, int y2, int color, int line_width, int length, int space, int origin_x, int origin_y);
 void o_line_print_phantom(TOPLEVEL *toplevel, FILE *fp, int x1, int y1, int x2, int y2, int color, int line_width, int length, int space, int origin_x, int origin_y);
-gdouble o_line_shortest_distance(LINE *line, gint x, gint y);
+double o_line_shortest_distance(OBJECT *object, int x, int y);
 void world_get_line_bounds(TOPLEVEL *toplevel, OBJECT *object, int *left, int *top, int *right, int *bottom);
 void o_line_recalc(TOPLEVEL *toplevel, OBJECT *o_current);
 
@@ -169,7 +169,7 @@ void o_net_recalc(TOPLEVEL *toplevel, OBJECT *o_current);
 OBJECT *o_path_read(TOPLEVEL *toplevel, const char *first_line, TextBuffer *tb, unsigned int release_ver, unsigned int fileformat_ver);
 char *o_path_save(OBJECT *object);
 void o_path_print(TOPLEVEL *toplevel, FILE *fp, OBJECT *o_current, int origin_x, int origin_y);
-gdouble o_path_shortest_distance(OBJECT *object, gint x, gint y);
+double o_path_shortest_distance(OBJECT *object, int x, int y);
 void world_get_path_bounds(TOPLEVEL *toplevel, OBJECT *object, int *left, int *top, int *right, int *bottom);
 void o_path_recalc(TOPLEVEL *toplevel, OBJECT *o_current);
 
@@ -179,7 +179,7 @@ OBJECT *o_picture_read(TOPLEVEL *toplevel, const char *first_line, TextBuffer *t
 char *o_picture_save(OBJECT *object);
 void o_picture_print(TOPLEVEL *toplevel, FILE *fp, OBJECT *o_current,
 		     int origin_x, int origin_y);
-gdouble o_picture_shortest_distance(PICTURE *picture, gint x, gint y);
+double o_picture_shortest_distance(OBJECT *object, int x, int y);
 void world_get_picture_bounds(TOPLEVEL *toplevel, OBJECT *object, int *left, int *top, int *right, int *bottom);
 void o_picture_recalc(TOPLEVEL *toplevel, OBJECT *o_current);
 
@@ -195,7 +195,7 @@ OBJECT *o_text_read(TOPLEVEL *toplevel, const char *first_line, TextBuffer *tb,
 char *o_text_save(OBJECT *object);
 void o_text_print_text_string(FILE *fp, char *string, int unicode_count, gunichar *unicode_table);
 void o_text_print(TOPLEVEL *toplevel, FILE *fp, OBJECT *o_current, int origin_x, int origin_y, int unicode_count, gunichar *unicode_table);
-gdouble o_text_shortest_distance(TEXT *text, gint x, gint y);
+double o_text_shortest_distance(OBJECT *object, int x, int y);
 int world_get_text_bounds(TOPLEVEL *toplevel, OBJECT *o_current, int *left, int *top, int *right, int *bottom);
 void o_text_recalc(TOPLEVEL *toplevel, OBJECT *o_current);
 
diff --git a/libgeda/src/o_arc_basic.c b/libgeda/src/o_arc_basic.c
index 18a0ead..0800e02 100644
--- a/libgeda/src/o_arc_basic.c
+++ b/libgeda/src/o_arc_basic.c
@@ -1234,58 +1234,54 @@ void o_arc_print_phantom(TOPLEVEL *toplevel, FILE *fp,
 /*! \brief Calculates the distance between the given point and the closest
  * point on the perimeter of the arc.
  *
- *  \param [in] arc the arc of the OBJECT
- *  \param [in] x The x coordinate of the given point.
- *  \param [in] y The y coordinate of the given point.
+ *  \param [in] object  The arc OBJECT.
+ *  \param [in] x       The x coordinate of the given point.
+ *  \param [in] y       The y coordinate of the given point.
  *  \return The shortest distance from the object to the point. With an
  *  invalid parameter, this function returns G_MAXDOUBLE.
  */
-gdouble o_arc_shortest_distance(ARC *arc, gint x, gint y)
+double o_arc_shortest_distance (OBJECT *object, int x, int y)
 {
-  gdouble radius;
-  gdouble shortest_distance;
+  double shortest_distance;
+  double radius;
 
-  if (arc == NULL) {
-    g_critical("o_arc_shortest_distance(): arc == NULL\n");
-    return G_MAXDOUBLE;
-  }
+  g_return_val_if_fail (object->arc != NULL, G_MAXDOUBLE);
 
-  radius = ((gdouble) arc->width) / 2.0;
+  radius = ((double)object->arc->width) / 2.0;
 
-  if ( o_arc_within_sweep(arc, x, y) ) {
-    gdouble distance_to_center;
-    gdouble dx;
-    gdouble dy;
+  if (o_arc_within_sweep (object->arc, x, y)) {
+    double distance_to_center;
+    double dx;
+    double dy;
 
-    dx = ((gdouble) x) - ((gdouble) arc->x);
-    dy = ((gdouble) y) - ((gdouble) arc->y);
+    dx = ((double)x) - ((double)object->arc->x);
+    dy = ((double)y) - ((double)object->arc->y);
 
-    distance_to_center = sqrt((dx*dx) + (dy*dy));
+    distance_to_center = sqrt ((dx * dx) + (dy * dy));
 
-    shortest_distance = fabs(distance_to_center - radius);
-  }
-  else {
-    gdouble angle;
-    gdouble distance_to_end0;
-    gdouble distance_to_end1;
-    gdouble dx;
-    gdouble dy;
+    shortest_distance = fabs (distance_to_center - radius);
+
+  } else {
+    double angle;
+    double distance_to_end0;
+    double distance_to_end1;
+    double dx, dy;
 
-    angle = G_PI * ((gdouble) arc->start_angle ) / 180;
+    angle = G_PI * ((double)object->arc->start_angle) / 180;
 
-    dx = ((gdouble) x) - radius*cos(angle) - ((gdouble) arc->x);
-    dy = ((gdouble) y) - radius*sin(angle) - ((gdouble) arc->y);
+    dx = ((double)x) - radius * cos (angle) - ((double)object->arc->x);
+    dy = ((double)y) - radius * sin (angle) - ((double)object->arc->y);
 
-    distance_to_end0 = sqrt((dx*dx) + (dy*dy));
+    distance_to_end0 = sqrt ((dx * dx) + (dy * dy));
 
-    angle += G_PI * ((gdouble) arc->end_angle ) / 180;
+    angle += G_PI * ((double)object->arc->end_angle) / 180;
 
-    dx = ((gdouble) x) - radius*cos(angle) - ((gdouble) arc->x);
-    dy = ((gdouble) y) - radius*sin(angle) - ((gdouble) arc->y);
+    dx = ((double)x) - radius * cos (angle) - ((double)object->arc->x);
+    dy = ((double)y) - radius * sin (angle) - ((double)object->arc->y);
 
-    distance_to_end1 = sqrt((dx*dx) + (dy*dy));
+    distance_to_end1 = sqrt ((dx * dx) + (dy * dy));
 
-    shortest_distance = min(distance_to_end0, distance_to_end1);
+    shortest_distance = min (distance_to_end0, distance_to_end1);
   }
 
   return shortest_distance;
diff --git a/libgeda/src/o_basic.c b/libgeda/src/o_basic.c
index 973a822..c7c88c8 100644
--- a/libgeda/src/o_basic.c
+++ b/libgeda/src/o_basic.c
@@ -377,65 +377,42 @@ void o_mirror_world (TOPLEVEL *toplevel, int world_centerx, int world_centery, O
  * point on the given object.
  *
  *  \param [in] object The given object.
- *  \param [in] x The x coordinate of the given point.
- *  \param [in] y The y coordinate of the given point.
+ *  \param [in] x      The x coordinate of the given point.
+ *  \param [in] y      The y coordinate of the given point.
  *  \return The shortest distance from the object to the point. If the
  *  distance cannot be calculated, this function returns a really large
  *  number (G_MAXDOUBLE).  If an error occurs, this function returns
  *  G_MAXDOUBLE.
  */
-gdouble o_shortest_distance(OBJECT *object, gint x, gint y)
+double o_shortest_distance (OBJECT *object, int x, int y)
 {
-  gdouble shortest_distance = G_MAXDOUBLE;
-
-  if (object == NULL) {
-    g_critical("o_shortest_distance(): object == NULL\n");
-    return G_MAXDOUBLE;
-  }
+  double shortest_distance = G_MAXDOUBLE;
+  double (*func) (OBJECT *, int, int) = NULL;
 
+  g_return_val_if_fail (object != NULL, G_MAXDOUBLE);
 
   switch(object->type) {
-
-    case(OBJ_ARC):
-      shortest_distance = o_arc_shortest_distance(object->arc, x, y);
-      break;
-
-    case(OBJ_BOX):
-      shortest_distance = o_box_shortest_distance(object->box, x, y);
-      break;
-
-    case(OBJ_BUS):
-    case(OBJ_LINE):
-    case(OBJ_NET):
-    case(OBJ_PIN):
-      shortest_distance = o_line_shortest_distance(object->line, x, y);
-      break;
-
-    case(OBJ_CIRCLE):
-      shortest_distance = o_circle_shortest_distance(object->circle, x, y);
-      break;
-
-    case(OBJ_COMPLEX):
-    case(OBJ_PLACEHOLDER):
-      shortest_distance = o_complex_shortest_distance(object->complex, x, y);
-      break;
-
-    case(OBJ_PATH):
-      shortest_distance = o_path_shortest_distance(object, x, y);
-      break;
-
-    case(OBJ_PICTURE):
-      shortest_distance = o_picture_shortest_distance(object->picture, x, y);
-      break;
-
-    case(OBJ_TEXT):
-      shortest_distance = o_text_shortest_distance(object->text, x, y);
-      break;
-
+    case OBJ_BUS:
+    case OBJ_NET:
+    case OBJ_PIN:
+    case OBJ_LINE:        func = o_line_shortest_distance;     break;
+    case OBJ_BOX:         func = o_box_shortest_distance;      break;
+    case OBJ_PICTURE:     func = o_picture_shortest_distance;  break;
+    case OBJ_CIRCLE:      func = o_circle_shortest_distance;   break;
+    case OBJ_PLACEHOLDER:
+    case OBJ_COMPLEX:     func = o_complex_shortest_distance;  break;
+    case OBJ_TEXT:        func = o_text_shortest_distance;     break;
+    case OBJ_PATH:        func = o_path_shortest_distance;     break;
+    case OBJ_ARC:         func = o_arc_shortest_distance;      break;
     default:
       g_critical ("o_shortest_distance: object %p has bad type '%c'\n",
                   object, object->type);
   }
+
+  if (func != NULL) {
+    shortest_distance = (*func) (object, x, y);
+  }
+
   return shortest_distance;
 }
 
diff --git a/libgeda/src/o_box_basic.c b/libgeda/src/o_box_basic.c
index 0851a2a..48236a5 100644
--- a/libgeda/src/o_box_basic.c
+++ b/libgeda/src/o_box_basic.c
@@ -1295,49 +1295,39 @@ void o_box_print_hatch(TOPLEVEL *toplevel, FILE *fp,
 /*! \brief Calculates the distance between the given point and the closest
  * point on the perimeter of the box.
  *
- *  \param [in] box  The box of an OBJECT (object->box != NULL).
- *  \param [in] x The x coordinate of the given point.
- *  \param [in] y The y coordinate of the given point.
+ *  \param [in] object  The box OBJECT.
+ *  \param [in] x       The x coordinate of the given point.
+ *  \param [in] y       The y coordinate of the given point.
  *  \return The shortest distance from the object to the point. With an 
  *  invalid parameter, this function returns G_MAXDOUBLE.
  */
-gdouble o_box_shortest_distance(BOX *box, gint x, gint y)
+double o_box_shortest_distance (OBJECT *object, int x, int y)
 {
-  gdouble dx;
-  gdouble dy;
-  gdouble shortest_distance;
-  gdouble x0;
-  gdouble x1;
-  gdouble y0;
-  gdouble y1;
-
-  if (box == NULL) {
-    g_critical("o_box_shortest_distance(): box == NULL\n");
-    return G_MAXDOUBLE;
-  }
+  double shortest_distance;
+  double x1, y1, x2, y2;
+  double dx, dy;
 
-  x0 = (gdouble) min(box->upper_x, box->lower_x);
-  x1 = (gdouble) max(box->upper_x, box->lower_x);
-  y0 = (gdouble) min(box->upper_y, box->lower_y);
-  y1 = (gdouble) max(box->upper_y, box->lower_y);
+  g_return_val_if_fail (object->box != NULL, G_MAXDOUBLE);
 
-  dx = min(((gdouble) x)-x0, x1-((gdouble) x));
-  dy = min(((gdouble) y)-y0, y1-((gdouble) y));
+  x1 = (double) min (object->box->upper_x, object->box->lower_x);
+  y1 = (double) min (object->box->upper_y, object->box->lower_y);
+  x2 = (double) max (object->box->upper_x, object->box->lower_x);
+  y2 = (double) max (object->box->upper_y, object->box->lower_y);
 
-  if ( dx < 0 ) {
-    if ( dy < 0 ) {
-      shortest_distance = sqrt((dx*dx) + (dy*dy));
-    }
-    else {
-      shortest_distance = fabs(dx);
-    }
-  }
-  else {
-    if ( dy < 0 ) {
-      shortest_distance = fabs(dy);
+  dx = min (((double)x) - x1, x2 - ((double)x));
+  dy = min (((double)y) - y1, y2 - ((double)y));
+
+  if (dx < 0) {
+    if (dy < 0) {
+      shortest_distance = sqrt ((dx * dx) + (dy * dy));
+    } else {
+      shortest_distance = fabs (dx);
     }
-    else {
-      shortest_distance = min(dx,dy);
+  } else {
+    if (dy < 0) {
+      shortest_distance = fabs (dy);
+    } else {
+      shortest_distance = min (dx, dy);
     }
   }
 
diff --git a/libgeda/src/o_circle_basic.c b/libgeda/src/o_circle_basic.c
index 53d5e6b..ceeaa92 100644
--- a/libgeda/src/o_circle_basic.c
+++ b/libgeda/src/o_circle_basic.c
@@ -1105,30 +1105,26 @@ void o_circle_print_hatch(TOPLEVEL *toplevel, FILE *fp,
 /*! \brief Calculates the distance between the given point and the closest
  * point on the perimeter of the circle.
  *
- *  \param [in] circle The circle of the OBJECT
- *  \param [in] x The x coordinate of the given point.
- *  \param [in] y The y coordinate of the given point.
+ *  \param [in] object  The circle OBJECT.
+ *  \param [in] x       The x coordinate of the given point.
+ *  \param [in] y       The y coordinate of the given point.
  *  \return The shortest distance from the object to the point.  With an
  *  invalid parameter, this function returns G_MAXDOUBLE.
  */
-gdouble o_circle_shortest_distance(CIRCLE *circle, gint x, gint y)
+double o_circle_shortest_distance (OBJECT *object, int x, int y)
 {
-  gdouble distance_to_center;
-  gdouble dx;
-  gdouble dy;
-  gdouble shortest_distance;
-
-  if (circle == NULL) {
-    g_critical("o_circle_shortest_distance(): circle == NULL\n");
-    return FALSE;
-  }
+  double shortest_distance;
+  double distance_to_center;
+  double dx, dy;
+
+  g_return_val_if_fail (object->circle != NULL, G_MAXDOUBLE);
 
-  dx = ((gdouble) x) - ((gdouble) circle->center_x);
-  dy = ((gdouble) y) - ((gdouble) circle->center_y);
+  dx = ((double)x) - ((double)object->circle->center_x);
+  dy = ((double)y) - ((double)object->circle->center_y);
 
-  distance_to_center = sqrt((dx*dx) + (dy*dy));
+  distance_to_center = sqrt ((dx * dx) + (dy * dy));
 
-  shortest_distance = fabs(distance_to_center - circle->radius);
+  shortest_distance = fabs (distance_to_center - object->circle->radius);
 
   return shortest_distance;
 }
diff --git a/libgeda/src/o_complex_basic.c b/libgeda/src/o_complex_basic.c
index 09e6bc1..37f580e 100644
--- a/libgeda/src/o_complex_basic.c
+++ b/libgeda/src/o_complex_basic.c
@@ -1533,26 +1533,24 @@ done:
 /*! \brief Calculates the distance between the given point and the closest
  * point on an object within the complex object.
  *
- *  \param [in] complex The complex of the OBJECT
- *  \param [in] x The x coordinate of the given point.
- *  \param [in] y The y coordinate of the given point.
+ *  \param [in] object  The complex  OBJECT.
+ *  \param [in] x       The x coordinate of the given point.
+ *  \param [in] y       The y coordinate of the given point.
  *  \return The shortest distance from the object to the point. If the
  *  distance cannot be calculated, this function returns a really large
  *  number (G_MAXDOUBLE).  With an invalid parameter, this function returns
  *  G_MAXDOUBLE.
  */
-gdouble o_complex_shortest_distance(COMPLEX *complex, gint x, gint y)
+double o_complex_shortest_distance (OBJECT *object, int x, int y)
 {
-  gdouble distance;
-  gdouble shortest_distance = G_MAXDOUBLE;
+  double shortest_distance = G_MAXDOUBLE;
+  double distance;
   GList *iter;
 
-  if (complex == NULL) {
-    g_critical("o_complex_shortest_distance(): complex == NULL\n");
-    return G_MAXDOUBLE;
-  }
+  g_return_val_if_fail (object->complex != NULL, G_MAXDOUBLE);
 
-  for (iter = complex->prim_objs; iter != NULL; iter= g_list_next (iter)) {
+  for (iter = object->complex->prim_objs;
+       iter != NULL; iter= g_list_next (iter)) {
     OBJECT *obj = iter->data;
 
     distance = o_shortest_distance (obj, x, y);
diff --git a/libgeda/src/o_line_basic.c b/libgeda/src/o_line_basic.c
index afcf684..6abd97e 100644
--- a/libgeda/src/o_line_basic.c
+++ b/libgeda/src/o_line_basic.c
@@ -1213,36 +1213,27 @@ double o_line_length(OBJECT *object)
  *  If the line represents a single point (the endpoints are the same), this
  *  function calcualtes the distance to that point.
  *
- *  \param [in] line  The line of an OBJECT
- *  \param [in] x The x coordinate of the given point.
- *  \param [in] y The y coordinate of the given point.
+ *  \param [in] object  The line OBJECT.
+ *  \param [in] x       The x coordinate of the given point.
+ *  \param [in] y       The y coordinate of the given point.
  *  \return The shortest distance from the object to the point. With an
  *  invalid parameter, this function returns G_MAXDOUBLE.
  */
-gdouble o_line_shortest_distance(LINE *line, gint x, gint y)
+double o_line_shortest_distance (OBJECT *object, int x, int y)
 {
-  gdouble cx;
-  gdouble cy;
-  gdouble dx;
-  gdouble dx0;
-  gdouble dy;
-  gdouble dy0;
-  gdouble ldx;
-  gdouble ldy;
-  gdouble lx0;
-  gdouble ly0;
-  gdouble shortest_distance;
-  gdouble t;
-
-  if (line == NULL) {
-    g_critical("o_line_shortest_distance(): line == NULL\n");
-    return G_MAXDOUBLE;
-  }
+  double cx, cy;
+  double dx, dy;
+  double dx0, dy0;
+  double lx0, ly0;
+  double ldx, ldy;
+  double t;
 
-  lx0 = (double) line->x[0];
-  ly0 = (double) line->y[0];
-  ldx = ((double) line->x[1]) - ((double) line->x[0]);
-  ldy = ((double) line->y[1]) - ((double) line->y[0]);
+  g_return_val_if_fail (object->line != NULL, G_MAXDOUBLE);
+
+  lx0 = (double)object->line->x[0];
+  ly0 = (double)object->line->y[0];
+  ldx = (double)(object->line->x[1] - object->line->x[0]);
+  ldy = (double)(object->line->y[1] - object->line->y[0]);
 
   if (ldx == 0 && ldy == 0) {
     /* if line is a point, just calculate distance to the point */
@@ -1269,8 +1260,6 @@ gdouble o_line_shortest_distance(LINE *line, gint x, gint y)
     dy = y - cy;
   }
 
-  shortest_distance = sqrt( (dx*dx) + (dy*dy) );
-
-  return shortest_distance;
+  return sqrt ((dx * dx) + (dy * dy));
 }
 
diff --git a/libgeda/src/o_path_basic.c b/libgeda/src/o_path_basic.c
index d592e8e..172da4f 100644
--- a/libgeda/src/o_path_basic.c
+++ b/libgeda/src/o_path_basic.c
@@ -1038,16 +1038,16 @@ void o_path_print(TOPLEVEL *toplevel, FILE *fp, OBJECT *o_current,
 /*! \brief Calculates the distance between the given point and the closest
  *  point on the given path segment.
  *
- *  \param [in] object The path OBJECT
- *  \param [in] x The x coordinate of the given point.
- *  \param [in] y The y coordinate of the given point.
+ *  \param [in] object  The path OBJECT.
+ *  \param [in] x       The x coordinate of the given point.
+ *  \param [in] y       The y coordinate of the given point.
  *  \return The shortest distance from the object to the point.  With an
  *  invalid parameter, this function returns G_MAXDOUBLE.
  */
-gdouble o_path_shortest_distance (OBJECT *object, gint x, gint y)
+double o_path_shortest_distance (OBJECT *object, int x, int y)
 {
+  double shortest_distance = G_MAXDOUBLE;
   GArray *points;
-  gdouble shortest = G_MAXDOUBLE;
   gboolean solid;
 
   points = g_array_new (FALSE, FALSE, sizeof (sPOINT));
@@ -1057,17 +1057,17 @@ gdouble o_path_shortest_distance (OBJECT *object, gint x, gint y)
   solid = object->fill_type != FILLING_HOLLOW;    /* FIXME */
 
   if (!solid) {
-    shortest = m_polygon_shortest_distance (points, x, y, FALSE);
+    shortest_distance = m_polygon_shortest_distance (points, x, y, FALSE);
 
   } else if (m_polygon_interior_point (points, x, y)) {
-    shortest = 0;
+    shortest_distance = 0;
 
   } else {
-    shortest = m_polygon_shortest_distance (points, x, y, TRUE);
+    shortest_distance = m_polygon_shortest_distance (points, x, y, TRUE);
   }
 
   g_array_free (points, TRUE);
 
-  return shortest;
+  return shortest_distance;
 }
 
diff --git a/libgeda/src/o_picture.c b/libgeda/src/o_picture.c
index adeac52..aa15b46 100644
--- a/libgeda/src/o_picture.c
+++ b/libgeda/src/o_picture.c
@@ -1021,40 +1021,30 @@ GdkPixbuf *o_picture_pixbuf_from_buffer (gchar *file_content,
  *
  *  Interrior points within the picture return a distance of zero.
  *
- *  \param [in] picture the picture of the OBJECT
- *  \param [in] x The x coordinate of the given point.
- *  \param [in] y The y coordinate of the given point.
+ *  \param [in] object  The picture OBJECT.
+ *  \param [in] x       The x coordinate of the given point.
+ *  \param [in] y       The y coordinate of the given point.
  *  \return The shortest distance from the object to the point. With an
  *  invalid parameter, this function returns G_MAXDOUBLE.
  */
-gdouble o_picture_shortest_distance(PICTURE *picture, gint x, gint y)
+double o_picture_shortest_distance (OBJECT *object, int x, int y)
 {
-  gdouble dx;
-  gdouble dy;
-  gdouble shortest_distance;
-  gdouble x0;
-  gdouble x1;
-  gdouble y0;
-  gdouble y1;
-
-  if (picture == NULL) {
-    g_critical("o_picture_shortest_distance(): picture == NULL\n");
-    return G_MAXDOUBLE;
-  }
+  double dx, dy;
+  double x1, y1, x2, y2;
 
-  x0 = (gdouble) min(picture->upper_x, picture->lower_x);
-  x1 = (gdouble) max(picture->upper_x, picture->lower_x);
-  y0 = (gdouble) min(picture->upper_y, picture->lower_y);
-  y1 = (gdouble) max(picture->upper_y, picture->lower_y);
+  g_return_val_if_fail (object->picture != NULL, G_MAXDOUBLE);
 
-  dx = min(((gdouble) x)-x0, x1-((gdouble) x));
-  dy = min(((gdouble) y)-y0, y1-((gdouble) y));
+  x1 = (double)min (object->picture->upper_x, object->picture->lower_x);
+  y1 = (double)min (object->picture->upper_y, object->picture->lower_y);
+  x2 = (double)max (object->picture->upper_x, object->picture->lower_x);
+  y2 = (double)max (object->picture->upper_y, object->picture->lower_y);
 
-  dx = min(dx, 0);
-  dy = min(dy, 0);
+  dx = min (((double)x) - x1, x2 - ((double)x));
+  dy = min (((double)y) - y1, y2 - ((double)y));
 
-  shortest_distance = sqrt((dx*dx) + (dy*dy));
+  dx = min (dx, 0);
+  dy = min (dy, 0);
 
-  return shortest_distance;
+  return sqrt ((dx * dx) + (dy * dy));
 }
 
diff --git a/libgeda/src/o_text_basic.c b/libgeda/src/o_text_basic.c
index 2d771b4..a95d5d9 100644
--- a/libgeda/src/o_text_basic.c
+++ b/libgeda/src/o_text_basic.c
@@ -1802,26 +1802,24 @@ void o_text_mirror_world(TOPLEVEL *toplevel,
  *  This function will calculate the distance to the text regardless
  *  if the text is visible or not.
  *
- *  \param [in] text  the text of the OBJECT
- *  \param [in] x The x coordinate of the given point.
- *  \param [in] y The y coordinate of the given point.
+ *  \param [in] object  The text OBJECT.
+ *  \param [in] x       The x coordinate of the given point.
+ *  \param [in] y       The y coordinate of the given point.
  *  \return The shortest distance from the object to the point. If the
  *  distance cannot be calculated, this function returns a really large
  *  number (G_MAXDOUBLE).  With an invalid parameter, this funciton
  *  returns G_MAXDOUBLE.
  */
-gdouble o_text_shortest_distance(TEXT *text, gint x, gint y)
+double o_text_shortest_distance (OBJECT *object, int x, int y)
 {
-  gdouble distance;
-  gdouble shortest_distance = G_MAXDOUBLE;
+  double shortest_distance = G_MAXDOUBLE;
+  double distance;
   GList *iter;
 
-  if (text == NULL) {
-    g_critical("o_text_shortest_distance(): text == NULL\n");
-    return G_MAXDOUBLE;
-  }
+  g_return_val_if_fail (object->text != NULL, G_MAXDOUBLE);
 
-  for (iter = text->prim_objs; iter != NULL; iter= g_list_next (iter)) {
+  for (iter = object->text->prim_objs;
+       iter != NULL; iter = g_list_next (iter)) {
     OBJECT *obj = iter->data;
 
     distance = o_shortest_distance (obj, x, y);




_______________________________________________
geda-cvs mailing list
geda-cvs@xxxxxxxxxxxxxx
http://www.seul.org/cgi-bin/mailman/listinfo/geda-cvs