#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_RAY2TRACER_H #define NUCLEX_GEOMETRY_LINES_TRACERS_RAY2TRACER_H #include "Nuclex/Geometry/Config.h" #include "Nuclex/Geometry/Lines/Line2.h" #include "Nuclex/Geometry/Lines/Ray2.h" #include "Nuclex/Geometry/LineContacts.h" namespace Nuclex { namespace Geometry { namespace Lines { namespace Tracers { // ------------------------------------------------------------------------------------------- // /// Determines contacts between 2D lines and rays template class Ray2Tracer { /// Determines where a line crosses a ray /// Line whose time of crossing will be determined /// Ray that might be crossed /// The time at which the line crosses the ray public: static LineContacts FindLineContacts( const Lines::Line2 &line, const Lines::Ray2 &ray ) { // Time of intersection of the segment with the traced line. This allows us to see // if the segment hits the traced line inside its length. TScalar s = ( line.Direction.X * (line.Origin.Y - ray.Start.Y) - line.Direction.Y * (line.Origin.X - ray.Start.X) ) / (line.Direction.X * ray.Direction.Y - ray.Direction.X * line.Direction.Y); if(s >= 0) { TScalar t = ( ray.Direction.X * (line.Origin.Y - ray.Start.Y) - ray.Direction.Y * (line.Origin.X - ray.Start.X) ) / (line.Direction.X * ray.Direction.Y - ray.Direction.X * line.Direction.Y); return LineContacts(t, t); } else { return LineContacts::None; } } }; // ------------------------------------------------------------------------------------------- // }}}} // namespace Nuclex::Geometry::Lines::Tracers #endif // NUCLEX_GEOMETRY_LINES_TRACERS_RAY2TRACER_H