8000 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
Open
@YichiZhang0613

Description

@YichiZhang0613

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)
    };
}

There are a lot of similar situations.

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);
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0