docs: 逐模块细化中文逻辑注释并覆盖测试与示例
This commit is contained in:
@@ -8,7 +8,7 @@ pub struct Point {
|
||||
}
|
||||
|
||||
impl Point {
|
||||
/// 构造本类型并初始化其状态;资源建立和默认字段以函数体为准。
|
||||
/// 直接保存二维坐标;不缩放、不舍入,也不检查有限性,调用方负责坐标空间和输入校验。
|
||||
pub const fn new(x: f32, y: f32) -> Self {
|
||||
Self { x, y }
|
||||
}
|
||||
@@ -24,7 +24,7 @@ pub struct Rect {
|
||||
}
|
||||
|
||||
impl Rect {
|
||||
/// 构造本类型并初始化其状态;资源建立和默认字段以函数体为准。
|
||||
/// 直接保存左上角和宽高;不归一化负尺寸,布局调用方需先产生合法边界。
|
||||
pub const fn new(x: f32, y: f32, width: f32, height: f32) -> Self {
|
||||
Self {
|
||||
x,
|
||||
@@ -34,7 +34,7 @@ impl Rect {
|
||||
}
|
||||
}
|
||||
|
||||
/// 判断给定点是否位于目标范围;需要相机转换的类型会先转换再判断。
|
||||
/// 用闭区间比较判断点是否命中,左右上下边缘都计入;调用前需将点转换到矩形所在空间。
|
||||
pub fn contains(self, point: Point) -> bool {
|
||||
point.x >= self.x
|
||||
&& point.x <= self.x + self.width
|
||||
@@ -49,6 +49,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn rectangle_contains_edges_but_not_outside_points() {
|
||||
// 同时验证左上和右下边界被包含,以及仅越过左边界的小偏差也会被排除。
|
||||
let rect = Rect::new(10.0, 20.0, 30.0, 40.0);
|
||||
assert!(rect.contains(Point::new(10.0, 20.0)));
|
||||
assert!(rect.contains(Point::new(40.0, 60.0)));
|
||||
|
||||
Reference in New Issue
Block a user