/*! \brief Calculates the distance between the given point and the closest * point on an object within the complex object. * * \note When querying the distance to our child objects, we always * force treating them as solid filled. * We ignore the force_solid argument to this function. * * \param [in] toplevel The TOPLEVEL object. * \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. * \param [in] force_solid If true, force treating the object as solid. * \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. */ double geda_complex_object_shortest_distance (TOPLEVEL *toplevel, OBJECT *object, int x, int y, int force_solid) { double shortest_distance = G_MAXDOUBLE; double distance; int found_line_bounds = 0; BOX line_bounds; GList *iter; g_return_val_if_fail (object->complex != NULL, G_MAXDOUBLE); for (iter = object->complex->prim_objs; iter != NULL; iter= g_list_next (iter)) { OBJECT *obj = iter->data; int left, top, right, bottom; /* Collect the bounds of any lines and arcs in the symbol */ if ((obj->type == OBJ_LINE || obj->type == OBJ_ARC) && geda_object_calculate_visible_bounds(toplevel, obj, &left, &top, &right, &bottom)) { if (found_line_bounds) { line_bounds.lower_x = min (line_bounds.lower_x, left); line_bounds.lower_y = min (line_bounds.lower_y, top); line_bounds.upper_x = max (line_bounds.upper_x, right); line_bounds.upper_y = max (line_bounds.upper_y, bottom); } else { line_bounds.lower_x = left; line_bounds.lower_y = top; line_bounds.upper_x = right; line_bounds.upper_y = bottom; found_line_bounds = 1; } } else { distance = geda_object_shortest_distance_full (toplevel, obj, x, y, TRUE); shortest_distance = min (shortest_distance, distance); } if (shortest_distance == 0.0) return shortest_distance; } if (found_line_bounds) { distance = geda_box_shortest_distance (&line_bounds, x, y, TRUE); shortest_distance = min (shortest_distance, distance); } return shortest_distance; }
/*! \brief Calculates the distance between the given point and the closest * point on the given object. * * \param [in] toplevel The TOPLEVEL 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. * \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. */ double geda_object_shortest_distance (TOPLEVEL *toplevel, OBJECT *object, int x, int y) { return geda_object_shortest_distance_full (toplevel, object, x, y, FALSE); }