1//************************************ bs::framework - Copyright 2018 Marko Pintera **************************************//
2//*********** Licensed under the MIT license. See LICENSE.md for full terms. This notice is not to be removed. ***********//
3#pragma once
4
5#include "Prerequisites/BsPrerequisitesUtil.h"
6#include "Math/BsVector3.h"
7
8namespace bs
9{
10 /** @addtogroup Math
11 * @{
12 */
13
14 /** Represents a line segment in three dimensional space defined by a start and an end point. */
15 class BS_UTILITY_EXPORT LineSegment3
16 {
17 public:
18 LineSegment3() = default;
19 LineSegment3(const Vector3& start, const Vector3& end);
20
21 /**
22 * Find the nearest point on the line segment and the provided ray.
23 *
24 * @return Set of nearest points and distance from the points. First nearest point is a point along the ray,
25 * while the second is along the line segment.
26 *
27 * @note If segment and ray are parallel the set of points at the segment origin are returned.
28 */
29 std::pair<std::array<Vector3, 2>, float> getNearestPoint(const Ray& ray) const;
30
31 /** Returns the length of the line segment. */
32 float getLength() const { return start.distance(end); }
33
34 /** Returns the center point along the line segment. */
35 Vector3 getCenter() const { return start + (end - start) * 0.5f; }
36
37 Vector3 start = BsZero;
38 Vector3 end = BsZero;
39 };
40
41 /** @} */
42}
43