5#ifndef NIRT_LINE_2D_HPP_INCLUDED
6#define NIRT_LINE_2D_HPP_INCLUDED
8#include <nirtcpp/core/engine/nirt_types.hpp>
9#include <nirtcpp/core/engine/vector2d.hpp>
31 line2d<T>& operator+=(
const vector2d<T>& point) {
start += point;
end += point;
return *
this; }
33 line2d<T> operator-(
const vector2d<T>& point)
const {
return line2d<T>(
start - point,
end - point); }
34 line2d<T>& operator-=(
const vector2d<T>& point) {
start -= point;
end -= point;
return *
this; }
36 bool operator==(
const line2d<T>& other)
const
37 {
return (
start==other.start &&
end==other.end) || (
end==other.start &&
start==other.end);}
38 bool operator!=(
const line2d<T>& other)
const
39 {
return !(
start==other.start &&
end==other.end) || (
end==other.start &&
start==other.end);}
90 if (
o4 == 0 &&
end.isBetweenPoints(
other.start,
other.end))
return true;
109 return a.nearlyParallel( b,
factor);
124 (
l.end.Y -
l.start.Y)*(
start.X -
l.start.X));
166 (
l.end.Y -
l.start.Y)*(
start.X -
l.start.X));
180 else if(
l.end ==
end ||
l.start ==
end)
202 else if ((
l.start.X>
start.X &&
l.start.X>
l.end.X &&
l.start.X>
end.X) || (
l.start.Y>
start.Y &&
l.start.Y>
l.end.Y &&
l.start.Y>
end.Y))
210 else if (
maxp !=
l.start && ((
l.start.X<
start.X &&
l.start.X<
l.end.X &&
l.start.X<
end.X) || (
l.start.Y<
start.Y &&
l.start.Y<
l.end.Y &&
l.start.Y<
end.Y)))
305 f64 d = v.getLength();
309 f64 t = v.dotProduct(c);
341 if (
t < 0)
return start;
342 if (
t >
d)
return end;
Axis aligned bounding box in 3d dimensional space.
Definition aabbox3d.hpp:22
aabbox3d()
Default Constructor.
Definition aabbox3d.hpp:26
2D line between two points with intersection methods.
Definition line2d.hpp:19
vector2d< T > end
End point of the line.
Definition line2d.hpp:324
vector2d< T > start
Start point of the line.
Definition line2d.hpp:322
vector2d< T > getVector() const
Get the vector of the line.
Definition line2d.hpp:66
bool intersectAsSegments(const line2d< T > &other) const
Definition line2d.hpp:70
line2d()
Default constructor for line going from (0,0) to (1,1).
Definition line2d.hpp:22
f64 getAngleWith(const line2d< T > &l) const
Get angle between this line and given line.
Definition line2d.hpp:266
void setLine(const T &xa, const T &ya, const T &xb, const T &yb)
Set this line to new line going through the two points.
Definition line2d.hpp:43
T getPointOrientation(const vector2d< T > &point) const
Tells us if the given point lies to the left, right, or on the line.
Definition line2d.hpp:276
T getLengthSQ() const
Get squared length of the line.
Definition line2d.hpp:55
T getLength() const
Get length of line.
Definition line2d.hpp:51
vector2d< T > getClosestPoint(const vector2d< T > &point, bool checkOnlySegments=true) const
Get the closest point on this line to a point.
Definition line2d.hpp:301
line2d(T xa, T ya, T xb, T yb)
Constructor for line between the two points.
Definition line2d.hpp:24
bool lineIntersectSegment(const line2d< T > &segment, vector2d< T > &out) const
Definition line2d.hpp:139
vector2d< T > fastLinesIntersection(const line2d< T > &l) const
Definition line2d.hpp:116
bool nearlyParallel(const line2d< T > &line, const T factor=relativeErrorFactor< T >()) const
Definition line2d.hpp:104
bool incidentSegments(const line2d< T > &other) const
Definition line2d.hpp:96
bool intersectWith(const line2d< T > &l, vector2d< T > &out, bool checkOnlySegments=true, bool ignoreCoincidentLines=false) const
Tests if this line intersects with another line.
Definition line2d.hpp:158
vector2d< T > getMiddle() const
Get middle of the line.
Definition line2d.hpp:59
void setLine(const line2d< T > &line)
Set this line to new line given as parameter.
Definition line2d.hpp:47
line2d(const vector2d< T > &start, const vector2d< T > &end)
Constructor for line between the two points given as vectors.
Definition line2d.hpp:26
vector2d< T > getUnitVector() const
Get unit vector of the line.
Definition line2d.hpp:257
bool isPointBetweenStartAndEnd(const vector2d< T > &point) const
Check if the given point is between start and end of the line.
Definition line2d.hpp:292
void setLine(const vector2d< T > &nstart, const vector2d< T > &nend)
Set this line to new line going through the two points.
Definition line2d.hpp:45
bool isPointOnLine(const vector2d< T > &point) const
Check if the given point is a member of the line.
Definition line2d.hpp:284
T getLength() const
Gets the length of the vector.
Definition vector2d.hpp:125
T dotProduct(const vector2d< T > &other) const
Get the dot product of this vector with another.
Definition vector2d.hpp:135
bool equals(const T a, const T b, const T tolerance=roundingError< T >())
returns if a equals b, taking possible rounding errors into account
Definition irrMath.hpp:243
As of Nirtcpp 1.6, position2d is a synonym for vector2d.
Definition vector3d.hpp:11
signed int s32
32 bit signed variable.
Definition irrTypes.hpp:72
double f64
64 bit floating point variable.
Definition irrTypes.hpp:114
float f32
32 bit floating point variable.
Definition irrTypes.hpp:110