#region CPL License /* Nuclex Framework Copyright (C) 2002-2009 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 */ #endregion using System; using System.Collections.Generic; namespace Nuclex.Geometry.Lines { /// /// Stores the times of first and last contact determined in an intersection test /// public struct LineContacts { /// Initializes a new contact point /// Time the contact was made at public LineContacts(float touchTime) : this(touchTime, touchTime) { } /// Initializes a new contact point /// Time the first contact was made at /// Time the last contact has occured public LineContacts(float entryTime, float exitTime) { this.EntryTime = entryTime; this.ExitTime = exitTime; } // TEMP! /// Converts a line contact record into a floating point array /// Contact record that will be converted /// The resulting floating point array public static implicit operator float[](LineContacts contacts) { if(float.IsNaN(contacts.EntryTime)) { return null; } else { return new float[2] { contacts.EntryTime, contacts.ExitTime }; } } /// Whether a contact is stored in the line contacts instance public bool HasContact { get { return !float.IsNaN(EntryTime); } } /// /// Determines whether this instance is identical to another instance /// /// Other instance of compare against /// True if both instances are identical public override bool Equals(object otherObject) { if(!(otherObject is LineContacts)) { return false; } LineContacts other = (LineContacts)otherObject; return (this.EntryTime == other.EntryTime) && (this.ExitTime == other.ExitTime); } /// Returns a hash code for the instance /// The instance's hash code public override int GetHashCode() { return this.EntryTime.GetHashCode() ^ this.ExitTime.GetHashCode(); } /// A line contacts instance for reporting no contacts public static readonly LineContacts None = new LineContacts(float.NaN, float.NaN); /// Time the first contact was made public float EntryTime; /// Time the last contact occurred public float ExitTime; } } // namespace Nuclex.Geometry.Lines