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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
//! # 🎲 Tiles Tools
//! # 🎲 Tiles Tools
//!
//! **High-Performance Tile-Based Game Development Toolkit**
//!
//! A comprehensive, generic, and extensible Rust crate for developing sophisticated
//! tile-based games and applications. This crate provides a complete toolkit for
//! working with multiple coordinate systems, pathfinding, ECS integration, and
//! advanced grid-based algorithms.
//!
//! ## ✨ Core Features
//!
//! - **🗺️ Universal Coordinate Systems**: Hexagonal, Square, Triangular, Isometric, and Pixel coordinates
//! - **🔄 Seamless Conversions**: Exact and approximate conversions between coordinate systems
//! - **🧭 Advanced Pathfinding**: A* algorithm optimized for all coordinate systems
//! - **⚡ ECS Integration**: Complete Entity-Component-System with game-specific components
//! - **👁️ Field of View**: Multiple FOV algorithms including shadowcasting and raycasting
//! - **🌊 Flow Fields**: Efficient multi-unit pathfinding and crowd simulation
//! - **🎯 Grid Collections**: Type-safe, high-performance grid data structures
//! - **🚀 Zero-Cost Abstractions**: Performance-focused design with compile-time optimizations
//!
//! ## 🚀 Quick Start
//!
//! ### Hexagonal Grids
//! ```rust
//! use tiles_tools::coordinates::hexagonal::{ Coordinate, Axial, Pointy };
//! use tiles_tools::coordinates::{ Distance, Neighbors };
//!
//! let coord = Coordinate::<Axial, Pointy>::new(2, -1);
//! let other_coord = Coordinate::<Axial, Pointy>::new(5, 1);
//! let distance = coord.distance(other_coord); // Hexagonal distance
//! let neighbors = coord.neighbors(); // 6 surrounding hexes
//! assert_eq!(neighbors.len(), 6);
//! ```
//!
//! ### Universal Pathfinding
//! ```rust
//! use tiles_tools::pathfind::astar;
//! use tiles_tools::coordinates::square::{ Coordinate, FourConnected };
//!
//! let start = Coordinate::<FourConnected>::new(0, 0);
//! let goal = Coordinate::<FourConnected>::new(10, 10);
//!
//! if let Some((path, cost)) = astar(&start, &goal, |_| true, |_| 1) {
//! println!("Found path with cost: {}", cost);
//! }
//! ```
//!
//! ### ECS Game Development
//! ```rust
//! # #[ cfg( feature = "enabled" ) ]
//! # {
//! use tiles_tools::ecs::{ World, Position, Health, Movable };
//! use tiles_tools::coordinates::square::{ Coordinate, FourConnected };
//!
//! let mut world = World::new();
//! let player = world.spawn((
//! Position::new(Coordinate::<FourConnected>::new(0, 0)),
//! Health::new(100),
//! Movable::new(3),
//! ));
//! # }
//! ```
//!
//! ## 🎮 Coordinate Systems
//!
//! All coordinate systems implement the [`Distance`](coordinates::Distance) and
//! [`Neighbors`](coordinates::Neighbors) traits, providing a uniform interface:
//!
//! - **Hexagonal**: Perfect for strategy games and organic movement patterns
//! - **Square**: Classic grid games with 4 or 8-connected movement
//! - **Triangular**: Unique tessellation with rich neighbor relationships
//! - **Isometric**: Pseudo-3D visualization for RPGs and city builders
//! - **Pixel**: Screen-space coordinates for rendering and input handling
//!
//! ## 🔄 Coordinate Conversions
//!
//! Convert between coordinate systems with exact or approximate transformations:
//!
//! ```rust
//! use tiles_tools::coordinates::conversion::{ Convert, ApproximateConvert };
//! use tiles_tools::coordinates::{
//! square::{ Coordinate as Square, FourConnected },
//! isometric::{ Coordinate as Iso, Diamond }
//! };
//!
//! let square = Square::<FourConnected>::new(3, 4);
//! let iso: Iso<Diamond> = square.convert(); // Exact conversion
//! let back: Square<FourConnected> = iso.convert(); // Perfect roundtrip
//! assert_eq!(square, back);
//! ```
//!
//! ## 📦 Feature Flags
//!
//! - **`enabled`** (default): Core functionality with all coordinate systems
//! - **`full`**: All features for maximum functionality
//! - **`ecs-systems`**: Enhanced ECS components and systems
//! - **`serialization`**: Serde support for save/load functionality
//! - **`pathfinding-algorithms`**: A* and other pathfinding algorithms
//! - **`field-of-view`**: Line of sight and visibility calculations
//! - **`flow-fields`**: Multi-unit pathfinding and crowd behavior
//!
//! ## 🏗️ Architecture
//!
//! This crate is built on solid architectural principles:
//!
//! - **Generic Design**: All algorithms work across coordinate systems
//! - **Zero-Cost Abstractions**: Compile-time polymorphism for performance
//! - **Modular Structure**: Use only the components you need
//! - **Type Safety**: Prevent coordinate system mixing errors at compile time
//! - **Memory Efficiency**: Cache-friendly data structures and algorithms