rust-geometry API documentation
Project documentation Docs

File: src/geometry.rs

1// --------------------------------------------------------------------------------------------------2// SPDX-License-Identifier: Apache-2.03// SPDX-FileCopyrightText: 2026 cpdocs developers4// --------------------------------------------------------------------------------------------------5/// A three-dimensional vector.6#[derive(Clone, Copy, Debug, PartialEq)]7pub struct Vector3 {8    /// X component.9    pub x: f64,10    /// Y component.11    pub y: f64,12    /// Z component.13    pub z: f64,14}15 16/// Return the dot product of two vectors.17pub fn dot(lhs: Vector3, rhs: Vector3) -> f64 {18    lhs.x * rhs.x + lhs.y * rhs.y + lhs.z * rhs.z19}20 21/// Return the dot products of corresponding vector pairs.22///23/// This API exists only in the `batch` Cargo feature.24#[cfg(feature = "batch")]25pub fn dot_many(lhs: &[Vector3], rhs: &[Vector3]) -> Vec<f64> {26    lhs.iter()27        .zip(rhs)28        .map(|(&left, &right)| dot(left, right))29        .collect()30}31 32/// Return a dot product only when both vectors have non-zero length.33///34/// This API exists only in the `checked` Cargo feature.35#[cfg(feature = "checked")]36pub fn checked_dot(lhs: Vector3, rhs: Vector3) -> Option<f64> {37    if crate::internal::norm_squared(lhs) == 0.0 || crate::internal::norm_squared(rhs) == 0.0 {38        None39    } else {40        Some(dot(lhs, rhs))41    }42}