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 | 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 | 9211973 | if (!m_surface->IsBody()) { | |
| 16 | 9211958 | return Vec2d{x, y}; | |
| 17 | } | ||
| 18 | 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 |