Gorgon Game Engine
Line.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <vector>
4 #include <exception>
5 
6 #include "Point.h"
7 
8 namespace Gorgon { namespace Geometry {
9 
15  template<class P_ = Pointf>
16  class Line {
17  public:
18 
20  Line() = default;
21 
22  Line(P_ start, P_ end) : Start(start), End(end) { }
23 
25  Float Slope() const {
26  return Float(End.Y - Start.Y) / (End.X - Start.X);
27  }
28 
30  Float Offset() const {
31  return Start.Y - Slope() * Start.X;
32  }
33 
36  Float SlopeInv() const {
37  return Float(End.X - Start.X) / (End.Y - Start.Y);
38  }
39 
42  Float OffsetInv() const {
43  return Start.X - SlopeInv() * Start.Y;
44  }
45 
47  typename P_::BaseType MinY() const {
48  return Start.Y < End.Y ? Start.Y : End.Y;
49  }
50 
52  typename P_::BaseType MaxY() const {
53  return Start.Y > End.Y ? Start.Y : End.Y;
54  }
55 
57  typename P_::BaseType MinX() const {
58  return Start.X < End.X ? Start.X : End.X;
59  }
60 
62  typename P_::BaseType MaxX() const {
63  return Start.X > End.X ? Start.X : End.X;
64  }
65 
69  int YDirection() const {
70  return Sign(End.Y - Start.Y);
71  }
72 
76  int XDirection() const {
77  return Sign(End.X - Start.X);
78  }
79 
81  P_ Start;
82 
84  P_ End;
85  };
86 
87 
88  //non-member operations: translate, scale, rotate, etc...
89 
90 } }
Gorgon::Geometry::Line::End
P_ End
Ending point of the line.
Definition: Line.h:84
Gorgon::Geometry::Line::MaxY
P_::BaseType MaxY() const
Returns maximum Y point.
Definition: Line.h:52
Gorgon::Geometry::Line::Offset
Float Offset() const
Returns the offset of the line. Assumes the line is 2D.
Definition: Line.h:30
Point.h
contains point class.
Gorgon::Geometry::Line
This class represents a set of points.
Definition: Line.h:16
Gorgon::Float
float Float
Represents floating point data type.
Definition: Types.h:16
Gorgon::Geometry::Line::Line
Line()=default
Empty constructor.
Gorgon
Root namespace for Gorgon Game Engine.
Definition: Any.h:19
Gorgon::Geometry::Line::MinX
P_::BaseType MinX() const
Returns minimum X point.
Definition: Line.h:57
Gorgon::Geometry::Line::Start
P_ Start
Starting point of the line.
Definition: Line.h:81
Gorgon::Geometry::Line::OffsetInv
Float OffsetInv() const
Returns the inverse offset of the line, where the line formula is now x = a * y + b.
Definition: Line.h:42
Gorgon::Geometry::Line::XDirection
int XDirection() const
Returns whether the line is moving left or right.
Definition: Line.h:76
Gorgon::Geometry::Line::SlopeInv
Float SlopeInv() const
Returns the inverse slope of the line, where the line formula is now x = a * y + b.
Definition: Line.h:36
Gorgon::Geometry::Line::MinY
P_::BaseType MinY() const
Returns minimum Y point.
Definition: Line.h:47
Gorgon::Sign
int Sign(T_ val)
Definition: Types.h:126
Gorgon::Geometry::Line::Line
Line(P_ start, P_ end)
Definition: Line.h:22
Gorgon::Geometry::Line::Slope
Float Slope() const
Returns the slope of the line. Assumes the line is 2D.
Definition: Line.h:25
Gorgon::end
std::vector< T_ >::const_iterator end(enum_type_id< T_ >)
Definition: Enum.h:288
Gorgon::Geometry::Line::MaxX
P_::BaseType MaxX() const
Returns maximum X point.
Definition: Line.h:62
Gorgon::Geometry::Line::YDirection
int YDirection() const
Returns whether the line is moving up or down.
Definition: Line.h:69