TwiceAsNice  2019-02-18
Public Types | Public Member Functions | Related Functions | List of all members
Nice::Line Class Reference

The Nice::Line class provides a two-dimensional vector using floating point precision. More...

#include <Line.h>

Inheritance diagram for Nice::Line:
Inheritance graph
Collaboration diagram for Nice::Line:
Collaboration graph

Public Types

enum  IntersectType {
  NoIntersection, BoundedIntersection, UnboundedIntersection, NoIntersection,
  BoundedIntersection, UnboundedIntersection
}
 
enum  IntersectType {
  NoIntersection, BoundedIntersection, UnboundedIntersection, NoIntersection,
  BoundedIntersection, UnboundedIntersection
}
 

Public Member Functions

 Line ()
 
 Line (const Point &pt1, const Point &pt2)
 
 Line (double x1, double y1, double x2, double y2)
 
 Line (const Nice::LineVar &line)
 
bool isNull () const
 
Point p1 () const
 
Point p2 () const
 
double x1 () const
 
double y1 () const
 
double x2 () const
 
double y2 () const
 
double dx () const
 
double dy () const
 
double length () const
 
void setLength (double len)
 
Line unitVector () const
 
Line normalVector () const
 
IntersectType intersect (const Line &l, Point *intersectionPoint) const
 
double angle (const Line &l) const
 
Point pointAt (double t) const
 
void translate (const Point &p)
 
void translate (double dx, double dy)
 
bool operator== (const Line &d) const
 
bool operator!= (const Line &d) const
 
 Line ()
 
 Line (const Point &pt1, const Point &pt2)
 
 Line (double x1, double y1, double x2, double y2)
 
 Line (const Nice::LineVar &line)
 
bool isNull () const
 
Point p1 () const
 
Point p2 () const
 
double x1 () const
 
double y1 () const
 
double x2 () const
 
double y2 () const
 
double dx () const
 
double dy () const
 
double length () const
 
void setLength (double len)
 
Line unitVector () const
 
Line normalVector () const
 
IntersectType intersect (const Line &l, Point *intersectionPoint) const
 
double angle (const Line &l) const
 
Point pointAt (double t) const
 
void translate (const Point &p)
 
void translate (double dx, double dy)
 
bool operator== (const Line &d) const
 
bool operator!= (const Line &d) const
 
- Public Member Functions inherited from Nice::LineVar
bool operator== (const LineVar &__rhs) const
 
bool operator< (const LineVar &__rhs) const
 
bool operator!= (const LineVar &__rhs) const
 
bool operator<= (const LineVar &__rhs) const
 
bool operator> (const LineVar &__rhs) const
 
bool operator>= (const LineVar &__rhs) const
 
bool operator== (const LineVar &__rhs) const
 
bool operator< (const LineVar &__rhs) const
 
bool operator!= (const LineVar &__rhs) const
 
bool operator<= (const LineVar &__rhs) const
 
bool operator> (const LineVar &__rhs) const
 
bool operator>= (const LineVar &__rhs) const
 

Related Functions

(Note that these are not member functions.)

std::ostream & operator<< (std::ostream &, const Nice::LineVar &)
 
std::istream & operator>> (std::istream &, Nice::LineVar &)
 
std::ostream & operator<< (std::ostream &os, const Nice::LineVar &line)
 
std::istream & operator>> (std::istream &is, Nice::LineVar &line)
 
std::ostream & operator<< (std::ostream &, const Nice::LineVar &)
 
std::istream & operator>> (std::istream &, Nice::LineVar &)
 

Additional Inherited Members

- Public Attributes inherited from Nice::LineVar
::Nice::PointVar pt1
 
::Nice::PointVar pt2
 

Detailed Description

The Nice::Line class provides a two-dimensional vector using floating point precision.

A Nice::Line describes a finite length line (or line segment) on a two-dimensional surface. Nice::Line defines the start and end points of the line using floating point accuracy for coordinates. Use the toLineVar() function to retrieve an integer based copy of this line.

qline-point.png qline-coordinates.png

The positions of the line's start and end points can be retrieved using the p1(), x1(), y1(), p2(), x2(), and y2() functions. The dx() and dy() functions return the horizontal and vertical components of the line, respectively.

The line's length can be retrieved using the length() function, and altered using the setLength() function. Use the isNull() function to determine whether the Nice::Line represents a valid line or a null line.

The intersect() function determines the IntersectType for this line and a given line, while the angle() function returns the angle between the lines. In addition, the unitVector() function returns a line that has the same starting point as this line, but with a length of only 1, while the normalVector() function returns a line that is perpendicular to this line with the same starting point and length.

