{"record":{"id":"66331c80f3370b51","repo":"bevyengine/bevy","slug":"need-at-least-two-samples-to-create-an-evencore-b","errorCode":null,"errorMessage":"Need at least two samples to create an EvenCore, but {samples} were provided","messagePattern":"Need at least two samples to create an EvenCore, but (.+?) were provided","errorType":"exception","errorClass":"EvenCoreError","httpStatus":null,"severity":"error","filePath":"crates/bevy_math/src/curve/cores.rs","lineNumber":143,"sourceCode":"    /// formed by interpolating them.\n    ///\n    /// # Invariants\n    /// This must always be a bounded interval; i.e. its endpoints must be finite.\n    pub domain: Interval,\n\n    /// The samples that are interpolated to extract values.\n    ///\n    /// # Invariants\n    /// This must always have a length of at least 2.\n    pub samples: Vec<T>,\n}\n\n/// An error indicating that an [`EvenCore`] could not be constructed.\n#[derive(Debug, Error)]\n#[error(\"Could not construct an EvenCore\")]\npub enum EvenCoreError {\n    /// Not enough samples were provided.\n    #[error(\"Need at least two samples to create an EvenCore, but {samples} were provided\")]\n    NotEnoughSamples {\n        /// The number of samples that were provided.\n        samples: usize,\n    },\n\n    /// Unbounded domains are not compatible with `EvenCore`.\n    #[error(\"Cannot create an EvenCore over an unbounded domain\")]\n    UnboundedDomain,\n}\n\n#[cfg(feature = \"alloc\")]\nimpl<T> EvenCore<T> {\n    /// Create a new [`EvenCore`] from the specified `domain` and `samples`. The samples are\n    /// regarded to be evenly spaced within the given domain interval, so that the outermost\n    /// samples form the boundary of that interval. An error is returned if there are not at\n    /// least 2 samples or if the given domain is unbounded.\n    #[inline]\n    pub fn new(","sourceCodeStart":125,"sourceCodeEnd":161,"githubUrl":"https://github.com/bevyengine/bevy/blob/396ca727080776bd313bb892423b7d94e03b81b4/crates/bevy_math/src/curve/cores.rs#L125-L161","documentation":"EvenCoreError::NotEnoughSamples is returned by EvenCore::new when fewer than 2 samples are provided. EvenCore interpolates between consecutive samples evenly spaced over a domain; with one sample there is nothing to interpolate between (the type documents a length >= 2 invariant on `samples`). `samples` reports the count you passed.","triggerScenarios":"EvenCore::new(domain, vec![value]) or an empty vec; higher-level curve constructors (e.g. even-sample curves in bevy_math curve module) that forward a sample list which degenerated to a single element.","commonSituations":"Sampling a function at a single point; a slider/asset that yields one keyframe; generated sample lists where the count is computed as (end-start)/step and rounds to 1.","solutions":["Provide at least 2 samples — the outermost ones define the domain boundary.","If you genuinely have one value, use a constant curve (e.g. ConstantCurve) instead of an interpolated core.","Compute sample counts carefully: use a step that yields >= 2 points, or build samples with (0..=n) inclusive ranges."],"exampleFix":"// before\nlet core = EvenCore::new(Interval::new(0.0, 1.0)?, vec![0.0f32]); // NotEnoughSamples { samples: 1 }\n\n// after\nlet core = EvenCore::new(Interval::new(0.0, 1.0)?, vec![0.0f32, 1.0])?;\n// or for a single value:\nlet curve = ConstantCurve::new(Interval::new(0.0, 1.0)?, 0.0f32);","handlingStrategy":"validation","validationCode":"if samples.len() >= 2 {\n    let core = EvenCore::new(domain, samples)?;\n}","typeGuard":null,"tryCatchPattern":"let core = match EvenCore::new(domain, samples) {\n    Ok(core) => core,\n    Err(EvenCoreError::NotEnoughSamples { samples }) => {\n        debug_assert!(samples < 2);\n        return Ok(()); // or use ConstantCurve for a single value\n    }\n    Err(e) => return Err(e.into()),\n};","preventionTips":["Treat a single value as a constant, not a curve: reach for ConstantCurve.","When generating samples from a range+step, verify the step yields >= 2 samples.","Use inclusive ranges (0..=n) when computing sample counts to avoid off-by-one empties."],"tags":["rust","bevy","math","curve","runtime"],"backgroundTag":"insufficient-curve-samples","analyzedSha":"396ca727080776bd313bb892423b7d94e03b81b4","analyzedAt":"2026-08-20T16:12:39.808Z","contentChangedAt":"2026-08-20T16:12:39.808Z","schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}