#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_LINECONTACTS_H #define NUCLEX_GEOMETRY_LINECONTACTS_H #include "Nuclex/Geometry/Config.h" #include "Nuclex/Geometry/Math.h" #include namespace Nuclex { namespace Geometry { // ------------------------------------------------------------------------------------------- // /// Stores the entry and exit intervals of a line through a shape template struct LineContacts { /// Contact times used if a line doesn't touch the shape at all public: static const LineContacts None; /// Constructs uninitialized line contacts public: LineContacts() = default; /// Initializes new line contacts using the specified times /// Time at which the line has entered the shape /// Time at which the line has exited the shape public: LineContacts(TScalar entryTime, TScalar exitTime) : EntryTime(entryTime), ExitTime(exitTime) {} /// Builds line contacts by using the extremes of the values /// First value that will be used for the line contacts /// Second value that will be used for the line contacts /// /// Line contacts with the smaller value for entry time and larger one for exit time /// public: static LineContacts FromExtremes(TScalar first, TScalar second) { if(first < second) { return LineContacts(first, second); } else { return LineContacts(second, first); } } /// Builds line contacts by using the extremes of the values /// First value that will be used for the line contacts /// Second value that will be used for the line contacts /// Third value that will be used for the line contacts /// /// Line contacts with the smallest value for entry time and largest one for exit time /// public: static LineContacts FromExtremes(TScalar first, TScalar second, TScalar third) { if(first < second) { if(third < first) { return LineContacts(third, second); // third - first - second } else if(third < second) { return LineContacts(first, second); // first - third - second } else { return LineContacts(first, third); // first - second - third } } else { if(third < second) { return LineContacts(third, first); // third - second - first } else if(third < first) { return LineContacts(second, first); // second - third - first } else { return LineContacts(second, third); // second - first - third } } } /// Whether the line has missed the shape /// True if the line has missed the shape, otherwise false public: bool HasMissed() const { return Math::IsNan(this->EntryTime); } /// Whether the line has missed the shape /// True if the line has missed the shape, otherwise false public: bool HasHit() const { return !Math::IsNan(this->EntryTime); } /// Time at which the line has entered the shape public: TScalar EntryTime; /// Time at which the line has entered the shape public: TScalar ExitTime; }; // ------------------------------------------------------------------------------------------- // template const LineContacts LineContacts::None( std::numeric_limits::signaling_NaN(), std::numeric_limits::signaling_NaN() ); // ------------------------------------------------------------------------------------------- // }} // namespace Nuclex::Geometry #endif // NUCLEX_GEOMETRY_LINECONTACTS_H