Skip to content

Commit d0cac1c

Browse files
committed
style: cargo fmt over the new imgproc additions
1 parent f1ab8d3 commit d0cac1c

6 files changed

Lines changed: 35 additions & 36 deletions

File tree

crates/yscv-imgproc/src/core.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,6 @@ pub use ops::connected_components_4;
105105
pub use ops::connected_components_with_stats;
106106
/// Connected-component labelling with statistics (8-connectivity).
107107
pub use ops::connected_components_with_stats_8;
108-
/// Minimum enclosing circle of a 2D point set (Welzl, exact).
109-
pub use ops::min_enclosing_circle;
110108
/// Compute contour area (signed, using shoelace formula).
111109
pub use ops::contour_area;
112110
/// Compute the convex hull of a set of 2D points.
@@ -124,24 +122,24 @@ pub use ops::detect_orb;
124122
pub use ops::detect_surf_keypoints;
125123
/// Morphological dilation with arbitrary structuring element.
126124
pub use ops::dilate;
127-
/// Dilation with an all-ones square kernel — separable, O(n) per pass.
128-
pub use ops::dilate_box;
129-
/// Binary dilation via sliding-window counts (~2 ops/pixel).
130-
pub use ops::dilate_binary_box;
131-
/// Binary erosion via sliding-window counts (~2 ops/pixel).
132-
pub use ops::erode_binary_box;
133-
/// Erosion with an all-ones square kernel — separable, O(n) per pass.
134-
pub use ops::erode_box;
135125
/// Morphological dilation with 3x3 square structuring element.
136126
/// Input: `[H, W]` grayscale f32.
137127
pub use ops::dilate_3x3;
128+
/// Binary dilation via sliding-window counts (~2 ops/pixel).
129+
pub use ops::dilate_binary_box;
130+
/// Dilation with an all-ones square kernel — separable, O(n) per pass.
131+
pub use ops::dilate_box;
138132
/// Euclidean distance transform. Input: `[H, W]` binary f32.
139133
pub use ops::distance_transform;
140134
/// Morphological erosion with arbitrary structuring element.
141135
pub use ops::erode;
142136
/// Morphological erosion with 3x3 square structuring element.
143137
/// Input: `[H, W]` grayscale f32.
144138
pub use ops::erode_3x3;
139+
/// Binary erosion via sliding-window counts (~2 ops/pixel).
140+
pub use ops::erode_binary_box;
141+
/// Erosion with an all-ones square kernel — separable, O(n) per pass.
142+
pub use ops::erode_box;
145143
/// Farneback dense optical flow between two frames.
146144
pub use ops::farneback_flow;
147145
/// FAST corner detection (configurable arc length).
@@ -208,6 +206,8 @@ pub use ops::median_blur_3x3;
208206
pub use ops::median_filter;
209207
/// Minimum area rotated rectangle of a set of 2D points.
210208
pub use ops::min_area_rect;
209+
/// Minimum enclosing circle of a 2D point set (Welzl, exact).
210+
pub use ops::min_enclosing_circle;
211211
/// Morphological black-hat transform (closing - input).
212212
pub use ops::morph_blackhat;
213213
/// Morphological gradient (dilation - erosion) with 3x3 element.

