#clipping #line #algorithm #graphics

line-clipping

A simple crate implementing line clipping algorithms

3 unstable releases

0.2.1 Nov 20, 2024
0.2.0 Nov 20, 2024
0.1.0 Nov 18, 2024

#432 in Algorithms

Download history 374/week @ 2024-11-16 491/week @ 2024-11-23 228/week @ 2024-11-30 269/week @ 2024-12-07 336/week @ 2024-12-14 150/week @ 2024-12-21 285/week @ 2024-12-28 571/week @ 2025-01-04 315/week @ 2025-01-11 242/week @ 2025-01-18 285/week @ 2025-01-25 562/week @ 2025-02-01 435/week @ 2025-02-08 514/week @ 2025-02-15 393/week @ 2025-02-22 582/week @ 2025-03-01

2,015 downloads per month

MIT/Apache

14KB
230 lines

Line clipping

A rust crate to implement several line clipping algorithms. See the documentation for more information. The choice of algorithms is based on the following article which contains a good summary of the options:

Matthes D, Drakopoulos V. Line Clipping in 2D: Overview, Techniques and Algorithms. J Imaging. 2022 Oct 17;8(10):286. doi: 10.3390/jimaging8100286. PMID: 36286380; PMCID: PMC9605407.

Supports:

  • Cohen-Sutherland

TODO

  • Cyrus-Beck
  • Liang-Barsky
  • Nicholl-Lee-Nicholl
  • More comprehensive testing

Installation

cargo add line-clipping

Usage

use line_clipping::{
    LineSegment, Point, Window,
    cohen_sutherland::clip_line,
}

let line = clip_line(
    LineSegment::new(Point::new(0.0, 0.0), Point::new(10.0, 10.0)),
    Window::new(1.0, 9.0, 1.0, 9.0),
);

License

Copyright (c) 2024 Josh McKinney

This project is licensed under either of

at your option.

Contribution

Contributions are welcome! Please open an issue or submit a pull request.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~110KB