MayaFlux 0.4.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
Geometry2D.hpp
Go to the documentation of this file.
1#pragma once
2
5
6namespace MayaFlux::Kinesis {
7
8// =============================================================================
9// Filled shapes — Kakshya::Vertex, TRIANGLE_LIST topology
10//
11// All coordinates are 2D NDC (z = 0). These produce vertex arrays suitable
12// for direct use with write_verts / FormaBuffer::submit / create_buffer.
13// No index buffer is required; triangle fan decomposition is inlined.
14// =============================================================================
15
16/**
17 * @brief Filled circle as a TRIANGLE_LIST triangle fan.
18 *
19 * Decomposes into (segments) triangles sharing a common center vertex.
20 * Minimum @p segments is 3; values below are clamped.
21 *
22 * @param center Circle center in NDC.
23 * @param radius Radius in NDC units.
24 * @param segments Triangle count around the circumference.
25 * @param color Uniform fill color.
26 */
27[[nodiscard]] MAYAFLUX_API std::vector<Kakshya::Vertex> filled_circle(
28 glm::vec2 center,
29 float radius,
30 uint32_t segments,
31 glm::vec3 color = glm::vec3(1.F));
32
33/**
34 * @brief Filled annulus (ring) as a TRIANGLE_LIST quad strip.
35 *
36 * Produces two triangles per angular segment between @p inner_r and
37 * @p outer_r. Minimum @p segments is 3.
38 *
39 * @param center Ring center in NDC.
40 * @param inner_r Inner radius in NDC units.
41 * @param outer_r Outer radius in NDC units.
42 * @param segments Quad count around the circumference.
43 * @param color Uniform fill color.
44 */
45[[nodiscard]] MAYAFLUX_API std::vector<Kakshya::Vertex> filled_ring(
46 glm::vec2 center,
47 float inner_r,
48 float outer_r,
49 uint32_t segments,
50 glm::vec3 color = glm::vec3(1.F));
51
52/**
53 * @brief Filled regular n-gon as a TRIANGLE_LIST triangle fan.
54 *
55 * Vertices are placed on a circle of @p radius, starting at
56 * @p rotation_rad from +X, CCW. Minimum @p sides is 3.
57 *
58 * @param center Polygon center in NDC.
59 * @param radius Circumradius in NDC units.
60 * @param sides Number of sides. Clamped to minimum 3.
61 * @param rotation_rad Starting angle in radians from +X axis.
62 * @param color Uniform fill color.
63 */
64[[nodiscard]] MAYAFLUX_API std::vector<Kakshya::Vertex> filled_polygon(
65 glm::vec2 center,
66 float radius,
67 uint32_t sides,
68 float rotation_rad = 0.F,
69 glm::vec3 color = glm::vec3(1.F));
70
71/**
72 * @brief Filled rect with per-corner colors, TRIANGLE_STRIP (4 vertices).
73 *
74 * Vertex order matches filled_rect: BL, BL-top, BR, BR-top (TRIANGLE_STRIP).
75 * Drop-in replacement for filled_rect when a gradient fill is needed.
76 *
77 * @param region NDC axis-aligned bounds.
78 * @param color_bl Bottom-left corner color.
79 * @param color_br Bottom-right corner color.
80 * @param color_tl Top-left corner color.
81 * @param color_tr Top-right corner color.
82 */
83[[nodiscard]] MAYAFLUX_API std::array<Kakshya::Vertex, 4> filled_rect_gradient(
84 AABB2D region,
85 glm::vec3 color_bl,
86 glm::vec3 color_br,
87 glm::vec3 color_tl,
88 glm::vec3 color_tr);
89
90/**
91 * @brief Filled rounded rectangle as a TRIANGLE_LIST mesh.
92 *
93 * Composed of a center rect, four edge rects, and four corner fans.
94 * @p corner_radius is clamped to half the shorter axis to prevent overlap.
95 * Minimum @p corner_segments is 1.
96 *
97 * @param region NDC axis-aligned bounds.
98 * @param corner_radius Radius of each rounded corner in NDC units.
99 * @param corner_segments Triangle count per quarter-circle corner arc.
100 * @param color Uniform fill color.
101 */
102[[nodiscard]] MAYAFLUX_API std::vector<Kakshya::Vertex> filled_rounded_rect(
103 AABB2D region,
104 float corner_radius,
105 uint32_t corner_segments,
106 glm::vec3 color = glm::vec3(1.F));
107
108/**
109 * @brief Filled circular arc sector (pie slice) as a TRIANGLE_LIST fan.
110 *
111 * @p angle_start and @p angle_end are in radians, measured from +X CCW.
112 * Minimum @p segments is 1.
113 *
114 * @param center Arc center in NDC.
115 * @param radius Radius in NDC units.
116 * @param angle_start Start angle in radians.
117 * @param angle_end End angle in radians.
118 * @param segments Triangle count over the arc span.
119 * @param color Uniform fill color.
120 */
121[[nodiscard]] MAYAFLUX_API std::vector<Kakshya::Vertex> filled_arc(
122 glm::vec2 center,
123 float radius,
124 float angle_start,
125 float angle_end,
126 uint32_t segments,
127 glm::vec3 color = glm::vec3(1.F));
128
129/**
130 * @brief Sample a circular arc as ordered NDC positions.
131 *
132 * Produces @p segments + 1 points along the arc from @p angle_start to
133 * @p angle_end, suitable as path input to stroke_slider or any other
134 * function consuming a @c span<const glm::vec2> path.
135 *
136 * @param center Arc center in NDC.
137 * @param radius_x Horizontal radius in NDC units.
138 * @param radius_y Vertical radius in NDC units (use == radius_x for a circle).
139 * @param angle_start Start angle in radians from +X, CCW.
140 * @param angle_end End angle in radians from +X, CCW.
141 * @param segments Number of segments; produces segments+1 points.
142 */
143[[nodiscard]] MAYAFLUX_API std::vector<glm::vec2> arc_path(
144 glm::vec2 center,
145 float radius_x,
146 float radius_y,
147 float angle_start,
148 float angle_end,
149 uint32_t segments);
150
151// =============================================================================
152// Outlines — Kakshya::LineVertex, LINE_LIST topology
153//
154// Each function produces adjacent vertex pairs for LINE_LIST draw.
155// LINE_STRIP callers can use every other vertex as the strip is equivalent
156// for these closed/open forms, but LINE_LIST is the canonical output to
157// match the existing Forma pipeline (radial, stroke_slider precedent).
158// =============================================================================
159
160/**
161 * @brief Circle outline as a LINE_LIST (closed loop, 2 * segments vertices).
162 *
163 * Each segment is one line: [ring[i], ring[(i+1) % segments]].
164 * Minimum @p segments is 3.
165 *
166 * @param center Circle center in NDC.
167 * @param radius Radius in NDC units.
168 * @param segments Edge count around the circumference.
169 * @param color Uniform line color.
170 * @param thickness Line thickness (maps to LineVertex::thickness).
171 */
172[[nodiscard]] MAYAFLUX_API std::vector<Kakshya::LineVertex> circle_outline(
173 glm::vec2 center,
174 float radius,
175 uint32_t segments,
176 glm::vec3 color = glm::vec3(1.F),
177 float thickness = 1.F);
178
179/**
180 * @brief Arc outline as a LINE_LIST (open curve, 2 * segments vertices).
181 *
182 * @p angle_start and @p angle_end are in radians from +X, CCW.
183 * Minimum @p segments is 1.
184 *
185 * @param center Arc center in NDC.
186 * @param radius Radius in NDC units.
187 * @param angle_start Start angle in radians.
188 * @param angle_end End angle in radians.
189 * @param segments Edge count over the arc span.
190 * @param color Uniform line color.
191 * @param thickness Line thickness.
192 */
193[[nodiscard]] MAYAFLUX_API std::vector<Kakshya::LineVertex> arc_outline(
194 glm::vec2 center,
195 float radius,
196 float angle_start,
197 float angle_end,
198 uint32_t segments,
199 glm::vec3 color = glm::vec3(1.F),
200 float thickness = 1.F);
201
202/**
203 * @brief Rectangle outline as a LINE_LIST (4 edges, 8 vertices).
204 *
205 * @param region NDC axis-aligned bounds.
206 * @param color Uniform line color.
207 * @param thickness Line thickness.
208 */
209[[nodiscard]] MAYAFLUX_API std::array<Kakshya::LineVertex, 8> rect_outline(
210 AABB2D region,
211 glm::vec3 color = glm::vec3(1.F),
212 float thickness = 1.F);
213
214/**
215 * @brief Polyline as a LINE_LIST (open path, 2 * (pts.size() - 1) vertices).
216 *
217 * Converts a span of NDC vec2 positions into adjacent LineVertex pairs.
218 * Suitable for waveform traces, cable routes, and arbitrary open curves.
219 *
220 * @param pts Ordered path vertices in NDC.
221 * @param color Uniform line color.
222 * @param thickness Line thickness.
223 */
224[[nodiscard]] MAYAFLUX_API std::vector<Kakshya::LineVertex> polyline(
225 std::span<const glm::vec2> pts,
226 glm::vec3 color = glm::vec3(1.F),
227 float thickness = 1.F);
228
229/**
230 * @brief Polyline with per-vertex colors as a LINE_LIST.
231 *
232 * @p pts and @p colors must have equal length. Each line segment blends
233 * from the color at its start vertex to the color at its end vertex.
234 *
235 * @param pts Ordered path vertices in NDC.
236 * @param colors Per-vertex colors. Must match @p pts in size.
237 * @param thickness Line thickness applied uniformly.
238 */
239[[nodiscard]] MAYAFLUX_API std::vector<Kakshya::LineVertex> polyline_colored(
240 std::span<const glm::vec2> pts,
241 std::span<const glm::vec3> colors,
242 float thickness = 1.F);
243
244/**
245 * @brief Regular n-gon outline as a LINE_LIST (closed loop, 2 * sides vertices).
246 *
247 * @param center Polygon center in NDC.
248 * @param radius Circumradius in NDC units.
249 * @param sides Side count. Clamped to minimum 3.
250 * @param rotation_rad Starting angle in radians from +X axis.
251 * @param color Uniform line color.
252 * @param thickness Line thickness.
253 */
254[[nodiscard]] MAYAFLUX_API std::vector<Kakshya::LineVertex> polygon_outline(
255 glm::vec2 center,
256 float radius,
257 uint32_t sides,
258 float rotation_rad = 0.F,
259 glm::vec3 color = glm::vec3(1.F),
260 float thickness = 1.F);
261
262} // namespace MayaFlux::Kinesis
std::vector< Kakshya::LineVertex > polygon_outline(glm::vec2 center, float radius, uint32_t sides, float rotation_rad, glm::vec3 color, float thickness)
Regular n-gon outline as a LINE_LIST (closed loop, 2 * sides vertices).
std::vector< Kakshya::Vertex > filled_circle(glm::vec2 center, float radius, uint32_t segments, glm::vec3 color)
Filled circle as a TRIANGLE_LIST triangle fan.
std::vector< Kakshya::Vertex > filled_ring(glm::vec2 center, float inner_r, float outer_r, uint32_t segments, glm::vec3 color)
Filled annulus (ring) as a TRIANGLE_LIST quad strip.
std::array< Kakshya::Vertex, 4 > filled_rect_gradient(AABB2D region, glm::vec3 color_bl, glm::vec3 color_br, glm::vec3 color_tl, glm::vec3 color_tr)
Filled rect with per-corner colors, TRIANGLE_STRIP (4 vertices).
std::array< Kakshya::LineVertex, 8 > rect_outline(AABB2D region, glm::vec3 color, float thickness)
Rectangle outline as a LINE_LIST (4 edges, 8 vertices).
std::vector< Kakshya::LineVertex > arc_outline(glm::vec2 center, float radius, float angle_start, float angle_end, uint32_t segments, glm::vec3 color, float thickness)
Arc outline as a LINE_LIST (open curve, 2 * segments vertices).
std::vector< Kakshya::LineVertex > polyline(std::span< const glm::vec2 > pts, glm::vec3 color, float thickness)
Polyline as a LINE_LIST (open path, 2 * (pts.size() - 1) vertices).
std::vector< Kakshya::LineVertex > circle_outline(glm::vec2 center, float radius, uint32_t segments, glm::vec3 color, float thickness)
Circle outline as a LINE_LIST (closed loop, 2 * segments vertices).
std::vector< Kakshya::Vertex > filled_polygon(glm::vec2 center, float radius, uint32_t sides, float rotation_rad, glm::vec3 color)
Filled regular n-gon as a TRIANGLE_LIST triangle fan.
std::vector< Kakshya::Vertex > filled_arc(glm::vec2 center, float radius, float angle_start, float angle_end, uint32_t segments, glm::vec3 color)
Filled circular arc sector (pie slice) as a TRIANGLE_LIST fan.
std::vector< Kakshya::Vertex > filled_rounded_rect(AABB2D region, float corner_radius, uint32_t corner_segments, glm::vec3 color)
Filled rounded rectangle as a TRIANGLE_LIST mesh.
std::vector< Kakshya::LineVertex > polyline_colored(std::span< const glm::vec2 > pts, std::span< const glm::vec3 > colors, float thickness)
Polyline with per-vertex colors as a LINE_LIST.
std::vector< glm::vec2 > arc_path(glm::vec2 center, float radius_x, float radius_y, float angle_start, float angle_end, uint32_t segments)
Sample a circular arc as ordered NDC positions.