/*! \brief Calculate the bounds of the path * * On failure, this function sets the bounds to empty. * * \param [in] toplevel Unused * \param [in] object The path to calculate bounds of. * \param [out] bounds The bounds of the path */ void geda_path_object_calculate_bounds (TOPLEVEL *toplevel, const OBJECT *object, GedaBounds *bounds) { gint expand; gint i; geda_bounds_init (bounds); g_return_if_fail (object != NULL); g_return_if_fail (object->type == OBJ_PATH); g_return_if_fail (object->path != NULL); /* Find the bounds of the path region */ for (i = 0; i < object->path->num_sections; i++) { PATH_SECTION *section = &object->path->sections[i]; switch (section->code) { case PATH_CURVETO: /* Bezier curves with this construction of control points will lie * within the convex hull of the control and curve end points */ bounds->min_x = MIN (bounds->min_x, section->x1); bounds->min_y = MIN (bounds->min_y, section->y1); bounds->max_x = MAX (bounds->max_x, section->x1); bounds->max_y = MAX (bounds->max_y, section->y1); bounds->min_x = MIN (bounds->min_x, section->x2); bounds->min_y = MIN (bounds->min_y, section->y2); bounds->max_x = MAX (bounds->max_x, section->x2); bounds->max_y = MAX (bounds->max_y, section->y2); /* Fall through */ case PATH_MOVETO: case PATH_MOVETO_OPEN: case PATH_LINETO: bounds->min_x = MIN (bounds->min_x, section->x3); bounds->min_y = MIN (bounds->min_y, section->y3); bounds->max_x = MAX (bounds->max_x, section->x3); bounds->max_y = MAX (bounds->max_y, section->y3); break; case PATH_END: break; } } expand = ceil (0.5 * G_SQRT2 * object->line_width); /* This isn't strictly correct, but a 1st order approximation */ geda_bounds_expand (bounds, bounds, expand, expand); }
/*! \brief Get BOX bounding rectangle in WORLD coordinates. * \par Function Description * This function sets the <B>left</B>, <B>top</B>, <B>right</B> and <B>bottom</B> * parameters to the boundings of the box object described in <B>*box</B> * in world units. * * \param [in] toplevel The TOPLEVEL object. * \param [in] object BOX OBJECT to read coordinates from. * \param [out] left Left box coordinate in WORLD units. * \param [out] top Top box coordinate in WORLD units. * \param [out] right Right box coordinate in WORLD units. * \param [out] bottom Bottom box coordinate in WORLD units. */ void geda_box_object_calculate_bounds (TOPLEVEL *toplevel, const OBJECT *object, GedaBounds *bounds) { gint expand; geda_bounds_init (bounds); g_return_if_fail (object != NULL); g_return_if_fail (object->type == OBJ_BOX); g_return_if_fail (object->box != NULL); geda_box_calculate_bounds (object->box, bounds); expand = (object->line_width + 1) / 2; /* This isn't strictly correct, but a 1st order approximation */ geda_bounds_expand (bounds, bounds, expand, expand); }
/*! \brief Calculate the bounds of the net * * On failure, this function sets the bounds to empty. * * \param [in] toplevel Unused * \param [in] object The net object * \param [out] bounds The bounds of the net */ void geda_net_object_calculate_bounds (TOPLEVEL *toplevel, const OBJECT *object, GedaBounds *bounds) { gint expand; geda_bounds_init (bounds); g_return_if_fail (object != NULL); g_return_if_fail (object->type == OBJ_NET); g_return_if_fail (object->line != NULL); geda_line_calculate_bounds (object->line, bounds); expand = ceil (0.5 * G_SQRT2 * NET_WIDTH); /* This isn't strictly correct, but a 1st order approximation */ geda_bounds_expand (bounds, bounds, expand, expand); }