Finally, the line can be translated a given offset using the translate() function, and can be traversed using the pointAt() function.

See also
Nice::Line, QPolygonF, QRectF

Member Enumeration Documentation

◆ IntersectType [1/2]

Describes the intersection between two lines.

qlinef-unbounded.png qlinef-bounded.png Nice::Line::UnboundedIntersection Nice::Line::BoundedIntersection

NoIntersection Indicates that the lines do not intersect; i.e. they are parallel.

UnboundedIntersection The two lines intersect, but not within the range defined by their lengths. This will be the case if the lines are not parallel.

BoundedIntersection The two lines intersect with each other within the start and end points of each line.

See also
intersect()
Enumerator
NoIntersection 
BoundedIntersection 
UnboundedIntersection 
NoIntersection 
BoundedIntersection 
UnboundedIntersection 

◆ IntersectType [2/2]

Enumerator
NoIntersection 
BoundedIntersection 
UnboundedIntersection 
NoIntersection 
BoundedIntersection 
UnboundedIntersection 

Constructor & Destructor Documentation

◆ Line() [1/8]

Nice::Line::Line ( )
inline

◆ Line() [2/8]

Nice::Line::Line ( const Point pt1,
const Point pt2 
)
inline

◆ Line() [3/8]

Nice::Line::Line ( double  x1,
double  y1,
double  x2,
double  y2 
)
inline

◆ Line() [4/8]

Nice::Line::Line ( const Nice::LineVar line)
inline

◆ Line() [5/8]

Nice::Line::Line ( )
inline

◆ Line() [6/8]

Nice::Line::Line ( const Point pt1,
const Point pt2 
)
inline

◆ Line() [7/8]

Nice::Line::Line ( double  x1,
double  y1,
double  x2,
double  y2 
)
inline

◆ Line() [8/8]

Nice::Line::Line ( const Nice::LineVar line)
inline

Member Function Documentation

◆ angle() [1/2]

double Nice::Line::angle ( const Line l) const

Returns the angle (in degrees) between this line and the given line, taking the direction of the lines into account. If the lines do not intersect within their range, it is the intersection point of the extended lines that serves as origo (see Nice::Line::UnboundedIntersection).

qlinef-angle-identicaldirection.png qlinef-angle-oppositedirection.png

When the lines are parallel, this function returns 0 if they have the same direction; otherwise it returns 180.

See also
intersect()

◆ angle() [2/2]

double Nice::Line::angle ( const Line l) const

◆ dx() [1/2]

double Nice::Line::dx ( ) const
inline

Returns the horizontal component of the line's vector.

See also
dy(), pointAt()

◆ dx() [2/2]

double Nice::Line::dx ( ) const
inline

◆ dy() [1/2]

double Nice::Line::dy ( ) const
inline

Returns the vertical component of the line's vector.

See also
dx(), pointAt()

◆ dy() [2/2]

double Nice::Line::dy ( ) const
inline

◆ intersect() [1/2]

IntersectType Nice::Line::intersect ( const Line l,
Point intersectionPoint 
) const

◆ intersect() [2/2]

Nice::Line::IntersectType Nice::Line::intersect ( const Line l,
Nice::Point intersectionPoint 
) const

Returns a value indicating whether or not this line intersects with the given line.

The actual intersection point is extracted to intersectionPoint (if the pointer is valid). If the lines are parallel, the intersection point is undefined.

◆ isNull() [1/2]

bool Nice::Line::isNull ( ) const

Returns true if the line is not set up with valid start and end point; otherwise returns false.

◆ isNull() [2/2]

bool Nice::Line::isNull ( ) const

Returns true if the line is not set up with valid start and end point; otherwise returns false.

◆ length() [1/2]

double Nice::Line::length ( ) const

Returns the length of the line.

See also
setLength()

◆ length() [2/2]

double Nice::Line::length ( ) const

Returns the length of the line.

See also
setLength()

◆ normalVector() [1/2]

Line Nice::Line::normalVector ( ) const

◆ normalVector() [2/2]

Line Nice::Line::normalVector ( ) const
inline

Returns a line that is perpendicular to this line with the same starting point and length.

See also
unitVector()

◆ operator!=() [1/2]

bool Nice::Line::operator!= ( const Line d) const
inline

◆ operator!=() [2/2]

bool Nice::Line::operator!= ( const Line d) const
inline

Returns true if the given line is not the same as this line.

A line is different from another line if their start or end points differ, or the internal order of the points is different.

