qchull 2.0.1-beta.0

Provides quick convex hull algorithm
// Copyright (C) 2020-2025 qchull authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use glam_det::{UnitVec3, Vec3};

#[inline]
pub(crate) fn normalize_and_len(normal: Vec3, invalid_len: f32) -> (UnitVec3, f32) {
    if let Some((normal, area)) = normal.try_normalize_to_unit_and_length(1e-8) {
        (normal, area)
    } else {
        (UnitVec3::X, invalid_len)
    }
}
#[cfg(test)]
mod tests {
    use approx_det::assert_relative_eq;
    use glam_det::{UnitVec3, Vec3};
    use wasm_bindgen_test::{wasm_bindgen_test_configure, *};
    wasm_bindgen_test_configure!(run_in_browser);
    #[test]
    #[wasm_bindgen_test]
    fn test_normalize_zero_len_vec() {
        let zero_vec = Vec3::new(0.0, 0.0, 1e-9);
        let (unit_vec, len) = super::normalize_and_len(zero_vec, 0.0);
        assert_relative_eq!(unit_vec, UnitVec3::X);
        assert_relative_eq!(len, 0.0);
    }

    #[test]
    #[wasm_bindgen_test]
    fn test_normalize_one_len_vec() {
        let value = Vec3::new(0.0, 0.0, 1f32);
        let (unit_vec, len) = super::normalize_and_len(value, 0.0);
        assert_relative_eq!(unit_vec, UnitVec3::Z);
        assert_relative_eq!(len, 1.0);
    }
}