#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_AREAS_TRACERS_DISC2TRACER_H #define NUCLEX_GEOMETRY_AREAS_TRACERS_DISC2TRACER_H #include "Nuclex/Geometry/Config.h" #include "Nuclex/Geometry/Areas/Disc2.h" #include "Nuclex/Geometry/Lines/Line2.h" #include "Nuclex/Geometry/LineContacts.h" namespace Nuclex { namespace Geometry { namespace Areas { namespace Tracers { // ------------------------------------------------------------------------------------------- // /// Determines contacts between lines and 2D discs template class Disc2Tracer { /// Determines where a line enters and where it exits a disc /// /// Line whose entry and exit through the disc will be determined /// /// Disc the line will be checked against /// The times at which the line enters and leaves the disc public: static LineContacts FindLineContacts( const Lines::Line2 &line, const Disc2 &disc ) { Vector2 offset = line.Origin - disc.Center; float dot = Vector2::Dot(line.Direction, offset); float lineDistanceSquared = (offset.GetSquaredLength() - (disc.Radius * disc.Radius)); float discrete = (dot * dot) - lineDistanceSquared; if(discrete > 0) { discrete = Math::SquareRoot(discrete); return LineContacts(-dot - discrete, -dot + discrete); } else { return LineContacts::None; } } }; // ------------------------------------------------------------------------------------------- // }}}} // namespace Nuclex::Geometry::Areas::Tracers #endif // NUCLEX_GEOMETRY_AREAS_TRACERS_DISC2TRACER_H