feat(tahuantinsuyu): fase 3 — engine real contra eternal + rueda pintada en GPUI
Bridge a eternal-astrology prendido por default. `engine::compute(chart)` abre una EphemerisSession VSOP2013 (cacheada vía OnceLock global), traduce los Stored* del modelo a BirthData/ChartConfig de eternal, corre NatalChart::compute + find_aspects(modern_western) y devuelve un RenderModel con cuatro capas: SignDial, Houses, Bodies, Aspects. - tahuantinsuyu-engine: bridge.rs nuevo con map_house_system, map_zodiac (incl. 8 ayanamshas), map_body_set, body_symbol, aspect_kind_id. compute_mock se mantiene como fallback sin feature. Errores tipados (EngineError::Eternal). Test real verde con datos natales de demo. - tahuantinsuyu-canvas: rewrite con gpui::canvas() + PathBuilder. Pinta: sectores zodiacales coloreados por elemento (Fire/Earth/Air/ Water), anillos de sign-dial/houses/aspects, cusps zodiacales, cusps de casas (con énfasis para Asc/MC/Desc/IC), líneas radiales hasta el centro para los ejes, líneas de aspectos coloreadas por kind con opacidad por orb, dots de cuerpos. Glifos unicode (♈-♓ signos, ☉-♇ planetas, ☊☋⚷⚸ puntos) como divs absolutos sobre el canvas. Marcador ᴿ cuando retrógrado. Rotación canónica: Asc a las 9, casas crecen contrarreloj. - shell: ahora llama engine::compute() real y reporta errores por stderr sin caer la app. Datos sintetizados: ascendente, MC, descendente, IC; 12 cusps de casa según el sistema configurado; placements de los cuerpos del BodySet con sus longitudes zodiacales, casa y flag retrógrado; aspectos mayores con opacidad proporcional al orb. `cargo check` y `cargo test --features eternal-bridge` verdes. La fase 4 traerá el panel interactivo (jog-dial, toggles, sliders, atajos teclado). Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -6,30 +6,34 @@
|
||||
//! (drag, hotkeys, toggles) mutan el estado; el render lee la última
|
||||
//! `RenderModel` y la deriva al frame.
|
||||
//!
|
||||
//! ## Modos
|
||||
//! ## Convención de rotación
|
||||
//!
|
||||
//! - [`CanvasMode::Wheel`] — pinta una carta única (la rueda).
|
||||
//! - [`CanvasMode::Thumbnails`] — pinta una grilla de mini-cartas
|
||||
//! cuando el item activo del tree es un Group o Contact.
|
||||
//! - [`CanvasMode::Empty`] — sin selección.
|
||||
//! El Ascendente cae a las 9 del reloj (lado izquierdo). Las casas
|
||||
//! crecen contrarreloj visualmente. Para una longitud eclíptica `L` y
|
||||
//! un ascendente `asc`:
|
||||
//!
|
||||
//! ## Fase 1
|
||||
//! ```text
|
||||
//! screen_angle_rad = π - (L - asc) · π/180 (más view_rotation)
|
||||
//! point = (cx + r·cos(θ), cy + r·sin(θ))
|
||||
//! ```
|
||||
//!
|
||||
//! Este crate trae el esqueleto: tipos, estado, render placeholder
|
||||
//! (caja cuadrada con título centrado, eje cardinal y un anillo
|
||||
//! perfilado). Las interacciones del jog-dial, el árbol Uraniano y la
|
||||
//! pintura de cada `Layer` vienen en fases siguientes.
|
||||
//! El `+y` de canvas apunta para abajo, así que `+sin` lleva al sur del
|
||||
//! lienzo → la convención coincide con el chart estándar (IC abajo,
|
||||
//! MC arriba).
|
||||
|
||||
#![forbid(unsafe_code)]
|
||||
#![warn(rust_2018_idioms)]
|
||||
|
||||
use std::f32::consts::PI;
|
||||
|
||||
use gpui::{
|
||||
Context, EventEmitter, IntoElement, Render, SharedString, Window, div, prelude::*, px,
|
||||
Bounds, Context, EventEmitter, Hsla, IntoElement, ParentElement, PathBuilder, Pixels, Render,
|
||||
SharedString, Styled, Window, canvas, div, hsla, point, prelude::*, px,
|
||||
};
|
||||
|
||||
use tahuantinsuyu_engine::RenderModel;
|
||||
use tahuantinsuyu_engine::{Geometry, Layer, LayerKind, RenderModel};
|
||||
use tahuantinsuyu_model::{ChartId, ContactId, GroupId};
|
||||
use tahuantinsuyu_theme::AstroPalette;
|
||||
use tahuantinsuyu_theme::{AspectKind as TAspectKind, AstroPalette, Element, Planet};
|
||||
use yahweh_theme::Theme;
|
||||
|
||||
// =====================================================================
|
||||
@@ -38,10 +42,7 @@ use yahweh_theme::Theme;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum CanvasEvent {
|
||||
/// El usuario hizo doble click sobre un thumbnail o pidió abrir la
|
||||
/// carta activa. El host (la app) decide si emitir al AppBus.
|
||||
ChartRequested(ChartId),
|
||||
/// El usuario rotó la rueda de tiempo: minutos de offset acumulados.
|
||||
TimeOffsetChanged(i64),
|
||||
}
|
||||
|
||||
@@ -49,14 +50,11 @@ pub enum CanvasEvent {
|
||||
// Estado
|
||||
// =====================================================================
|
||||
|
||||
/// Modo de visualización del canvas.
|
||||
#[derive(Clone, Debug, Default)]
|
||||
pub enum CanvasMode {
|
||||
#[default]
|
||||
Empty,
|
||||
/// Single chart wheel.
|
||||
Wheel { render: Box<RenderModel> },
|
||||
/// Grilla de thumbnails para un Group o Contact con varias cartas.
|
||||
Thumbnails {
|
||||
scope: ThumbnailScope,
|
||||
items: Vec<ThumbnailItem>,
|
||||
@@ -74,25 +72,15 @@ pub struct ThumbnailItem {
|
||||
pub chart_id: ChartId,
|
||||
pub label: SharedString,
|
||||
pub subtitle: Option<SharedString>,
|
||||
/// `Some` si ya hay un render-mock disponible. `None` = lazy.
|
||||
pub preview: Option<RenderModel>,
|
||||
}
|
||||
|
||||
/// Estado unificado del canvas. Inspirado en la conversación de Sergio
|
||||
/// con el agente — todo lo que controla qué se pinta vive acá.
|
||||
#[derive(Clone, Debug, Default)]
|
||||
pub struct CanvasState {
|
||||
pub mode: CanvasMode,
|
||||
|
||||
/// Rotación manual del lienzo en grados. `0.0` = Aries al este.
|
||||
/// Rotación adicional manual en grados. `0.0` = el Asc cae a las 9.
|
||||
pub view_rotation_deg: f32,
|
||||
|
||||
/// Offset acumulado del time-scrubbing (jog-dial perimetral) en
|
||||
/// minutos. La engine recalcula la `RenderModel` cuando esto cambia.
|
||||
pub time_offset_minutes: i64,
|
||||
|
||||
/// Capas activas por `module_id`. Si una capa del `RenderModel`
|
||||
/// pertenece a un módulo no presente aquí, no se pinta.
|
||||
pub active_modules: std::collections::HashSet<String>,
|
||||
}
|
||||
|
||||
@@ -118,7 +106,6 @@ impl AstrologyCanvas {
|
||||
&self.state
|
||||
}
|
||||
|
||||
/// Reemplaza el modo de visualización (lo que se pinta).
|
||||
pub fn set_mode(&mut self, mode: CanvasMode, cx: &mut Context<Self>) {
|
||||
self.state.mode = mode;
|
||||
cx.notify();
|
||||
@@ -141,6 +128,12 @@ impl AstrologyCanvas {
|
||||
// Render
|
||||
// =====================================================================
|
||||
|
||||
/// Tamaño del cuadrado de la rueda en píxeles. Fijo para que glifos y
|
||||
/// geometría coincidan sin un round-trip de bounds. La rueda se centra
|
||||
/// en el panel del canvas; el resto del espacio queda como margen.
|
||||
const WHEEL_SIZE: f32 = 580.0;
|
||||
const WHEEL_MARGIN: f32 = 28.0;
|
||||
|
||||
impl Render for AstrologyCanvas {
|
||||
fn render(&mut self, _w: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||
let theme = Theme::global(cx).clone();
|
||||
@@ -148,10 +141,10 @@ impl Render for AstrologyCanvas {
|
||||
|
||||
let body = match &self.state.mode {
|
||||
CanvasMode::Empty => render_empty(&theme),
|
||||
CanvasMode::Wheel { render } => render_wheel(&theme, &palette, render),
|
||||
CanvasMode::Thumbnails { scope: _, items } => {
|
||||
render_thumbnails(&theme, &palette, items)
|
||||
CanvasMode::Wheel { render } => {
|
||||
render_wheel(&theme, &palette, render, self.state.view_rotation_deg)
|
||||
}
|
||||
CanvasMode::Thumbnails { items, .. } => render_thumbnails(&theme, items),
|
||||
};
|
||||
|
||||
div()
|
||||
@@ -165,6 +158,10 @@ impl Render for AstrologyCanvas {
|
||||
}
|
||||
}
|
||||
|
||||
// =====================================================================
|
||||
// Modos: empty / thumbnails / wheel
|
||||
// =====================================================================
|
||||
|
||||
fn render_empty(theme: &Theme) -> gpui::Div {
|
||||
div()
|
||||
.flex()
|
||||
@@ -186,57 +183,13 @@ fn render_empty(theme: &Theme) -> gpui::Div {
|
||||
)
|
||||
}
|
||||
|
||||
fn render_wheel(theme: &Theme, palette: &AstroPalette, render: &RenderModel) -> gpui::Div {
|
||||
// Fase 1: placeholder visual. Una caja cuadrada con el título y un
|
||||
// contador de capas. El pintado real de los Layer vendrá con
|
||||
// `gpui::canvas` + matrices en la fase 3.
|
||||
let _ = palette; // silencia warning hasta la fase 3.
|
||||
div()
|
||||
.flex()
|
||||
.flex_col()
|
||||
.items_center()
|
||||
.justify_center()
|
||||
.gap(px(10.0))
|
||||
.child(
|
||||
div()
|
||||
.text_size(px(16.0))
|
||||
.text_color(theme.fg_text)
|
||||
.child(SharedString::from(render.title.clone())),
|
||||
)
|
||||
.child(
|
||||
div()
|
||||
.text_size(px(11.0))
|
||||
.text_color(theme.fg_muted)
|
||||
.child(SharedString::from(format!(
|
||||
"{} capa(s) · {} ms",
|
||||
render.layers.len(),
|
||||
render.compute_ms
|
||||
))),
|
||||
)
|
||||
.child(
|
||||
// Marco cuadrado provisional — el render real lo ocupará.
|
||||
div()
|
||||
.size(px(480.0))
|
||||
.rounded(px(8.0))
|
||||
.border_1()
|
||||
.border_color(theme.border_strong)
|
||||
.bg(theme.bg_panel_alt.clone()),
|
||||
)
|
||||
}
|
||||
|
||||
fn render_thumbnails(
|
||||
theme: &Theme,
|
||||
_palette: &AstroPalette,
|
||||
items: &[ThumbnailItem],
|
||||
) -> gpui::Div {
|
||||
fn render_thumbnails(theme: &Theme, items: &[ThumbnailItem]) -> gpui::Div {
|
||||
if items.is_empty() {
|
||||
return div()
|
||||
.text_size(px(12.0))
|
||||
.text_color(theme.fg_muted)
|
||||
.child("Sin cartas en este grupo todavía.");
|
||||
}
|
||||
// Grid simple en flex-wrap. La fase 3 lo reemplaza por miniaturas
|
||||
// pintadas con la rueda en miniatura.
|
||||
let mut row = div().flex().flex_row().flex_wrap().gap(px(12.0));
|
||||
for it in items {
|
||||
row = row.child(
|
||||
@@ -262,3 +215,638 @@ fn render_thumbnails(
|
||||
}
|
||||
row
|
||||
}
|
||||
|
||||
// =====================================================================
|
||||
// Wheel
|
||||
// =====================================================================
|
||||
|
||||
fn render_wheel(
|
||||
theme: &Theme,
|
||||
palette: &AstroPalette,
|
||||
render: &RenderModel,
|
||||
view_rotation_deg: f32,
|
||||
) -> gpui::Div {
|
||||
let asc = render.ascendant_deg;
|
||||
let rot_offset = view_rotation_deg;
|
||||
let cx_center = WHEEL_SIZE / 2.0;
|
||||
let cy_center = WHEEL_SIZE / 2.0;
|
||||
let r_outer = (WHEEL_SIZE - WHEEL_MARGIN * 2.0) / 2.0;
|
||||
|
||||
let radii = Radii::from_outer(r_outer);
|
||||
|
||||
// --- Canvas element con todo el trazo ---
|
||||
let palette_paint = palette.clone();
|
||||
let theme_paint = theme.clone();
|
||||
let layers_paint: Vec<Layer> = render.layers.clone();
|
||||
let asc_for_paint = asc;
|
||||
let mc_for_paint = render.midheaven_deg;
|
||||
let canvas_element = canvas(
|
||||
move |_b: Bounds<Pixels>, _w, _cx| (),
|
||||
move |bounds: Bounds<Pixels>, _, window, _| {
|
||||
paint_wheel(
|
||||
bounds,
|
||||
window,
|
||||
&theme_paint,
|
||||
&palette_paint,
|
||||
&layers_paint,
|
||||
asc_for_paint,
|
||||
mc_for_paint,
|
||||
rot_offset,
|
||||
radii,
|
||||
);
|
||||
},
|
||||
)
|
||||
.absolute()
|
||||
.w(px(WHEEL_SIZE))
|
||||
.h(px(WHEEL_SIZE));
|
||||
|
||||
// --- Glyphs como divs absolutos (text-rendering nativo) ---
|
||||
let mut wheel = div()
|
||||
.relative()
|
||||
.w(px(WHEEL_SIZE))
|
||||
.h(px(WHEEL_SIZE))
|
||||
.child(canvas_element);
|
||||
|
||||
// Sign glyphs en el centro de cada sector zodiacal.
|
||||
let sign_ring_mid = (radii.sign_outer + radii.sign_inner) / 2.0;
|
||||
for layer in &render.layers {
|
||||
if matches!(layer.kind, LayerKind::SignDial) {
|
||||
for g in &layer.glyphs {
|
||||
let (x, y) = polar_to_screen(g.deg, asc, rot_offset, sign_ring_mid);
|
||||
let color = element_color_for_sign(palette, &g.symbol);
|
||||
wheel = wheel.child(centered_glyph(
|
||||
cx_center + x,
|
||||
cy_center + y,
|
||||
20.0,
|
||||
18.0,
|
||||
sign_unicode(&g.symbol).into(),
|
||||
color,
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// House numbers cerca de cada cusp.
|
||||
let house_label_r = (radii.houses_outer + radii.houses_inner) / 2.0;
|
||||
for layer in &render.layers {
|
||||
if matches!(layer.kind, LayerKind::Houses) {
|
||||
for g in &layer.glyphs {
|
||||
let (x, y) = polar_to_screen(g.deg, asc, rot_offset, house_label_r);
|
||||
if let Some(h) = g.house {
|
||||
wheel = wheel.child(centered_glyph(
|
||||
cx_center + x,
|
||||
cy_center + y,
|
||||
16.0,
|
||||
10.0,
|
||||
format!("{}", h).into(),
|
||||
palette.house_cusp,
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Planet glyphs sobre el ring de cuerpos.
|
||||
for layer in &render.layers {
|
||||
if matches!(layer.kind, LayerKind::Bodies) {
|
||||
for g in &layer.glyphs {
|
||||
let (x, y) = polar_to_screen(g.deg, asc, rot_offset, radii.bodies);
|
||||
let color = planet_color(palette, &g.symbol);
|
||||
let glyph_text = if g.retrograde {
|
||||
format!("{}ᴿ", planet_unicode(&g.symbol))
|
||||
} else {
|
||||
planet_unicode(&g.symbol).into()
|
||||
};
|
||||
wheel = wheel.child(centered_glyph(
|
||||
cx_center + x,
|
||||
cy_center + y,
|
||||
24.0,
|
||||
18.0,
|
||||
glyph_text.into(),
|
||||
color,
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// --- Composición final con título arriba ---
|
||||
let header = div()
|
||||
.flex()
|
||||
.flex_col()
|
||||
.items_center()
|
||||
.gap(px(2.0))
|
||||
.child(
|
||||
div()
|
||||
.text_size(px(16.0))
|
||||
.text_color(theme.fg_text)
|
||||
.child(SharedString::from(render.title.clone())),
|
||||
);
|
||||
let header = if let Some(sub) = &render.subtitle {
|
||||
header.child(
|
||||
div()
|
||||
.text_size(px(11.0))
|
||||
.text_color(theme.fg_muted)
|
||||
.child(SharedString::from(sub.clone())),
|
||||
)
|
||||
} else {
|
||||
header
|
||||
};
|
||||
let footer = div()
|
||||
.text_size(px(10.0))
|
||||
.text_color(theme.fg_disabled)
|
||||
.child(SharedString::from(format!(
|
||||
"Asc {:.1}° MC {:.1}° · {} capas · {} ms",
|
||||
render.ascendant_deg,
|
||||
render.midheaven_deg,
|
||||
render.layers.len(),
|
||||
render.compute_ms,
|
||||
)));
|
||||
|
||||
div()
|
||||
.flex()
|
||||
.flex_col()
|
||||
.items_center()
|
||||
.gap(px(8.0))
|
||||
.child(header)
|
||||
.child(wheel)
|
||||
.child(footer)
|
||||
}
|
||||
|
||||
// =====================================================================
|
||||
// Painting
|
||||
// =====================================================================
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
struct Radii {
|
||||
sign_outer: f32,
|
||||
sign_inner: f32,
|
||||
houses_outer: f32,
|
||||
houses_inner: f32,
|
||||
bodies: f32,
|
||||
aspects: f32,
|
||||
}
|
||||
|
||||
impl Radii {
|
||||
fn from_outer(r: f32) -> Self {
|
||||
Self {
|
||||
sign_outer: r,
|
||||
sign_inner: r * 0.88,
|
||||
houses_outer: r * 0.86,
|
||||
houses_inner: r * 0.72,
|
||||
bodies: r * 0.65,
|
||||
aspects: r * 0.58,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
fn paint_wheel(
|
||||
bounds: Bounds<Pixels>,
|
||||
window: &mut Window,
|
||||
theme: &Theme,
|
||||
palette: &AstroPalette,
|
||||
layers: &[Layer],
|
||||
ascendant_deg: f32,
|
||||
midheaven_deg: f32,
|
||||
rot_offset_deg: f32,
|
||||
radii: Radii,
|
||||
) {
|
||||
let ox: f32 = bounds.origin.x.into();
|
||||
let oy: f32 = bounds.origin.y.into();
|
||||
let bw: f32 = bounds.size.width.into();
|
||||
let bh: f32 = bounds.size.height.into();
|
||||
let cx = ox + bw / 2.0;
|
||||
let cy = oy + bh / 2.0;
|
||||
|
||||
// 1. Sectores del zodíaco coloreados por elemento.
|
||||
paint_sign_sectors(window, cx, cy, &radii, palette, ascendant_deg, rot_offset_deg);
|
||||
|
||||
// 2. Anillos (outer + inner del sign dial, houses outer, body outer).
|
||||
stroke_circle(window, cx, cy, radii.sign_outer, 1.5, palette.dial_ring);
|
||||
stroke_circle(window, cx, cy, radii.sign_inner, 1.0, palette.dial_ring);
|
||||
stroke_circle(
|
||||
window,
|
||||
cx,
|
||||
cy,
|
||||
radii.houses_inner,
|
||||
0.8,
|
||||
with_alpha(palette.house_cusp, 0.6),
|
||||
);
|
||||
|
||||
// 3. Líneas de cusp del zodíaco (cada 30° desde Aries 0°).
|
||||
for i in 0..12 {
|
||||
let lon = (i as f32) * 30.0;
|
||||
let color = if i == 0 {
|
||||
palette.angle_highlight
|
||||
} else {
|
||||
palette.dial_ring
|
||||
};
|
||||
paint_radial_line(
|
||||
window,
|
||||
cx,
|
||||
cy,
|
||||
lon,
|
||||
ascendant_deg,
|
||||
rot_offset_deg,
|
||||
radii.sign_inner,
|
||||
radii.sign_outer,
|
||||
color,
|
||||
1.0,
|
||||
);
|
||||
}
|
||||
|
||||
// 4. Casas: cusps radiales + énfasis Asc / MC.
|
||||
for layer in layers {
|
||||
if matches!(layer.kind, LayerKind::Houses) {
|
||||
if let Geometry::Ring { cusps_deg } = &layer.geometry {
|
||||
for (i, c) in cusps_deg.iter().enumerate() {
|
||||
let is_angle = i == 0 || i == 3 || i == 6 || i == 9;
|
||||
let color = if is_angle {
|
||||
palette.angle_highlight
|
||||
} else {
|
||||
with_alpha(palette.house_cusp, 0.7)
|
||||
};
|
||||
let width = if is_angle { 2.0 } else { 0.8 };
|
||||
paint_radial_line(
|
||||
window,
|
||||
cx,
|
||||
cy,
|
||||
*c,
|
||||
ascendant_deg,
|
||||
rot_offset_deg,
|
||||
radii.houses_inner,
|
||||
radii.houses_outer,
|
||||
color,
|
||||
width,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 5. Énfasis Asc + MC extendido hasta el centro (línea fina).
|
||||
paint_radial_line(
|
||||
window,
|
||||
cx,
|
||||
cy,
|
||||
ascendant_deg,
|
||||
ascendant_deg,
|
||||
rot_offset_deg,
|
||||
0.0,
|
||||
radii.houses_outer,
|
||||
with_alpha(palette.angle_highlight, 0.35),
|
||||
1.0,
|
||||
);
|
||||
paint_radial_line(
|
||||
window,
|
||||
cx,
|
||||
cy,
|
||||
midheaven_deg,
|
||||
ascendant_deg,
|
||||
rot_offset_deg,
|
||||
0.0,
|
||||
radii.houses_outer,
|
||||
with_alpha(palette.angle_highlight, 0.35),
|
||||
1.0,
|
||||
);
|
||||
|
||||
// 6. Aspectos.
|
||||
for layer in layers {
|
||||
if matches!(layer.kind, LayerKind::Aspects) {
|
||||
if let Geometry::Lines(segs) = &layer.geometry {
|
||||
for seg in segs {
|
||||
let color = aspect_color(palette, &seg.kind);
|
||||
let color = with_alpha(color, color.a * seg.opacity);
|
||||
paint_aspect_line(
|
||||
window,
|
||||
cx,
|
||||
cy,
|
||||
seg.from_deg,
|
||||
seg.to_deg,
|
||||
ascendant_deg,
|
||||
rot_offset_deg,
|
||||
radii.aspects,
|
||||
color,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 7. Cuerpos: pequeño dot detrás del glifo.
|
||||
let dot_r = (radii.sign_outer * 0.018).max(2.0);
|
||||
for layer in layers {
|
||||
if matches!(layer.kind, LayerKind::Bodies) {
|
||||
for g in &layer.glyphs {
|
||||
let color = planet_color(palette, &g.symbol);
|
||||
let (x, y) = polar_to_screen(g.deg, ascendant_deg, rot_offset_deg, radii.bodies);
|
||||
fill_circle(window, cx + x, cy + y, dot_r, color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 8. Marco exterior del lienzo (sutil).
|
||||
let _ = theme;
|
||||
}
|
||||
|
||||
fn paint_sign_sectors(
|
||||
window: &mut Window,
|
||||
cx: f32,
|
||||
cy: f32,
|
||||
radii: &Radii,
|
||||
palette: &AstroPalette,
|
||||
ascendant_deg: f32,
|
||||
rot_offset_deg: f32,
|
||||
) {
|
||||
// Cada sector cubre 30° de longitud zodiacal entre `sign_inner` y
|
||||
// `sign_outer`. Lo aproximamos con polígonos para no depender de
|
||||
// `arc_to` (que requiere `Vector<Pixels>`; los polígonos son
|
||||
// suficientemente suaves a este radio).
|
||||
const SUBDIVISIONS: usize = 18;
|
||||
for i in 0..12 {
|
||||
let lon_start = (i as f32) * 30.0;
|
||||
let lon_end = lon_start + 30.0;
|
||||
let element = sign_element_by_index(i);
|
||||
let color = with_alpha(palette.element(element), 0.10);
|
||||
|
||||
let mut builder = PathBuilder::fill();
|
||||
let (x0, y0) = polar_to_screen(lon_start, ascendant_deg, rot_offset_deg, radii.sign_inner);
|
||||
builder.move_to(point(px(cx + x0), px(cy + y0)));
|
||||
|
||||
// Borde interno (lon_start → lon_end), N subdivisiones.
|
||||
for k in 1..=SUBDIVISIONS {
|
||||
let t = lon_start + (lon_end - lon_start) * (k as f32) / (SUBDIVISIONS as f32);
|
||||
let (x, y) = polar_to_screen(t, ascendant_deg, rot_offset_deg, radii.sign_inner);
|
||||
builder.line_to(point(px(cx + x), px(cy + y)));
|
||||
}
|
||||
// Salto al borde externo en lon_end.
|
||||
let (xe, ye) = polar_to_screen(lon_end, ascendant_deg, rot_offset_deg, radii.sign_outer);
|
||||
builder.line_to(point(px(cx + xe), px(cy + ye)));
|
||||
|
||||
// Borde externo de lon_end → lon_start (al revés).
|
||||
for k in (0..SUBDIVISIONS).rev() {
|
||||
let t = lon_start + (lon_end - lon_start) * (k as f32) / (SUBDIVISIONS as f32);
|
||||
let (x, y) = polar_to_screen(t, ascendant_deg, rot_offset_deg, radii.sign_outer);
|
||||
builder.line_to(point(px(cx + x), px(cy + y)));
|
||||
}
|
||||
builder.close();
|
||||
if let Ok(path) = builder.build() {
|
||||
window.paint_path(path, color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn stroke_circle(
|
||||
window: &mut Window,
|
||||
cx: f32,
|
||||
cy: f32,
|
||||
r: f32,
|
||||
width: f32,
|
||||
color: Hsla,
|
||||
) {
|
||||
const SEGMENTS: usize = 96;
|
||||
let mut builder = PathBuilder::stroke(px(width));
|
||||
for i in 0..=SEGMENTS {
|
||||
let t = (i as f32) / (SEGMENTS as f32) * (2.0 * PI);
|
||||
let x = cx + r * t.cos();
|
||||
let y = cy + r * t.sin();
|
||||
if i == 0 {
|
||||
builder.move_to(point(px(x), px(y)));
|
||||
} else {
|
||||
builder.line_to(point(px(x), px(y)));
|
||||
}
|
||||
}
|
||||
if let Ok(path) = builder.build() {
|
||||
window.paint_path(path, color);
|
||||
}
|
||||
}
|
||||
|
||||
fn fill_circle(window: &mut Window, cx: f32, cy: f32, r: f32, color: Hsla) {
|
||||
const SEGMENTS: usize = 32;
|
||||
let mut builder = PathBuilder::fill();
|
||||
builder.move_to(point(px(cx + r), px(cy)));
|
||||
for i in 1..=SEGMENTS {
|
||||
let t = (i as f32) / (SEGMENTS as f32) * (2.0 * PI);
|
||||
let x = cx + r * t.cos();
|
||||
let y = cy + r * t.sin();
|
||||
builder.line_to(point(px(x), px(y)));
|
||||
}
|
||||
builder.close();
|
||||
if let Ok(path) = builder.build() {
|
||||
window.paint_path(path, color);
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
fn paint_radial_line(
|
||||
window: &mut Window,
|
||||
cx: f32,
|
||||
cy: f32,
|
||||
longitude_deg: f32,
|
||||
ascendant_deg: f32,
|
||||
rot_offset_deg: f32,
|
||||
r_inner: f32,
|
||||
r_outer: f32,
|
||||
color: Hsla,
|
||||
width: f32,
|
||||
) {
|
||||
let (xi, yi) = polar_to_screen(longitude_deg, ascendant_deg, rot_offset_deg, r_inner);
|
||||
let (xo, yo) = polar_to_screen(longitude_deg, ascendant_deg, rot_offset_deg, r_outer);
|
||||
let mut builder = PathBuilder::stroke(px(width));
|
||||
builder.move_to(point(px(cx + xi), px(cy + yi)));
|
||||
builder.line_to(point(px(cx + xo), px(cy + yo)));
|
||||
if let Ok(path) = builder.build() {
|
||||
window.paint_path(path, color);
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
fn paint_aspect_line(
|
||||
window: &mut Window,
|
||||
cx: f32,
|
||||
cy: f32,
|
||||
a_deg: f32,
|
||||
b_deg: f32,
|
||||
ascendant_deg: f32,
|
||||
rot_offset_deg: f32,
|
||||
r: f32,
|
||||
color: Hsla,
|
||||
) {
|
||||
let (xa, ya) = polar_to_screen(a_deg, ascendant_deg, rot_offset_deg, r);
|
||||
let (xb, yb) = polar_to_screen(b_deg, ascendant_deg, rot_offset_deg, r);
|
||||
let mut builder = PathBuilder::stroke(px(1.0));
|
||||
builder.move_to(point(px(cx + xa), px(cy + ya)));
|
||||
builder.line_to(point(px(cx + xb), px(cy + yb)));
|
||||
if let Ok(path) = builder.build() {
|
||||
window.paint_path(path, color);
|
||||
}
|
||||
}
|
||||
|
||||
// =====================================================================
|
||||
// Geometry helpers
|
||||
// =====================================================================
|
||||
|
||||
/// Mapea una longitud eclíptica + ascendente + rotación adicional → (x, y)
|
||||
/// **relativos al centro del lienzo** (positivo hacia derecha/abajo).
|
||||
fn polar_to_screen(
|
||||
longitude_deg: f32,
|
||||
ascendant_deg: f32,
|
||||
rot_offset_deg: f32,
|
||||
radius: f32,
|
||||
) -> (f32, f32) {
|
||||
// Convención: el Asc cae a las 9 (θ=π). A más longitud, más
|
||||
// contrarreloj visual → θ decrece.
|
||||
let deg = 180.0 - (longitude_deg - ascendant_deg + rot_offset_deg);
|
||||
let rad = deg * PI / 180.0;
|
||||
(radius * rad.cos(), radius * rad.sin())
|
||||
}
|
||||
|
||||
fn centered_glyph(
|
||||
x: f32,
|
||||
y: f32,
|
||||
box_size: f32,
|
||||
font_size: f32,
|
||||
text: SharedString,
|
||||
color: Hsla,
|
||||
) -> gpui::Div {
|
||||
div()
|
||||
.absolute()
|
||||
.left(px(x - box_size / 2.0))
|
||||
.top(px(y - box_size / 2.0))
|
||||
.w(px(box_size))
|
||||
.h(px(box_size))
|
||||
.flex()
|
||||
.items_center()
|
||||
.justify_center()
|
||||
.text_size(px(font_size))
|
||||
.text_color(color)
|
||||
.child(text)
|
||||
}
|
||||
|
||||
fn with_alpha(c: Hsla, a: f32) -> Hsla {
|
||||
hsla(c.h, c.s, c.l, a.clamp(0.0, 1.0))
|
||||
}
|
||||
|
||||
// =====================================================================
|
||||
// Symbol → unicode / theme
|
||||
// =====================================================================
|
||||
|
||||
fn sign_unicode(name: &str) -> &'static str {
|
||||
match name {
|
||||
"aries" => "♈",
|
||||
"taurus" => "♉",
|
||||
"gemini" => "♊",
|
||||
"cancer" => "♋",
|
||||
"leo" => "♌",
|
||||
"virgo" => "♍",
|
||||
"libra" => "♎",
|
||||
"scorpio" => "♏",
|
||||
"sagittarius" => "♐",
|
||||
"capricorn" => "♑",
|
||||
"aquarius" => "♒",
|
||||
"pisces" => "♓",
|
||||
_ => "?",
|
||||
}
|
||||
}
|
||||
|
||||
fn planet_unicode(name: &str) -> &'static str {
|
||||
match name {
|
||||
"sun" => "☉",
|
||||
"moon" => "☽",
|
||||
"mercury" => "☿",
|
||||
"venus" => "♀",
|
||||
"mars" => "♂",
|
||||
"jupiter" => "♃",
|
||||
"saturn" => "♄",
|
||||
"uranus" => "♅",
|
||||
"neptune" => "♆",
|
||||
"pluto" => "♇",
|
||||
"north_node" => "☊",
|
||||
"south_node" => "☋",
|
||||
"chiron" => "⚷",
|
||||
"lilith" => "⚸",
|
||||
"ceres" => "⚳",
|
||||
"pallas" => "⚴",
|
||||
"juno" => "⚵",
|
||||
"vesta" => "⚶",
|
||||
_ => "•",
|
||||
}
|
||||
}
|
||||
|
||||
fn planet_color(p: &AstroPalette, name: &str) -> Hsla {
|
||||
let planet = match name {
|
||||
"sun" => Planet::Sun,
|
||||
"moon" => Planet::Moon,
|
||||
"mercury" => Planet::Mercury,
|
||||
"venus" => Planet::Venus,
|
||||
"mars" => Planet::Mars,
|
||||
"jupiter" => Planet::Jupiter,
|
||||
"saturn" => Planet::Saturn,
|
||||
"uranus" => Planet::Uranus,
|
||||
"neptune" => Planet::Neptune,
|
||||
"pluto" => Planet::Pluto,
|
||||
"chiron" => Planet::Chiron,
|
||||
"north_node" => Planet::NorthNode,
|
||||
"south_node" => Planet::SouthNode,
|
||||
"lilith" => Planet::Lilith,
|
||||
_ => return p.fg_text_fallback(),
|
||||
};
|
||||
p.planet(planet)
|
||||
}
|
||||
|
||||
fn sign_element_by_index(i: usize) -> Element {
|
||||
match i % 4 {
|
||||
0 => Element::Fire,
|
||||
1 => Element::Earth,
|
||||
2 => Element::Air,
|
||||
_ => Element::Water,
|
||||
}
|
||||
}
|
||||
|
||||
fn element_color_for_sign(p: &AstroPalette, name: &str) -> Hsla {
|
||||
let elem = match name {
|
||||
"aries" | "leo" | "sagittarius" => Element::Fire,
|
||||
"taurus" | "virgo" | "capricorn" => Element::Earth,
|
||||
"gemini" | "libra" | "aquarius" => Element::Air,
|
||||
"cancer" | "scorpio" | "pisces" => Element::Water,
|
||||
_ => return p.fg_text_fallback(),
|
||||
};
|
||||
p.element(elem)
|
||||
}
|
||||
|
||||
fn aspect_color(p: &AstroPalette, kind: &str) -> Hsla {
|
||||
let k = match kind {
|
||||
"conjunction" => TAspectKind::Conjunction,
|
||||
"opposition" => TAspectKind::Opposition,
|
||||
"trine" => TAspectKind::Trine,
|
||||
"square" => TAspectKind::Square,
|
||||
"sextile" => TAspectKind::Sextile,
|
||||
"quincunx" => TAspectKind::Quincunx,
|
||||
"semi_sextile" => TAspectKind::Semisextile,
|
||||
"semi_square" => TAspectKind::Semisquare,
|
||||
"sesquiquadrate" => TAspectKind::Sesquisquare,
|
||||
"quintile" => TAspectKind::Quintile,
|
||||
"biquintile" => TAspectKind::Biquintile,
|
||||
_ => return p.minor_aspect,
|
||||
};
|
||||
p.aspect(k)
|
||||
}
|
||||
|
||||
// =====================================================================
|
||||
// Adendum: fallback color cuando la paleta no tiene match
|
||||
// =====================================================================
|
||||
|
||||
impl AstroPaletteExt for AstroPalette {
|
||||
fn fg_text_fallback(&self) -> Hsla {
|
||||
if self.is_dark {
|
||||
hsla(0.0, 0.0, 0.85, 1.0)
|
||||
} else {
|
||||
hsla(0.0, 0.0, 0.25, 1.0)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
trait AstroPaletteExt {
|
||||
fn fg_text_fallback(&self) -> Hsla;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user