./
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
11 / 11
100.0%
Branches:
6 / 6
100.0%
Functions:
2 / 2
100.0%

src/layers/anchored_plane.cpp
Line Branch Exec Source
1 // SPDX-License-Identifier: BSD-3-Clause
2
3 #include "terraingen/layers/anchored_plane.h"
4
5 namespace terraingen {
6
7 9212015 AnchoredPlane::AnchoredPlane(const Surface& surface, const Vec2d& anchor)
8 9212015 : m_surface(&surface), m_anchor(anchor) {
9
2/2
✓ Branch 0 taken 13 times.
✓ Branch 1 taken 9212002 times.
9212015 if (m_surface->IsBody()) {
10 13 m_direction = UnitVector(m_anchor.x, m_anchor.y);
11 }
12 9212015 }
13
14 9211973 std::optional<Vec2d> AnchoredPlane::Project(double x, double y) const {
15
2/2
✓ Branch 0 taken 9211958 times.
✓ Branch 1 taken 15 times.
9211973 if (!m_surface->IsBody()) {
16 9211958 return Vec2d{x, y};
17 }
18
2/2
✓ Branch 1 taken 7 times.
✓ Branch 2 taken 8 times.
15 if (Dot(UnitVector(x, y), m_direction) <= 0.0) {
19 7 return std::nullopt;
20 }
21 8 return m_surface->Offset(m_anchor, {x, y});
22 }
23
24 } // namespace terraingen
25