crates/yscv-imgproc/src/ops/contours.rs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,9 @@ pub fn min_enclosing_circle(points: &[(f32, f32)]) -> Option<((f32, f32), f32)>
639639
// без внешнего RNG, воспроизводимо между запусками.
640640
let mut state: u64 = 0x9E37_79B9_7F4A_7C15;
641641
for i in (1..pts.len()).rev() {
642-
state = state.wrapping_mul(6364136223846793005).wrapping_add(1442695040888963407);
642+
state = state
643+
.wrapping_mul(6364136223846793005)
644+
.wrapping_add(1442695040888963407);
643645
let j = (state >> 33) as usize % (i + 1);
644646
pts.swap(i, j);
645647
}
@@ -648,11 +650,7 @@ pub fn min_enclosing_circle(points: &[(f32, f32)]) -> Option<((f32, f32), f32)>
648650
let c = ((a.0 + b.0) / 2.0, (a.1 + b.1) / 2.0);
649651
(c, dist(c, a))
650652
}
651-
fn circle_from3(
652-
a: (f64, f64),
653-
b: (f64, f64),
654-
c: (f64, f64),
655-
) -> Option<((f64, f64), f64)> {
653+
fn circle_from3(a: (f64, f64), b: (f64, f64), c: (f64, f64)) -> Option<((f64, f64), f64)> {
656654
let d = 2.0 * (a.0 * (b.1 - c.1) + b.0 * (c.1 - a.1) + c.0 * (a.1 - b.1));
657655
if d.abs() < 1e-12 {
658656
return None; // коллинеарны
@@ -696,10 +694,7 @@ pub fn min_enclosing_circle(points: &[(f32, f32)]) -> Option<((f32, f32), f32)>
696694
}
697695

698696
#[allow(clippy::cast_possible_truncation)]
699-
Some((
700-
(circle.0.0 as f32, circle.0.1 as f32),
701-
circle.1 as f32,
702-
))
697+
Some(((circle.0.0 as f32, circle.0.1 as f32), circle.1 as f32))
703698
}
704699

705700
/// Compute region properties from a label image.

crates/yscv-imgproc/src/ops/mod.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ pub use color::{
7171
};
7272
pub use contours::{
7373
ComponentStats, Contour, RegionProp, approx_poly_dp, arc_length, bounding_rect,
74-
connected_components_with_stats, connected_components_with_stats_8, contour_area,
75-
convex_hull, find_contours, fit_ellipse, min_enclosing_circle,
76-
homography_4pt, hu_moments, min_area_rect, ransac_homography, region_props,
74+
connected_components_with_stats, connected_components_with_stats_8, contour_area, convex_hull,
75+
find_contours, fit_ellipse, homography_4pt, hu_moments, min_area_rect, min_enclosing_circle,
76+
ransac_homography, region_props,
7777
};
7878
pub use draw::{
7979
Detection as DrawDetection, draw_circle, draw_detections, draw_line, draw_polylines, draw_rect,
@@ -106,8 +106,9 @@ pub use inpaint::inpaint_telea;
106106
pub use intensity::{adjust_gamma, adjust_log, rescale_intensity};
107107
pub use io::{imread, imread_gray, imwrite};
108108
pub use morphology::{
109-
closing_3x3, dilate, dilate_3x3, erode, erode_3x3, morph_blackhat, morph_gradient_3x3,
110-
morph_tophat, opening_3x3, remove_small_objects, skeletonize, dilate_binary_box, dilate_box, erode_binary_box, erode_box,
109+
closing_3x3, dilate, dilate_3x3, dilate_binary_box, dilate_box, erode, erode_3x3,
110+
erode_binary_box, erode_box, morph_blackhat, morph_gradient_3x3, morph_tophat, opening_3x3,
111+
remove_small_objects, skeletonize,
111112
};
112113
pub use nms::{BBox, TemplateMatchMethod, TemplateMatchResult, nms, template_match};
113114
pub use normalize::normalize;

crates/yscv-imgproc/src/ops/morphology.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1242,7 +1242,11 @@ fn box_filter_2d(
12421242
for y in 0..h {
12431243
row[r..r + w].copy_from_slice(&data[y * w..(y + 1) * w]);
12441244
for (i, &v) in row.iter().enumerate() {
1245-
left[i] = if i % ksize == 0 { v } else { pick(left[i - 1], v) };
1245+
left[i] = if i % ksize == 0 {
1246+
v
1247+
} else {
1248+
pick(left[i - 1], v)
1249+
};
12461250
}
12471251
for i in (0..padded_w).rev() {
12481252
right[i] = if (i + 1) % ksize == 0 || i + 1 == padded_w {

crates/yscv-imgproc/src/tests/contour.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -281,14 +281,9 @@ fn min_enclosing_circle_exact_cases() {
281281
assert!((r - std::f32::consts::SQRT_2).abs() < 1e-5);
282282

283283
// точка внутри не влияет
284-
let ((_, _), r2) = min_enclosing_circle(&[
285-
(0.0, 0.0),
286-
(2.0, 0.0),
287-
(2.0, 2.0),
288-
(0.0, 2.0),
289-
(1.0, 1.0),
290-
])
291-
.unwrap();
284+
let ((_, _), r2) =
285+
min_enclosing_circle(&[(0.0, 0.0), (2.0, 0.0), (2.0, 2.0), (0.0, 2.0), (1.0, 1.0)])
286+
.unwrap();
292287
assert!((r2 - std::f32::consts::SQRT_2).abs() < 1e-5);
293288

294289
assert!(min_enclosing_circle(&[]).is_none());

crates/yscv-imgproc/src/tests/morphology.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,9 @@ fn box_morphology_matches_generic_ones_kernel() {
387387
let mut state = 0x1234_5678_u64;
388388
let mut data = Vec::with_capacity(h * w);
389389
for _ in 0..h * w {
390-
state = state.wrapping_mul(6364136223846793005).wrapping_add(1442695040888963407);
390+
state = state
391+
.wrapping_mul(6364136223846793005)
392+
.wrapping_add(1442695040888963407);
391393
data.push(((state >> 33) % 1000) as f32 / 100.0);
392394
}
393395
let img = Tensor::from_vec(vec![h, w, 1], data).unwrap();
@@ -417,7 +419,9 @@ fn binary_box_matches_generic_ones_kernel() {
417419
let mut state = 0xDEAD_BEEF_u64;
418420
let mut data = Vec::with_capacity(h * w);
419421
for _ in 0..h * w {
420-
state = state.wrapping_mul(6364136223846793005).wrapping_add(1442695040888963407);
422+
state = state
423+
.wrapping_mul(6364136223846793005)
424+
.wrapping_add(1442695040888963407);
421425
data.push(if (state >> 33) % 3 == 0 { 1.0f32 } else { 0.0 });
422426
}
423427
let img = Tensor::from_vec(vec![h, w, 1], data).unwrap();

0 commit comments

Comments
 (0)