Skip to main content

cliffy_core/
lib.rs

1//! # Cliffy Core
2//!
3//! Reactive UI framework with geometric algebra state management.
4//!
5//! Cliffy uses Clifford/Geometric Algebra as its mathematical foundation,
6//! providing FRP-style reactive primitives where all state transformations
7//! are geometric operations under the hood.
8//!
9//! ## Quick Start
10//!
11//! ```rust
12//! use cliffy_core::{Behavior, behavior};
13//!
14//! // Create a reactive behavior (internally a GA3 multivector)
15//! let count = behavior(0i32);
16//!
17//! // Sample the current value
18//! assert_eq!(count.sample(), 0);
19//!
20//! // Update via transformation
21//! count.update(|n| n + 1);
22//! assert_eq!(count.sample(), 1);
23//!
24//! // Map to derived behavior
25//! let doubled = count.map(|n| n * 2);
26//! assert_eq!(doubled.sample(), 2);
27//! ```
28//!
29//! ## Explicit Geometric Control
30//!
31//! For applications that need explicit geometric transformations:
32//!
33//! ```rust
34//! use cliffy_core::{GeometricState, Rotor, Translation};
35//! use std::f64::consts::PI;
36//!
37//! // Create state representing a 3D position
38//! let pos = GeometricState::from_vector(1.0, 0.0, 0.0);
39//!
40//! // Apply explicit geometric transformations
41//! let rotated = pos.apply_rotor(&Rotor::xy(PI / 2.0));  // 90° rotation
42//! let translated = rotated.apply_translation(&Translation::new(1.0, 0.0, 0.0));
43//!
44//! // Get the result as a vector
45//! let (x, y, z) = translated.as_vector();
46//! assert!((x - 1.0).abs() < 1e-10);  // ~1.0
47//! assert!((y - 1.0).abs() < 1e-10);  // ~1.0
48//! ```
49//!
50//! ## Architecture
51//!
52//! - **Behavior<T>**: Time-varying values backed by geometric algebra
53//! - **Event<T>**: Discrete occurrences with geometric transformations
54//! - **GeometricState**: Explicit geometric operations (rotations, translations)
55//! - **Projection**: Extract user types from geometric state
56//! - **Combinators**: `when`, `combine` for composition
57//!
58//! The geometric algebra foundation can be hidden from users (they work with
59//! familiar types like `i32`, `String`, `Vec<T>`) or exposed explicitly via
60//! `GeometricState` for advanced use cases.
61
62pub mod behavior;
63pub mod combinators;
64pub mod component;
65pub mod dataflow;
66pub mod event;
67pub mod geometric;
68pub mod projection;
69pub mod state;
70pub mod transforms;
71
72// Re-export main types - basic FRP
73pub use behavior::{behavior, Behavior, Subscription};
74pub use combinators::{combine, when};
75pub use event::{event, Event};
76pub use geometric::{FromGeometric, IntoGeometric, GA3};
77
78// Re-export geometric state types
79pub use projection::{
80    BivectorProjection, BoolProjection, ColorAlphaProjection, ColorProjection, CustomProjection,
81    IntProjection, MagnitudeProjection, MappedProjection, Position2DProjection,
82    Position3DProjection, Projection, RotorAngleProjection, ScalarProjection,
83    TypedBivectorProjection, TypedVectorProjection, VectorProjection,
84};
85pub use state::{GeometricState, GeometricSubscription};
86pub use transforms::{Rotor, Transform, Translation, Versor};
87
88// Re-export component types
89pub use component::{
90    component, compose, Component, ComposedComponent, Element, ElementKind, FnComponent, PropValue,
91    Props, StateSplit,
92};
93
94// Re-export dataflow types
95pub use dataflow::{
96    CombinerType, DataflowGraph, GraphBuilder, Node, NodeId, NodeKind, ProjectionSpec,
97    RotationPlane, SinkSpec, TransformType,
98};
99
100// Re-export Amari types for advanced users
101pub use amari_core::Multivector;