10000 Code Comment Inconsistency · Issue #95 · ricosjp/truck · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Code Comment Inconsistency #95

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
YichiZhang0613 opened this issue May 10, 2025 · 0 comments
Open

Code Comment Inconsistency #95

YichiZhang0613 opened this issue May 10, 2025 · 0 comments

Comments

@YichiZhang0613
Copy link

In crate truck-geotrait, truck-master/truck-geotrait/src/algo/surface.rs and truck-master/truck-geotrait/src/algo/curve.rs,

/// # Panics
///
/// `tol` must be more than `TOLERANCE`.
#[inline(always)]
pub fn parameter_division<S>(
    surface: &S,
    (urange, vrange): ((f64, f64), (f64, f64)),
    tol: f64,
) -> (Vec<f64>, Vec<f64>)
where
    S: ParametricSurface,
    S::Point: EuclideanSpace<Scalar = f64> + MetricSpace<Metric = f64> + HashGen<f64>,
{
    nonpositive_tolerance!(tol);
    let (mut udiv, mut vdiv) = (vec![urange.0, urange.1], vec![vrange.0, vrange.1]);
    sub_parameter_division(surface, (&mut udiv, &mut vdiv), tol);
    (udiv, vdiv)
}
/// # Panics
///
/// `tol` must be more than `TOLERANCE`.
pub fn parameter_division<C>(curve: &C, range: (f64, f64), tol: f64) -> (Vec<f64>, Vec<C::Point>)
where
    C: ParametricCurve,
    C::Point: EuclideanSpace<Scalar = f64> + MetricSpace<Metric = f64> + HashGen<f64>, {
    nonpositive_tolerance!(tol);
    sub_parameter_division(
        curve,
        range,
        (curve.subs(range.0), curve.subs(range.1)),
        tol,
        100,
    )
}

above 2 functions' comments indicate tol must > TOLERANCE otherwise they will panic while actually code will not panic when tol = TOLERANCE.

macro_rules! nonpositive_tolerance {
    ($tol: expr, $minimum: expr) => {
        assert!(
            $tol >= $minimum,
            "tolerance must be no less than {:e}",
            $minimum
        );
    };
    ($tol: expr) => {
        nonpositive_tolerance!($tol, TOLERANCE)
    };
}

In truck-master/truck-platform/src/buffer_handler.rs,
The comment indicates that code will panic when dest.size < self.size while code panic when self.size < dest.size and assertion message indicates that dest.size must < self.size otherwise it will panic, those three are inconsistent.

/// Copy the values of buffer to `dest`.
    /// # Panic
    /// Panic occurs if the size of `dest` is smaller than the one of `self`.
    #[inline(always)]
    pub fn copy_buffer(&self, encoder: &mut CommandEncoder, dest: &BufferHandler) {
        assert!(
            self.size < dest.size,
            "The destination buffer size must be shorter than the source buffer size."
        );
        encoder.copy_buffer_to_buffer(&self.buffer, 0, &dest.buffer, 0, self.size);
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant
0