mod basics;
mod concave;
mod editing;
mod meets;
mod series;
use crate::guide::{EIGHT_FOLD_INDICES, Goal, GoalContext, Group, Guide};
use indicatrix::geometry::meet_solver::MeetConstraint;
use indicatrix_cut_core::{ConstraintTier, Design};
const MAIN: [f64; 8] = EIGHT_FOLD_INDICES;
const STAR: [f64; 8] = [6.0, 18.0, 30.0, 42.0, 54.0, 66.0, 78.0, 90.0];
const FORM: &[Group] = &[Group::TierForm, Group::TierTable, Group::History];
const FORM_ADVANCED: &[Group] = &[
Group::TierForm,
Group::TierTable,
Group::Advanced,
Group::History,
];
const TABLE: &[Group] = &[Group::TierTable, Group::History];
const TABLE_ADVANCED: &[Group] = &[Group::TierTable, Group::Advanced, Group::History];
#[must_use]
pub fn guides() -> Vec<Guide> {
let mut guides = Vec::new();
guides.extend(basics::guides());
guides.extend(meets::guides());
guides.extend(series::guides());
guides.extend(editing::guides());
guides.extend(concave::guides());
guides
}
const fn check(label: &'static str, test: fn(&GoalContext<'_>) -> bool) -> Goal {
Goal::Check { label, test }
}
fn position(design: &Design, name: &str) -> Option<usize> {
design.tiers.iter().position(|tier| {
tier.names()
.iter()
.any(|known| known.trim().eq_ignore_ascii_case(name.trim()))
})
}
fn tier_called<'a>(design: &'a Design, name: &str) -> Option<&'a ConstraintTier> {
position(design, name).and_then(|at| design.tiers.get(at))
}
fn meets_named(design: &Design, tier: &str, target: &str) -> bool {
tier_called(design, tier).is_some_and(|found| {
matches!(
&found.constraint,
MeetConstraint::MeetNamed(names)
if names.iter().any(|name| name.trim().eq_ignore_ascii_case(target.trim()))
)
})
}
fn is_driven(design: &Design, name: &str) -> bool {
position(design, name).is_some_and(|at| design.is_tier_driven(at))
}
fn detached_is(design: &Design, name: &str, wanted: &[f64]) -> bool {
tier_called(design, name).is_some_and(|found| {
found.detached.len() == wanted.len()
&& wanted
.iter()
.all(|want| found.detached.iter().any(|have| (have - want).abs() < 1e-6))
})
}