#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_TRACERS_LINE2TRACER_H #define NUCLEX_GEOMETRY_LINES_TRACERS_LINE2TRACER_H #include "Nuclex/Geometry/Config.h" #include "Nuclex/Geometry/Lines/Line2.h" #include "Nuclex/Geometry/LineContacts.h" namespace Nuclex { namespace Geometry { namespace Lines { namespace Tracers { // ------------------------------------------------------------------------------------------- // /// Determines contacts between lines template class Line2Tracer { /// Determines where a line crosses another line /// Line whose time of crossing will be determined /// Other line that might be crossed /// The time at which the line crosses the other line public: static LineContacts FindLineContacts( const Lines::Line2 &line, const Lines::Line2 &otherLine ) { float perpendicularDot = (line.Direction.X * otherLine.Direction.Y) - (line.Direction.Y * otherLine.Direction.X); if(perpendicularDot == 0) { return LineContacts::None; } Vector2 offset = otherLine.Origin - line.Origin; float t = (offset.X * otherLine.Direction.Y - offset.Y * otherLine.Direction.X); t /= perpendicularDot; return LineContacts(t, t); } }; // ------------------------------------------------------------------------------------------- // }}}} // namespace Nuclex::Geometry::Lines::Tracers #endif // NUCLEX_GEOMETRY_LINES_TRACERS_LINE2TRACER_H