src/noise/surface_noise.cpp
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // SPDX-License-Identifier: BSD-3-Clause | ||
| 2 | |||
| 3 | #include "terraingen/noise/surface_noise.h" | ||
| 4 | |||
| 5 | #include "noise/fractal_rows.h" | ||
| 6 | |||
| 7 | namespace terraingen { | ||
| 8 | |||
| 9 | 5278536 | float FractalStackAt(const std::vector<Fractal>& fractals, const Vec2d& origin, | |
| 10 | const Surface& surface, double x, double y) { | ||
| 11 | 5278536 | if (fractals.empty()) { | |
| 12 | return 0.0f; | ||
| 13 | } | ||
| 14 | 1289501 | if (surface.IsBody()) { | |
| 15 | 503629 | const Vec3d p = surface.Position({x, y}); | |
| 16 | 503620 | return EvaluateFractals3(p.x, p.y, p.z, fractals.data(), fractals.size()); | |
| 17 | } | ||
| 18 | 785872 | return EvaluateFractals(static_cast<float>(x - origin.x), static_cast<float>(y - origin.y), | |
| 19 | 820533 | fractals.data(), fractals.size()); | |
| 20 | } | ||
| 21 | |||
| 22 | 2337153 | void FractalStackRows(const std::vector<Fractal>& fractals, const Vec2d& origin, | |
| 23 | const Surface& surface, Span<const Vec2d> points, Span<float> heights) { | ||
| 24 | 2337153 | if (fractals.empty() || surface.IsBody()) { | |
| 25 | 1434408 | for (std::size_t i = 0; i < points.size(); ++i) { | |
| 26 | 1340423 | heights[i] = FractalStackAt(fractals, origin, surface, points[i].x, points[i].y); | |
| 27 | } | ||
| 28 | 93985 | return; | |
| 29 | } | ||
| 30 | 2243174 | std::vector<float> xs(points.size()); | |
| 31 | 2244260 | std::vector<float> ys(points.size()); | |
| 32 | 12152301 | for (std::size_t i = 0; i < points.size(); ++i) { | |
| 33 | 9906600 | xs[i] = static_cast<float>(points[i].x - origin.x); | |
| 34 | 9910598 | ys[i] = static_cast<float>(points[i].y - origin.y); | |
| 35 | } | ||
| 36 | 2245701 | EvaluateFractalsRows(xs, ys, fractals.data(), fractals.size(), heights); | |
| 37 | 2238954 | } | |
| 38 | |||
| 39 | } // namespace terraingen | ||
| 40 |