degate  0.1.2
Public Member Functions | Private Member Functions | Private Attributes
degate::Line Class Reference

#include <Line.h>

Inheritance diagram for degate::Line:
Inheritance graph
[legend]

List of all members.

Public Member Functions

 Line ()
 Line (int from_x, int from_y, int to_x, int to_y, unsigned int diameter)
virtual ~Line ()
void cloneDeepInto (DeepCopyable_shptr destination, oldnew_t *oldnew) const
 Deep-copy all members to destination.
virtual bool in_shape (int x, int y, int max_distance=0) const
 Check in the Point with coordinates x and y is within the area of the shape.
virtual bool in_bounding_box (BoundingBox const &bbox) const
 Check if this shape is in the bounding box.
virtual BoundingBox const & get_bounding_box () const
 Get the bounding box.
virtual int get_from_x () const
virtual int get_to_x () const
virtual int get_from_y () const
virtual int get_to_y () const
virtual void set_from_x (int min_x)
virtual void set_from_y (int min_y)
virtual void set_to_x (int max_x)
virtual void set_to_y (int max_y)
virtual void shift_x (int delta_x)
 Shift the shape vertically.
virtual void shift_y (int delta_y)
 Shift the shape horizontally.
virtual unsigned int get_diameter () const
virtual void set_diameter (unsigned int diameter)
virtual bool is_vertical () const
virtual bool is_horizontal () const
virtual unsigned int get_length () const
virtual Point get_p1 () const
virtual Point get_p2 () const
virtual void set_p1 (Point const &p)
virtual void set_p2 (Point const &p)

Private Member Functions

void calculate_bounding_box ()
 Recalulate the bounding box of a line.

Private Attributes

int from_x
int from_y
int to_x
int to_y
unsigned int diameter
double d_x
double d_y
BoundingBox bounding_box

Detailed Description

Definition at line 33 of file Line.h.


Constructor & Destructor Documentation

Definition at line 30 of file Line.cc.

References calculate_bounding_box().

           :
  from_x(0),
  from_y(0),
  to_x(0),
  to_y(0),
  diameter(0),
  d_x(0),
  d_y(0) {
  calculate_bounding_box();
}

Here is the call graph for this function:

Line::Line ( int  from_x,
int  from_y,
int  to_x,
int  to_y,
unsigned int  diameter 
)

Definition at line 41 of file Line.cc.

References calculate_bounding_box().

                                                                                 :
  from_x(_from_x),
  from_y(_from_y),
  to_x(_to_x),
  to_y(_to_y),
  diameter(_diameter),
  d_x(_to_x - _from_x),
  d_y(_to_y - _from_y) {
  calculate_bounding_box();
}

Here is the call graph for this function:

virtual degate::Line::~Line ( ) [inline, virtual]

Definition at line 60 of file Line.h.

{}

Member Function Documentation

void Line::calculate_bounding_box ( ) [private]

Recalulate the bounding box of a line.

If the line is either horizontally nor vertically aligned, the bounding box corresponds exactly to the area, the line spans. If the line is horizontal or vertical, the bounding box also depends on the diameter.

Definition at line 181 of file Line.cc.

References bounding_box, diameter, from_x, from_y, is_horizontal(), is_vertical(), to_x, and to_y.

