#pragma region CPL License /* Nuclex Native Framework Copyright (C) 2002-2015 Nuclex Development Labs This library is free software; you can redistribute it and/or modify it under the terms of the IBM Common Public License as published by the IBM Corporation; either version 1.0 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the IBM Common Public License for more details. You should have received a copy of the IBM Common Public License along with this library */ #pragma endregion // CPL License #ifndef NUCLEX_GEOMETRY_LINES_LINE2_H #define NUCLEX_GEOMETRY_LINES_LINE2_H #include "Nuclex/Geometry/Config.h" #include "Nuclex/Geometry/Point2.h" #include "Nuclex/Geometry/Vector2.h" namespace Nuclex { namespace Geometry { namespace Lines { // ------------------------------------------------------------------------------------------- // /// 2D line defined by an offset point and a direction template struct Line2 { /// Constructs an uninitialized line public: Line2() {} /// Initializes a line from a line segment public: static Line2 FromSegment(const Point2 &start, const Point2 &end) { return Line2(start, Vector2::Normalize(end - start)); } /// Initializes a line using the specified coordinates /// Offset point at which the line starts /// Direction into which the ray extends public: Line2(const Point2 &origin, const Vector2 &direction) : Origin(origin), Direction(direction) {} /// Offsets the entire line by the specified amount /// Amount the line will be offset on the X axis /// Amount the line will be offset on the Y axis public: void ShiftBy(TScalar offsetX, TScalar offsetY) { this->Origin.X += offsetX; this->Origin.Y += offsetY; } /// Offsets the entire line by the specified amount /// Amount the line will be offset public: void ShiftBy(const Vector2 &offset) { this->Origin += offset; } /// Coordinates at which the line begins /// /// Theoretically, the distance of the line from the coordinate system's center /// would suffice, but this would complicate many calculations (as you need to /// find the line's orthogonal direction first) and eliminate relative intersection /// intervals which can otherwise be made use of by ray and line segment tests. /// public: Point2 Origin; /// Direction into which the line entends public: Vector2 Direction; }; // ------------------------------------------------------------------------------------------- // }}} // namespace Nuclex::Geometry::Lines #endif // NUCLEX_GEOMETRY_LINES_LINE2_H