diff --git a/crates/apps/tahuantinsuyu/src/shell.rs b/crates/apps/tahuantinsuyu/src/shell.rs index 61ceeb9..5b5aad4 100644 --- a/crates/apps/tahuantinsuyu/src/shell.rs +++ b/crates/apps/tahuantinsuyu/src/shell.rs @@ -206,9 +206,25 @@ impl Shell { target_age_years: age, }); } + if module_enabled(&self.module_configs, "synastry") { + if let Some(partner) = self.find_synastry_partner() { + requests.push(PipelineRequest::Synastry { + partner_chart: Box::new(partner), + }); + } + } requests } + /// Encuentra una carta hermana del contacto actual (cualquier otra + /// carta con el mismo `contact_id` ≠ self). `None` si no hay + /// hermana — el shell salta el request silenciosamente. + fn find_synastry_partner(&self) -> Option { + let current = self.current_chart.as_ref()?; + let siblings = self.store.list_charts(current.contact_id).ok()?; + siblings.into_iter().find(|c| c.id != current.id) + } + /// Lee `target_age_years` del módulo o cae a la edad actual del /// sujeto (calculada desde la fecha de nacimiento y el reloj). fn module_age_or_current(&self, module_id: &str) -> f64 { @@ -321,9 +337,29 @@ impl Shell { if let serde_json::Value::Object(map) = entry { map.insert(key.clone(), value.clone()); } + // Transit y Synastry comparten el outer ring del + // canvas — son mutuamente excluyentes. Al prender + // uno, apagamos el otro y sincronizamos el panel. + if key == "enabled" && bool_val { + let conflicting = match module_id.as_str() { + "transit" => Some("synastry"), + "synastry" => Some("transit"), + _ => None, + }; + if let Some(other) = conflicting { + if module_enabled(&self.module_configs, other) { + set_module_enabled(&mut self.module_configs, other, false); + let other_str = other.to_string(); + self.panel.update(cx, |p, cx| { + p.set_toggle(&other_str, "enabled", false, cx) + }); + } + } + } // Sincronizar visualmente el toggle [T] del canvas - // cuando el cambio fue al "enabled" del transit. - if module_id == "transit" && key == "enabled" { + // cuando el cambio afecta el outer ring (transit o + // synastry — ambos lo usan). + if (module_id == "transit" || module_id == "synastry") && key == "enabled" { self.canvas.update(cx, |c, cx| { c.set_layer_visible(LayerKind::Outer, bool_val, cx) }); diff --git a/crates/modules/tahuantinsuyu/tahuantinsuyu-canvas/src/lib.rs b/crates/modules/tahuantinsuyu/tahuantinsuyu-canvas/src/lib.rs index b7e663f..26a2cba 100644 --- a/crates/modules/tahuantinsuyu/tahuantinsuyu-canvas/src/lib.rs +++ b/crates/modules/tahuantinsuyu/tahuantinsuyu-canvas/src/lib.rs @@ -567,10 +567,13 @@ fn render_wheel( } } - // Planet glyphs (transit ring) — solo si la capa Outer está activa. + // Planet glyphs en el outer ring — transit o synastry, los dos + // comparten ese slot (mutuamente excluyentes a nivel de Shell). if visible.get(&LayerKind::Outer).copied().unwrap_or(true) { for layer in &render.layers { - if matches!(layer.kind, LayerKind::Outer) && layer.module_id == "transit" { + if matches!(layer.kind, LayerKind::Outer) + && (layer.module_id == "transit" || layer.module_id == "synastry") + { for g in &layer.glyphs { let (x, y) = polar_to_screen(g.deg, asc, rot_offset, radii.transits); let color = with_alpha(planet_color(palette, &g.symbol), 0.9); @@ -724,10 +727,12 @@ impl Radii { /// Resuelve qué radios corresponden a una capa de aspectos según el /// `module_id`: natal-natal en `aspects`, cross con cada overlay - /// desde `bodies` (extremo natal) al ring del módulo. + /// desde `bodies` (extremo natal) al ring del módulo. Synastry + /// comparte el outer ring de tránsito (son mutuamente excluyentes + /// a nivel de Shell). fn aspect_endpoints(&self, module_id: &str) -> (f32, f32) { match module_id { - "transit" => (self.bodies, self.transits), + "transit" | "synastry" => (self.bodies, self.transits), "progression" => (self.bodies, self.progression), "solar_arc" => (self.bodies, self.solar_arc), _ => (self.aspects, self.aspects), @@ -935,12 +940,14 @@ fn paint_wheel( } } - // 5. Outer ring (transit overlay): anillo guía + dots de transit. - let transit_active = layers - .iter() - .any(|l| matches!(l.kind, LayerKind::Outer) && l.module_id == "transit"); - if transit_active && show(LayerKind::Outer) { - // Anillos guía para delimitar el slot. + // 5. Outer ring (transit o synastry overlay): anillo guía + dots + // de la capa activa. Son mutuamente excluyentes a nivel de Shell; + // si alguno de los dos está prendido, pintamos el slot. + let outer_active = layers.iter().any(|l| { + matches!(l.kind, LayerKind::Outer) + && (l.module_id == "transit" || l.module_id == "synastry") + }); + if outer_active && show(LayerKind::Outer) { stroke_circle( window, cx, @@ -960,7 +967,9 @@ fn paint_wheel( let dot_r = (radii.sign_outer * 0.017).max(2.0); for layer in layers { - if matches!(layer.kind, LayerKind::Outer) && layer.module_id == "transit" { + if matches!(layer.kind, LayerKind::Outer) + && (layer.module_id == "transit" || layer.module_id == "synastry") + { for g in &layer.glyphs { let color = with_alpha(planet_color(palette, &g.symbol), 0.85); let (x, y) = diff --git a/crates/modules/tahuantinsuyu/tahuantinsuyu-engine/src/bridge.rs b/crates/modules/tahuantinsuyu/tahuantinsuyu-engine/src/bridge.rs index cb9a1ae..77e12d7 100644 --- a/crates/modules/tahuantinsuyu/tahuantinsuyu-engine/src/bridge.rs +++ b/crates/modules/tahuantinsuyu/tahuantinsuyu-engine/src/bridge.rs @@ -261,6 +261,9 @@ pub fn compose( crate::PipelineRequest::SolarArc { target_age_years } => { build_solar_arc_overlay(&natal, *target_age_years, &mut render)?; } + crate::PipelineRequest::Synastry { partner_chart } => { + build_synastry_overlay(&natal, partner_chart, &mut render)?; + } } } @@ -466,6 +469,68 @@ fn build_solar_arc_overlay( Ok(()) } +/// Helper: agrega al `RenderModel` las capas del overlay de sinastría +/// con otra carta natal completa. La carta partner se computa con su +/// propio observer/config (no comparte con la natal). El outer ring +/// se comparte con Transit — mutuamente excluyentes a nivel de Shell. +fn build_synastry_overlay( + natal: &NatalChart, + partner_chart: &Chart, + render: &mut RenderModel, +) -> Result<(), EngineError> { + let (partner, _config, _observer) = compute_natal_chart(partner_chart, 0)?; + + let glyphs: Vec = partner + .placements + .iter() + .map(|p| Glyph { + deg: p.longitude.longitude_deg() as f32, + symbol: body_symbol(p.body).into(), + annotation: Some(format!("{:.1}°", p.longitude.degree_in_sign_decimal())), + retrograde: p.longitude_rate_rad_per_day < 0.0, + house: Some(p.house_number), + }) + .collect(); + render.layers.push(Layer { + module_id: "synastry".into(), + kind: LayerKind::Outer, + ring: 0.82, + z: 10, + geometry: Geometry::GlyphsOnly, + glyphs, + }); + + let cross = find_synastry_aspects( + natal, + &partner, + &OrbTable::modern_western(), + EAspectKind::MAJORS, + ); + let cross_lines: Vec = cross + .iter() + .filter_map(|a| { + let natal_p = natal.placement(a.person_a_body)?; + let partner_p = partner.placement(a.person_b_body)?; + let opacity = orb_to_opacity(a.orb_abs_deg(), a.kind); + Some(LineSeg { + from_deg: natal_p.longitude.longitude_deg() as f32, + to_deg: partner_p.longitude.longitude_deg() as f32, + kind: aspect_kind_id(a.kind).into(), + opacity: opacity * 0.85, + }) + }) + .collect(); + render.layers.push(Layer { + module_id: "synastry".into(), + kind: LayerKind::Aspects, + ring: 0.0, + z: 11, + geometry: Geometry::Lines(cross_lines), + glyphs: Vec::new(), + }); + Ok(()) +} + // ===================================================================== // NatalChart → RenderModel // ===================================================================== diff --git a/crates/modules/tahuantinsuyu/tahuantinsuyu-engine/src/lib.rs b/crates/modules/tahuantinsuyu/tahuantinsuyu-engine/src/lib.rs index d235767..f11f802 100644 --- a/crates/modules/tahuantinsuyu/tahuantinsuyu-engine/src/lib.rs +++ b/crates/modules/tahuantinsuyu/tahuantinsuyu-engine/src/lib.rs @@ -30,6 +30,10 @@ use thiserror::Error; pub use tahuantinsuyu_model::{Chart, ChartId, ChartKind}; +// `Chart` reexportado arriba es lo que `PipelineRequest::Synastry` +// transporta — el caller (shell) lee del Store y pasa el Chart entero +// para que el bridge construya su NatalChart en eternal. + #[cfg(feature = "eternal-bridge")] mod bridge; @@ -180,8 +184,13 @@ pub enum PipelineRequest { SolarArc { target_age_years: f64, }, - // ── Fase 10 ───────────────────────────────────────────────────── - // Synastry { partner: tahuantinsuyu_model::ChartId }, + /// `module_id = "synastry"` — bi-wheel: la natal en el centro, la + /// carta del partner en el anillo externo (compartido con Transit + /// — mutuamente excluyentes), cross aspects natal × partner. + /// El partner viene como `Chart` completo del shell. + Synastry { + partner_chart: Box, + }, } /// Composición canónica: carta natal + todos los overlays pedidos. diff --git a/crates/modules/tahuantinsuyu/tahuantinsuyu-modules/src/lib.rs b/crates/modules/tahuantinsuyu/tahuantinsuyu-modules/src/lib.rs index 2981335..278cbd6 100644 --- a/crates/modules/tahuantinsuyu/tahuantinsuyu-modules/src/lib.rs +++ b/crates/modules/tahuantinsuyu/tahuantinsuyu-modules/src/lib.rs @@ -126,6 +126,7 @@ impl Registry { r.register(Box::new(transit::TransitModule)); r.register(Box::new(progression::ProgressionModule)); r.register(Box::new(solar_arc::SolarArcModule)); + r.register(Box::new(synastry::SynastryModule)); r } @@ -333,6 +334,50 @@ pub mod progression { } } +// ===================================================================== +// SynastryModule — bi-wheel con otra carta hermana del contacto actual +// ===================================================================== + +pub mod synastry { + use super::*; + + /// Pone la carta del partner en el anillo externo (compartido con + /// Transit — mutuamente excluyentes) y dibuja las cross aspects + /// natal × partner. El shell elige el partner: la primera carta + /// hermana del mismo contacto. Si no hay hermana, el request se + /// salta silenciosamente. + pub struct SynastryModule; + + impl Module for SynastryModule { + fn id(&self) -> &'static str { + "synastry" + } + fn label(&self) -> &'static str { + "Sinastría" + } + fn description(&self) -> &'static str { + "Bi-wheel con la primera carta hermana del contacto." + } + fn applies_to(&self, kind: ChartKind) -> bool { + matches!(kind, ChartKind::Natal) + } + fn enabled_by_default(&self) -> bool { + false + } + fn controls(&self) -> Vec { + vec![Control::Toggle { + key: "enabled".into(), + label: "Activar".into(), + default: false, + hotkey: None, + }] + } + fn compute_layers(&self, _chart: &Chart, _cfg: &serde_json::Value) -> Vec { + Vec::new() + } + } +} + // ===================================================================== // SolarArcModule — Solar Arc dirigido (true progressed Sun) // ===================================================================== @@ -397,8 +442,9 @@ mod tests { assert!(r.find("transit").is_some()); assert!(r.find("progression").is_some()); assert!(r.find("solar_arc").is_some()); - // Natal kind tiene 4 módulos: natal + transit + progression + solar_arc. - assert_eq!(r.for_kind(ChartKind::Natal).len(), 4); + assert!(r.find("synastry").is_some()); + // Natal kind tiene 5 módulos aplicables. + assert_eq!(r.for_kind(ChartKind::Natal).len(), 5); assert!(r.for_kind(ChartKind::Synastry).is_empty()); } }