contour_tracing/
lib.rs

1/*
2 * Contour tracing library
3 * https://github.com/STPR/contour_tracing
4 *
5 * Copyright (c) 2022, STPR - https://github.com/STPR
6 *
7 * SPDX-License-Identifier: EUPL-1.2
8 */
9
10//! A 2D library to trace contours.
11//!
12//! # Features
13//! Core features:
14//! - Trace contours using the Theo Pavlidis' algorithm (connectivity: 4-connected)
15//! - Trace **outlines** in **clockwise direction**
16//! - Trace **holes** in **counterclockwise direction**
17//! - Input format: a 2D array of bits or an image buffer
18//! - Output format: a string of SVG Path commands
19//!
20//! Manual parameters:
21//! - User can specify to close or not the paths (with the SVG Path **Z** command)
22//! 
23//! # Examples
24//! Have a look at the different functions inside the modules below.
25
26#![cfg_attr(docsrs, feature(doc_cfg))]
27
28const MN: [(i8, i8); 8] = [(0, -1), (1, -1), (1, 0), (1, 1), (0, 1), (-1, 1), (-1, 0), (-1, -1)]; // Moore neighborhood
29
30/*
31 contours: an array of contours
32 buffer: an image buffer
33 ol: outlines level
34 hl: holes level
35 rn: reachable neighbor - for the outlines: 0: none, 1: front left,  2: front, 3: front right
36                        - for the holes:    0: none, 1: front right, 2: front, 3: front left
37 o: orientation, e.g. to the east:
38
39          N
40    ┏━━━━━━━━━━━┓
41    ┃ 7   0   1 ┃
42  W ┃ 6   o > 2 ┃ E   o = [2, 3, 4, 5, 6, 7, 0, 1]
43    ┃ 5   4   3 ┃
44    ┗━━━━━━━━━━━┛
45          S
46*/
47
48#[cfg(feature = "array")]
49#[cfg_attr(docsrs, doc(cfg(feature = "array")))]
50pub mod array;
51
52#[cfg(feature = "image")]
53#[cfg_attr(docsrs, doc(cfg(feature = "image")))]
54pub mod image;