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#include "Math/BsLine2.h"
4#include "Math/BsMath.h"
5
6namespace bs
7{
8 std::pair<bool, float> Line2::intersects(const Line2& rhs) const
9 {
10 Vector2 diff = rhs.getOrigin() - getOrigin();
11 Vector2 perpDir = rhs.getDirection();
12 perpDir = Vector2(perpDir.y, -perpDir.x);
13
14 float dot = getDirection().dot(perpDir);
15 if (std::abs(dot) > 1.0e-4f) // Not parallel
16 {
17 float distance = diff.dot(perpDir) / dot;
18
19 return std::make_pair(true, distance);
20 }
21 else // Parallel
22 return std::make_pair(true, 0.0f);
23 }
24}