redid it library style

This commit is contained in:
2026-03-16 22:27:33 +01:00
parent 1192350b3c
commit cedd29e96e
10 changed files with 840 additions and 129 deletions

109
ReadMe.md
View File

@@ -1,26 +1,111 @@
# Redoal
> Defeating the DNS hedgemony through path comparisons of all possibilties of the curve on a DHT
> Gesture indexing math library for generating stable index keys from gestures
A library to quantize input path data as a search tree enabling the core functionality of a DHT to be used for path comparisons.
A library focused purely on gesture indexing mathematics for DHT-based path comparisons and similarity search.
Local cache
## Core Capabilities
# What it does
1. **Gesture Normalization** - Remove translation and scale variations
2. **Path Resampling** - Fixed number of evenly spaced points
3. **Shape Descriptors** - Hu invariant moments for shape characterization
4. **Spectral Embeddings** - Laplacian eigenvalues for gesture signature
5. **Dimensionality Reduction** - PCA for feature compression
6. **Spatial Indexing** - Morton/Z-order curve for integer keys
1. Optionally we asyncronously preprocess input data, normalize, center weight and ensure it's not out of bounds, as a turning function.
## Usage Example
2. Cluster path data into a k-d tree.
### Creating a Gesture Key for DHT
3. Indexing - Store the tree coordinates in a hashmap with a unique key.
```rust
use redoal::*;
4. Query Processing - Query the tree for the nearest neighbor.
fn main() {
// Load or create a gesture (sequence of points)
let gesture = vec![
Point::new(0.0, 0.0),
Point::new(1.0, 0.0),
Point::new(0.5, 1.0),
Point::new(0.0, 0.5),
];
// Normalize the gesture (remove translation and scale)
let normalized = normalize(&gesture);
// Resample to fixed number of points for consistency
let resampled = resample(&normalized, 64);
// Compute spectral signature
let spectral = spectral_signature(&resampled, 4);
# Deserialize and Serialize
To encode and decode path data from
// Create Morton code for DHT key
let key = morton2(
(spectral[0] * 1000.0) as u32,
(spectral[1] * 1000.0) as u32
);
# Testing
println!("Gesture key: {}", key);
}
```
Visual tests can render and offer manual input data input that renders using the lyon crate.
### Similarity Search
```rust
use redoal::*;
fn find_similar_gestures(query: &[Point], database: &[(&str, Vec<Point>)]) -> Vec<(&str, f64)> {
// Normalize and resample query
let query_norm = normalize(query);
let query_resamp = resample(&query_norm, 64);
let query_spectral = spectral_signature(&query_resamp, 4);
// Compute similarity for each gesture in database
let mut similarities = Vec::new();
for (name, gesture) in database {
let gesture_norm = normalize(gesture);
let gesture_resamp = resample(&gesture_norm, 64);
let gesture_spectral = spectral_signature(&gesture_resamp, 4);
// Euclidean distance between spectral signatures
let distance = query_spectral.iter()
.zip(gesture_spectral.iter())
.map(|(a, b)| (a - b).powi(2))
.sum::<f64>()
.sqrt();
similarities.push((name, distance));
}
// Sort by similarity (lower distance = more similar)
similarities.sort_by(|a, b| a.1.partial_cmp(&b.1).unwrap());
similarities
}
```
## Mathematical Operations
| Module | Function | Purpose |
|--------|----------|---------|
| `point` | `Point::new(x, y)` | Create 2D points with floating-point coordinates |
| `normalize` | `normalize(points)` | Center gesture at origin and scale to unit size |
| `resample` | `resample(points, n)` | Resample to n evenly spaced points |
| `moments` | `hu_moments(points)` | Compute Hu invariant moments (7-value shape descriptor) |
| `spectral` | `spectral_signature(points, k)` | Compute k Laplacian eigenvalues |
| `pca` | `pca(data, k)` | Dimensionality reduction to k principal components |
| `morton` | `morton2(x, y)` | Convert 2D coordinates to 64-bit Morton code |
## Dependencies
- `nalgebra` - Linear algebra and matrix operations
- `ndarray` - Multi-dimensional array support
- `itertools` - Iteration helpers
- `rand` - Test data generation
## Testing
Run tests with:
```bash
cargo test
```
All tests pass, demonstrating correct implementation of gesture indexing mathematics.