1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
//! # Structured Point Grids and Quadrilateral Extraction
//!
//! Tools for working with structured grids of points and extracting quadrilateral
//! meshes from them. Useful for creating regular tessellations, distorted grids,
//! and structured patterns in generative art.
//!
//! ## Key Features
//!
//! - **[`Grid`]**: Structured grid of points with quadrilateral extraction
//! - **[`Quadrilateral`]**: Four-point geometric primitive for mesh generation
//! - **Spatial filtering**: Extract quads within specific boundary conditions
//!
//! ## Basic Usage
//!
//! ```no_run
//! use wassily_geometry::*;
//! use wassily_core::points::pt;
//!
//! // Create a matrix of points
//! let points_matrix = Matrix::generate(3, 3, |i, j| {
//! pt(j as f32 * 10.0, i as f32 * 10.0)
//! });
//!
//! let grid = Grid { grid: points_matrix };
//!
//! // Extract all quadrilaterals
//! let quads = grid.quads();
//! assert_eq!(quads.len(), 4); // (3-1) × (3-1) = 4 quads
//!
//! // Filter quads within bounds
//! let bounded_quads = grid.quads_inside(50.0, 50.0);
//! ```
use crate*;
use Point;
/// **Structured grid of points for quadrilateral mesh generation.**
///
/// A `Grid` represents a structured arrangement of points in a matrix format,
/// where adjacent points can be connected to form quadrilateral elements.
/// This is essential for creating regular tessellations, deformed grids,
/// and structured geometric patterns.
///
/// ## Structure
///
/// Points are arranged in a matrix where:
/// - `grid[i][j]` represents the point at row i, column j
/// - Each 2×2 submatrix of points defines one quadrilateral
/// - Grid with m×n points produces (m-1)×(n-1) quadrilaterals
///
/// ## Example
///
/// ```no_run
/// use wassily_geometry::*;
/// use wassily_core::points::pt;
///
/// // Create 3×3 regular grid
/// let grid_matrix = Matrix::generate(3, 3, |i, j| {
/// pt(j as f32 * 20.0, i as f32 * 20.0)
/// });
/// let grid = Grid { grid: grid_matrix };
///
/// // Extract 2×2 = 4 quadrilaterals
/// let quads = grid.quads();
/// ```
/// **Four-point quadrilateral in counter-clockwise order.**
///
/// Represents a quadrilateral defined by four corner points arranged as:
/// `[bottom_left, top_left, top_right, bottom_right]`
///
/// This ordering ensures consistent winding for rendering and geometric operations.
pub type Quadrilateral = ;