Пример #1
0
/*! \brief Calculate the bounds of a box
 *
 *  Calculates the bounds of a box with zero line width.
 *
 *  If this function fails, the bounds will be set to empty.
 *
 *  \param [in] box the circle
 *  \param [out] bounds the bounds of the box
 */
void
geda_box_calculate_bounds (const GedaBox *box, GedaBounds *bounds)
{
  if (box == NULL) {
    geda_bounds_init (bounds);
    g_return_if_fail (box != NULL);
  }

  geda_bounds_init_with_points (bounds,
                                box->lower_x,
                                box->lower_y,
                                box->upper_x,
                                box->upper_y);
}
Пример #2
0
/*! \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);
}
Пример #3
0
/*! \brief Get picture bounding rectangle in WORLD coordinates.
 *
 *  On failure, this function sets the bounds to empty.
 *
 *  \param [in]  toplevel  Unused
 *  \param [in]  object    Picture OBJECT to read coordinates from.
 *  \param [out] bounds    The bounds of the picture
 */
void
geda_picture_object_calculate_bounds (TOPLEVEL *toplevel,
                                      const OBJECT *object,
                                      GedaBounds *bounds)
{
  geda_bounds_init (bounds);

  g_return_if_fail (object != NULL);
  g_return_if_fail (object->type == OBJ_PICTURE);
  g_return_if_fail (object->picture != NULL);

  geda_bounds_init_with_points (bounds,
                                object->picture->lower_x,
                                object->picture->lower_y,
                                object->picture->upper_x,
                                object->picture->upper_y);
}
Пример #4
0
/*! \brief Calculate the bounds of a complex object
 *
 *  On failure, this function sets the bounds to empty.
 *
 *  \param [in] toplevel The toplevel object.
 *  \param [in] object The complex object.
 *  \param [out] bounds The bounds of the complex object
 */
void
geda_complex_object_calculate_bounds (TOPLEVEL *toplevel,
                                      const OBJECT *object,
                                      GedaBounds *bounds)
{
  geda_bounds_init (bounds);

  g_return_if_fail (object != NULL);
  g_return_if_fail (((object->type == OBJ_COMPLEX) || (object->type == OBJ_PLACEHOLDER)));
  g_return_if_fail (object->complex != NULL);

  world_get_object_glist_bounds (toplevel,
                                 object->complex->prim_objs,
                                 &(bounds->min_x),
                                 &(bounds->min_y),
                                 &(bounds->max_x),
                                 &(bounds->max_y));
}
Пример #5
0
/*! \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);
}
Пример #6
0
/*! \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);
}
Пример #7
0
/*! \brief calculate and return the boundaries of a text object
 *
 *  The responsibility of calculating the bounds of any object should probably
 *  be moved to EdaRenderer. And, this method should not be a virtual method
 *  of GedaObject.
 *
 *  \param [in]  toplevel  The TOPLEVEL object.
 *  \param [in]  object    a text object
 *  \param [out] bounds    the bounds of the text
 *  \return TRUE if successful, FALSE if unsuccessful
 */
gboolean
geda_text_object_calculate_bounds (TOPLEVEL *toplevel,
                                   const GedaObject *object,
                                   GedaBounds *bounds)
{
  geda_bounds_init (bounds);

  g_return_val_if_fail (object != NULL, FALSE);
  g_return_val_if_fail (object->text != NULL, FALSE);
  g_return_val_if_fail (object->type == OBJ_TEXT, FALSE);
  g_return_val_if_fail (toplevel != NULL, FALSE);
  g_return_val_if_fail (toplevel->rendered_text_bounds_func != NULL, FALSE);

  return toplevel->rendered_text_bounds_func (toplevel->rendered_text_bounds_data,
                                              object,
                                              &bounds->min_x,
                                              &bounds->min_y,
                                              &bounds->max_x,
                                              &bounds->max_y);
}