// // Distributed under the BSD Licence (see LICENCE file). // // Copyright (c) 2014, Nition, http://www.momentstudio.co.nz/ // Copyright (c) 2017, Máté Cserép, http://codenet.hu // All rights reserved. // namespace Octree { using System; using System.Runtime.Serialization; /// /// Representation of rays. /// /// /// A ray is an infinite line starting at and going in some . /// /// This class was inspired by the Ray type of the Unity Engine and /// designed with the exact same interface to provide maximum compatibility. /// public struct Ray { /// /// Gets or sets the origin of the ray. /// public Point Origin { get; set; } /// /// The direction of the ray. /// private Point _direction; /// /// Gets or sets the direction of the ray. /// public Point Direction { get { return _direction; } set { _direction = value.Normalized; } } /// /// Creates a ray starting at origin along direction. /// /// The origin of the ray. /// The direction of the ray. public Ray(Point origin, Point direction) { Origin = origin; _direction = direction.Normalized; } /// /// Returns a point at the given distance along the ray. /// /// The distance. /// The point on the ray. public Point GetPoint(double distance) { return Origin + Direction * distance; } /// /// Returns a nicely formatted string for this ray. /// public override string ToString() { return String.Format("Origin: {0}, Dir: {1}", Origin, Direction ); } /// /// Returns a nicely formatted string for this ray. /// /// The format for the origin and direction. public string ToString(string format) { return String.Format("Origin: {0}, Dir: {1}", Origin.ToString(format), Direction.ToString(format) ); } } }