◆ operator==() [1/2]

bool Nice::Line::operator== ( const Line d) const
inline

Returns true if the given line is the same as this line.

A line is identical to another line if the start and end points are identical, and the internal order of the points is the same.

◆ operator==() [2/2]

bool Nice::Line::operator== ( const Line d) const
inline

◆ p1() [1/2]

Point Nice::Line::p1 ( ) const
inline

◆ p1() [2/2]

Point Nice::Line::p1 ( ) const
inline

Returns the line's start point.

See also
x1(), y1(), p2()

◆ p2() [1/2]

Point Nice::Line::p2 ( ) const
inline

◆ p2() [2/2]

Point Nice::Line::p2 ( ) const
inline

Returns the line's end point.

See also
x2(), y2(), p1()

◆ pointAt() [1/2]

Point Nice::Line::pointAt ( double  t) const
inline

Returns the point at the parameterized position specified by t. The function returns the line's start point if t = 0, and its end point if t = 1.

See also
dx(), dy()

◆ pointAt() [2/2]

Point Nice::Line::pointAt ( double  t) const

◆ setLength() [1/2]

void Nice::Line::setLength ( double  length)
inline

Sets the length of the line to the given length. If the line is a null line, the length will remain zero regardless of the length specified.

See also
length(), isNull()

◆ setLength() [2/2]

void Nice::Line::setLength ( double  len)

◆ translate() [1/4]

void Nice::Line::translate ( const Point p)
inline

◆ translate() [2/4]

void Nice::Line::translate ( const Point p)
inline

Translates this line by the given offset.

◆ translate() [3/4]

void Nice::Line::translate ( double  dx,
double  dy 
)
inline

◆ translate() [4/4]

void Nice::Line::translate ( double  dx,
double  dy 
)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Translates this line the distance specified by dx and dy.

◆ unitVector() [1/2]

Line Nice::Line::unitVector ( ) const

Returns the unit vector for this line, i.e a line starting at the same point as this line with a length of 1.0.

See also
normalVector()

◆ unitVector() [2/2]

Nice::Line Nice::Line::unitVector ( ) const

Returns the unit vector for this line, i.e a line starting at the same point as this line with a length of 1.0.

See also
normalVector()

◆ x1() [1/2]

double Nice::Line::x1 ( ) const
inline

◆ x1() [2/2]

double Nice::Line::x1 ( ) const
inline

Returns the x-coordinate of the line's start point.

See also
p1()

◆ x2() [1/2]

double Nice::Line::x2 ( ) const
inline

Returns the x-coordinate of the line's end point.

See also
p2()

◆ x2() [2/2]

double Nice::Line::x2 ( ) const
inline

◆ y1() [1/2]

double Nice::Line::y1 ( ) const
inline

◆ y1() [2/2]

double Nice::Line::y1 ( ) const
inline

Returns the y-coordinate of the line's start point.

See also
p1()

◆ y2() [1/2]

double Nice::Line::y2 ( ) const
inline

Returns the y-coordinate of the line's end point.

See also
p2()

◆ y2() [2/2]

double Nice::Line::y2 ( ) const
inline

Friends And Related Function Documentation

◆ operator<<() [1/3]

std::ostream & operator<< ( std::ostream &  os,
const Nice::LineVar line 
)
related

Writes the given line to the given stream and returns a reference to the stream.

See also
{Format of the QDataStream Operators}

◆ operator<<() [2/3]

std::ostream & operator<< ( std::ostream &  ,
const Nice::LineVar  
)
related

Writes the given line to the given stream and returns a reference to the stream.

See also
{Format of the QDataStream Operators}

◆ operator<<() [3/3]

std::ostream & operator<< ( std::ostream &  ,
const Nice::LineVar  
)
related

Writes the given line to the given stream and returns a reference to the stream.

See also
{Format of the QDataStream Operators}

◆ operator>>() [1/3]

std::istream & operator>> ( std::istream &  is,
Nice::LineVar line 
)
related

Reads a line from the given stream into the given line and returns a reference to the stream.

See also
{Format of the std::istream Operators}

◆ operator>>() [2/3]

std::istream & operator>> ( std::istream &  ,
Nice::LineVar  
)
related

Reads a line from the given stream into the given line and returns a reference to the stream.

See also
{Format of the std::istream Operators}

◆ operator>>() [3/3]

std::istream & operator>> ( std::istream &  ,
Nice::LineVar  
)
related

Reads a line from the given stream into the given line and returns a reference to the stream.

See also
{Format of the std::istream Operators}

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