Referenced by Line(), set_diameter(), set_from_x(), set_from_y(), set_to_x(), set_to_y(), shift_x(), and shift_y().

                                  {
  int radius = diameter >> 1;

  if(is_vertical())
    bounding_box = BoundingBox(std::max(from_x  - radius, 0),
                               std::max(to_x + radius, 0), from_y, to_y);
  else if(is_horizontal())
    bounding_box = BoundingBox(from_x, to_x,
                               std::max(from_y - radius, 0),
                               std::max(to_y + radius, 0));
  else
    bounding_box = BoundingBox(from_x, to_x, from_y, to_y);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void Line::cloneDeepInto ( DeepCopyable_shptr  destination,
oldnew_t oldnew 
) const [virtual]

Deep-copy all members to destination.

Todo:
Find out whether the default assignment operator can be used to simplify implementations of this method.

Implements degate::DeepCopyableBase.

Reimplemented in degate::Wire.

Definition at line 52 of file Line.cc.

References d_x, d_y, diameter, from_x, from_y, to_x, and to_y.

                                                                        {
  auto clone = std::dynamic_pointer_cast<Line>(dest);
  clone->from_x = from_x;
  clone->from_y = from_y;
  clone->to_x = to_x;
  clone->to_y = to_y;
  clone->diameter = diameter;
  clone->d_x = d_x;
  clone->d_y = d_y;
  clone->calculate_bounding_box();
}
BoundingBox const & Line::get_bounding_box ( ) const [virtual]

Get the bounding box.

Implements degate::AbstractShape.

Reimplemented in degate::Wire.

Definition at line 107 of file Line.cc.

References bounding_box.

                                                {
  return bounding_box;
}
unsigned int Line::get_diameter ( ) const [virtual]

Definition at line 124 of file Line.cc.

References diameter.

Referenced by degate::Wire::cloneShallow(), and degate::Wire::push_object_to_server().

                                      {
  return diameter;
}

Here is the caller graph for this function:

int Line::get_from_x ( ) const [virtual]

Definition at line 128 of file Line.cc.

References from_x.

Referenced by degate::Wire::cloneShallow(), degate::LinearPrimitive::print(), and degate::Wire::push_object_to_server().

                           {
  return from_x;
}

Here is the caller graph for this function:

int Line::get_from_y ( ) const [virtual]

Definition at line 132 of file Line.cc.

References from_y.

Referenced by degate::Wire::cloneShallow(), degate::LinearPrimitive::print(), and degate::Wire::push_object_to_server().

                           {
  return from_y;
}

Here is the caller graph for this function:

unsigned int Line::get_length ( ) const [virtual]

Definition at line 196 of file Line.cc.

References from_x, from_y, to_x, and to_y.

Referenced by degate::LinearPrimitive::print().

                                    {
  return ((labs(from_x - to_x) << 1) + (labs(from_y - to_y) << 1)) >> 1;
}

Here is the caller graph for this function:

Point Line::get_p1 ( ) const [virtual]

Definition at line 200 of file Line.cc.

References from_x, and from_y.

Referenced by degate::LineSegment::merge().

                         {
  return Point(from_x, from_y);
}

Here is the caller graph for this function:

Point Line::get_p2 ( ) const [virtual]

Definition at line 204 of file Line.cc.

References to_x, and to_y.

Referenced by degate::LineSegment::merge().

                         {
  return Point(to_x, to_y);
}

Here is the caller graph for this function:

int Line::get_to_x ( ) const [virtual]

Definition at line 136 of file Line.cc.

References to_x.

Referenced by degate::Wire::cloneShallow(), degate::LinearPrimitive::print(), and degate::Wire::push_object_to_server().

                         {
  return to_x;
}

Here is the caller graph for this function:

int Line::get_to_y ( ) const [virtual]

Definition at line 140 of file Line.cc.

References to_y.

Referenced by degate::Wire::cloneShallow(), degate::LinearPrimitive::print(), and degate::Wire::push_object_to_server().

                         {
  return to_y;
}

Here is the caller graph for this function:

bool Line::in_bounding_box ( BoundingBox const &  bbox) const [virtual]

Check if this shape is in the bounding box.

Note: it is somhow unclear if this 'in' means complete within or if an intersection is sufficient.

Implements degate::AbstractShape.

Reimplemented in degate::Wire.

Definition at line 102 of file Line.cc.

References bounding_box, and degate::BoundingBox::in_bounding_box().

                                                        {
  return bounding_box.in_bounding_box(bbox);
}

Here is the call graph for this function:

bool Line::in_shape ( int  x,
int  y,
int  max_distance = 0 
) const [virtual]

Check in the Point with coordinates x and y is within the area of the shape.

Implements degate::AbstractShape.

Reimplemented in degate::Wire.

Definition at line 64 of file Line.cc.

References bounding_box, d_x, d_y, diameter, from_x, from_y, degate::BoundingBox::in_shape(), is_horizontal(), is_vertical(), and to_x.

                                                        {

  /*
    How to check if a point is on a line:
    y = m*x + n
    m = dy / dx
    n = y0 - m*x0
    y' = m*x' + n

    |y' - y| < epsilon?
  */

  /*
    Check if it is a vertical line (dy ~~ 0). If it is true, the bounding box
    describes the line. The same applies to horiontal lines.
  */

  if(is_vertical() || is_horizontal()) {
    return bounding_box.in_shape(x, y, max_distance);
  }
  else {

    // check if x is outside the x-range
    if(x < std::min(from_x,to_x) ||
       x > std::max(from_x, to_x))
       return false;

    double m = d_y / d_x;
    double n = (double)from_y - m * (double)from_x;
    double y_dash = m * (double) x + n;

    if(fabs(y_dash - y) <= diameter / 2 + max_distance)
      return true;
    else
      return false;
  }
}

Here is the call graph for this function:

bool Line::is_horizontal ( ) const [virtual]

Definition at line 115 of file Line.cc.

References from_y, and to_y.

Referenced by calculate_bounding_box(), and in_shape().

                               {
  return to_y - from_y == 0;
}

Here is the caller graph for this function:

bool Line::is_vertical ( ) const [virtual]

Definition at line 111 of file Line.cc.

References from_x, and to_x.

Referenced by calculate_bounding_box(), and in_shape().

                             {
  return to_x - from_x == 0;
}

Here is the caller graph for this function:

void Line::set_diameter ( unsigned int  diameter) [virtual]

Definition at line 119 of file Line.cc.

References calculate_bounding_box(), and diameter.

Here is the call graph for this function:

void Line::set_from_x ( int  min_x) [virtual]

Definition at line 144 of file Line.cc.

References calculate_bounding_box(), d_x, from_x, and to_x.

Referenced by set_p1().

Here is the call graph for this function:

Here is the caller graph for this function:

void Line::set_from_y ( int  min_y) [virtual]

Definition at line 156 of file Line.cc.

References calculate_bounding_box(), d_y, from_y, and to_y.

Referenced by set_p1().

Here is the call graph for this function:

Here is the caller graph for this function:

void Line::set_p1 ( Point const &  p) [virtual]

Definition at line 208 of file Line.cc.

References degate::Point::get_x(), degate::Point::get_y(), set_from_x(), and set_from_y().

Referenced by degate::LineSegment::merge().

                                {
  set_from_x(p.get_x());
  set_from_y(p.get_y());
}

Here is the call graph for this function:

Here is the caller graph for this function:

void Line::set_p2 ( Point const &  p) [virtual]

Definition at line 213 of file Line.cc.

References degate::Point::get_x(), degate::Point::get_y(), set_to_x(), and set_to_y().

Referenced by degate::LineSegment::merge().

                                {
  set_to_x(p.get_x());
  set_to_y(p.get_y());
}

Here is the call graph for this function:

Here is the caller graph for this function:

void Line::set_to_x ( int  max_x) [virtual]

Definition at line 150 of file Line.cc.

References calculate_bounding_box(), d_x, from_x, and to_x.

Referenced by set_p2().

Here is the call graph for this function:

Here is the caller graph for this function:

void Line::set_to_y ( int  max_y) [virtual]

Definition at line 162 of file Line.cc.

References calculate_bounding_box(), d_y, from_y, and to_y.

Referenced by set_p2().

Here is the call graph for this function:

Here is the caller graph for this function:

void Line::shift_x ( int  delta_x) [virtual]

Shift the shape vertically.

Note: If you store this shape in a QuadTree, you have to manage the changes in your QuadTree by yourself.

Implements degate::AbstractShape.

Reimplemented in degate::Wire.

Definition at line 174 of file Line.cc.

References calculate_bounding_box(), from_x, and to_x.

                              {
  from_x += delta_x;
  to_x += delta_x;
  calculate_bounding_box();
}

Here is the call graph for this function:

void Line::shift_y ( int  delta_y) [virtual]

Shift the shape horizontally.

Note: If you store this shape in a QuadTree, you have to manage the changes in your QuadTree by yourself.

Implements degate::AbstractShape.

Reimplemented in degate::Wire.

Definition at line 168 of file Line.cc.

References calculate_bounding_box(), from_y, and to_y.

                              {
  from_y += delta_y;
  to_y += delta_y;
  calculate_bounding_box();
}

Here is the call graph for this function:


Member Data Documentation

Definition at line 41 of file Line.h.

Referenced by calculate_bounding_box(), get_bounding_box(), in_bounding_box(), and in_shape().

double degate::Line::d_x [private]

Definition at line 39 of file Line.h.

Referenced by cloneDeepInto(), in_shape(), set_from_x(), and set_to_x().

double degate::Line::d_y [private]

Definition at line 39 of file Line.h.

Referenced by cloneDeepInto(), in_shape(), set_from_y(), and set_to_y().

unsigned int degate::Line::diameter [private]

Definition at line 37 of file Line.h.

Referenced by calculate_bounding_box(), cloneDeepInto(), get_diameter(), in_shape(), and set_diameter().

int degate::Line::from_x [private]
int degate::Line::from_y [private]
int degate::Line::to_x [private]
int degate::Line::to_y [private]

The documentation for this class was generated from the following files: