QmlMaterial 0.1.0
Loading...
Searching...
No Matches
corner_fan.hpp
1#pragma once
2
3#include <QRectF>
4#include <QVector4D>
5
6namespace qml_material::sg::mesh
7{
8
17 int corner_index;
18 float outer_x, outer_y;
19 float inner_x, inner_y;
20 float arc_x, arc_y;
21 float sign_x, sign_y;
22 float radius;
23};
24
27template<class Fn>
28void for_each_rrect_corner(const QRectF& bounds, QVector4D radius, float inset, Fn&& fn) {
29 const float L = bounds.left();
30 const float R = bounds.right();
31 const float T = bounds.top();
32 const float B = bounds.bottom();
33
34 // Corner layout matches the existing TL/TR/BL/BR convention used throughout.
35 const struct {
36 int idx;
37 float ox, oy; // outer rect corner
38 float sx, sy; // outward sign
39 } sides[4] = {
40 { 0, L, T, -1.0f, -1.0f },
41 { 1, R, T, +1.0f, -1.0f },
42 { 2, L, B, -1.0f, +1.0f },
43 { 3, R, B, +1.0f, +1.0f },
44 };
45
46 for (auto const& s : sides) {
47 const float r = radius[s.idx];
48 rrect_corner c {
49 .corner_index = s.idx,
50 .outer_x = s.ox,
51 .outer_y = s.oy,
52 .inner_x = s.ox - s.sx * inset,
53 .inner_y = s.oy - s.sy * inset,
54 .arc_x = s.ox - s.sx * r,
55 .arc_y = s.oy - s.sy * r,
56 .sign_x = s.sx,
57 .sign_y = s.sy,
58 .radius = r,
59 };
60 fn(c);
61 }
62}
63
64} // namespace qml_material::sg::mesh
Definition corner_fan.hpp:16