HighMap library (C++)
Loading...
Searching...
No Matches
cell_path.hpp
Go to the documentation of this file.
1/* Copyright (c) 2026 Otto Link. Distributed under the terms of the GNU General
2 Public License. The full license is in the file LICENSE, distributed with
3 this software. */
4
11#pragma once
12#include <vector>
13
14#include <glm/glm.hpp>
15
16#include "highmap/functions.hpp"
17
18namespace hmap
19{
20
28{
29public:
30 // ==========================================================================
31 // Constructors
32 // ==========================================================================
33
37 CellPath() = default;
38
43 CellPath(const std::vector<glm::ivec2> &indices);
44
49 CellPath(std::vector<glm::ivec2> &&indices) noexcept;
50
51 // ==========================================================================
52 // Container interface
53 // ==========================================================================
54
58 std::vector<glm::ivec2>::iterator begin() noexcept;
59
63 std::vector<glm::ivec2>::const_iterator begin() const noexcept;
64
68 std::vector<glm::ivec2>::iterator end() noexcept;
69
73 std::vector<glm::ivec2>::const_iterator end() const noexcept;
74
78 glm::ivec2 &front();
79
83 const glm::ivec2 &front() const;
84
88 glm::ivec2 &back();
89
93 const glm::ivec2 &back() const;
94
99 glm::ivec2 &operator[](size_t index);
100
105 const glm::ivec2 &operator[](size_t index) const;
106
110 void clear() noexcept;
111
116 bool empty() const noexcept;
117
122 void push_back(const glm::ivec2 &idx);
123
128 size_t size() const noexcept;
129
134 std::vector<glm::ivec2> &get_indices();
135
140 const std::vector<glm::ivec2> &get_indices() const;
141
142private:
143 std::vector<glm::ivec2> indices;
144};
145
157void add_line_bresenham(CellPath &out, glm::ivec2 a, glm::ivec2 b);
158
182void add_noise(CellPath &path,
183 std::uint32_t seed,
184 float kw,
185 float amp,
186 const glm::ivec2 &shape,
187 NoiseType noise_type = NoiseType::PERLIN,
188 int octaves = 8,
189 float weight = 0.7f,
190 float persistence = 0.5f,
191 float lacunarity = 2.f);
192
202
212bool is_path_adjacent(const CellPath &path);
213
214} // namespace hmap
bool empty() const noexcept
Check whether the cell path is empty.
Definition cell_path.cpp:47
size_t size() const noexcept
Get the number of cells in the path.
Definition cell_path.cpp:97
std::vector< glm::ivec2 >::iterator end() noexcept
Return an iterator to the end.
Definition cell_path.cpp:52
void push_back(const glm::ivec2 &idx)
Add a cell index to the end of the path.
Definition cell_path.cpp:92
glm::ivec2 & front()
Access the first element.
Definition cell_path.cpp:62
CellPath()=default
Construct a new CellPath object.
glm::ivec2 & back()
Access the last element.
Definition cell_path.cpp:22
std::vector< glm::ivec2 >::iterator begin() noexcept
Return an iterator to the beginning.
Definition cell_path.cpp:32
void clear() noexcept
Clear all cell indices.
Definition cell_path.cpp:42
std::vector< glm::ivec2 > & get_indices()
Get the cell indices.
Definition cell_path.cpp:72
float f(int i, float gi)
Definition distance_transform.cpp:14
Definition opencv.hpp:20
void enforce_path_adjacency(CellPath &path)
Ensures that an integer path is grid-adjacent and gap-free.
Definition add_noise.cpp:121
void add_line_bresenham(CellPath &out, glm::ivec2 a, glm::ivec2 b)
Rasterizes a segment between two integer points using Bresenham's algorithm.
Definition add_noise.cpp:21
bool is_path_adjacent(const CellPath &path)
Checks if a grid path has no gaps (8-connectivity).
Definition add_noise.cpp:154
NoiseType
Enumeration of various noise types used for procedural generation.
Definition functions.hpp:67
@ PERLIN
Perlin.
Definition functions.hpp:69
void add_noise(CellPath &path, std::uint32_t seed, float kw, float amp, const glm::ivec2 &shape, NoiseType noise_type=NoiseType::PERLIN, int octaves=8, float weight=0.7f, float persistence=0.5f, float lacunarity=2.f)
Applies transverse noise displacement along an integer path.
Definition add_noise.cpp:56