|
degate 0.1.1
|
#include <Line.h>

Public Member Functions | |
| Line () | |
| Line (int from_x, int from_y, int to_x, int to_y, unsigned int diameter) | |
| virtual | ~Line () |
| 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 |
| Line::Line | ( | ) |
| Line::Line | ( | int | from_x, |
| int | from_y, | ||
| int | to_x, | ||
| int | to_y, | ||
| unsigned int | diameter | ||
| ) |
| 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 168 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);
}


| BoundingBox const & Line::get_bounding_box | ( | ) | const [virtual] |
Get the bounding box.
Implements degate::AbstractShape.
Reimplemented in degate::Wire.
Definition at line 94 of file Line.cc.
References bounding_box.
{
return bounding_box;
}
| unsigned int Line::get_diameter | ( | ) | const [virtual] |
Definition at line 111 of file Line.cc.
References diameter.
Referenced by degate::Wire::push_object_to_server().
{
return diameter;
}

| int Line::get_from_x | ( | ) | const [virtual] |
Definition at line 115 of file Line.cc.
References from_x.
Referenced by degate::LinearPrimitive::print(), and degate::Wire::push_object_to_server().
{
return from_x;
}

| int Line::get_from_y | ( | ) | const [virtual] |
Definition at line 119 of file Line.cc.
References from_y.
Referenced by degate::LinearPrimitive::print(), and degate::Wire::push_object_to_server().
{
return from_y;
}

| unsigned int Line::get_length | ( | ) | const [virtual] |
| Point Line::get_p1 | ( | ) | const [virtual] |
| Point Line::get_p2 | ( | ) | const [virtual] |
| int Line::get_to_x | ( | ) | const [virtual] |
Definition at line 123 of file Line.cc.
References to_x.
Referenced by degate::LinearPrimitive::print(), and degate::Wire::push_object_to_server().
{
return to_x;
}

| int Line::get_to_y | ( | ) | const [virtual] |
Definition at line 127 of file Line.cc.
References to_y.
Referenced by degate::LinearPrimitive::print(), and degate::Wire::push_object_to_server().
{
return to_y;
}

| 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 89 of file Line.cc.
References bounding_box, and degate::BoundingBox::in_bounding_box().
{
return bounding_box.in_bounding_box(bbox);
}

| 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 51 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;
}
}

| bool Line::is_horizontal | ( | ) | const [virtual] |
Definition at line 102 of file Line.cc.
Referenced by calculate_bounding_box(), and in_shape().

| bool Line::is_vertical | ( | ) | const [virtual] |
Definition at line 98 of file Line.cc.
Referenced by calculate_bounding_box(), and in_shape().

| void Line::set_diameter | ( | unsigned int | diameter | ) | [virtual] |
Definition at line 106 of file Line.cc.
References calculate_bounding_box(), and diameter.
{
this->diameter = diameter;
calculate_bounding_box();
}

| void Line::set_from_x | ( | int | min_x | ) | [virtual] |
| void Line::set_from_y | ( | int | min_y | ) | [virtual] |
| void Line::set_p1 | ( | Point const & | p | ) | [virtual] |
Definition at line 195 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());
}


| void Line::set_p2 | ( | Point const & | p | ) | [virtual] |
Definition at line 200 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().


| void Line::set_to_x | ( | int | max_x | ) | [virtual] |
| void Line::set_to_y | ( | int | max_y | ) | [virtual] |
| 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 161 of file Line.cc.
References calculate_bounding_box(), from_x, and to_x.
{
from_x += delta_x;
to_x += delta_x;
calculate_bounding_box();
}

| 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 155 of file Line.cc.
References calculate_bounding_box(), from_y, and to_y.
{
from_y += delta_y;
to_y += delta_y;
calculate_bounding_box();
}

BoundingBox degate::Line::bounding_box [private] |
Definition at line 39 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 37 of file Line.h.
Referenced by in_shape(), set_from_x(), and set_to_x().
double degate::Line::d_y [private] |
Definition at line 37 of file Line.h.
Referenced by in_shape(), set_from_y(), and set_to_y().
unsigned int degate::Line::diameter [private] |
Definition at line 35 of file Line.h.
Referenced by calculate_bounding_box(), get_diameter(), in_shape(), and set_diameter().
int degate::Line::from_x [private] |
Definition at line 34 of file Line.h.
Referenced by calculate_bounding_box(), get_from_x(), get_length(), get_p1(), in_shape(), is_vertical(), set_from_x(), set_to_x(), and shift_x().
int degate::Line::from_y [private] |
Definition at line 34 of file Line.h.
Referenced by calculate_bounding_box(), get_from_y(), get_length(), get_p1(), in_shape(), is_horizontal(), set_from_y(), set_to_y(), and shift_y().
int degate::Line::to_x [private] |
Definition at line 34 of file Line.h.
Referenced by calculate_bounding_box(), get_length(), get_p2(), get_to_x(), in_shape(), is_vertical(), set_from_x(), set_to_x(), and shift_x().
int degate::Line::to_y [private] |
Definition at line 34 of file Line.h.
Referenced by calculate_bounding_box(), get_length(), get_p2(), get_to_y(), is_horizontal(), set_from_y(), set_to_y(), and shift_y().
1.7.4