#algorithm #clipping #line #graphics

line-clipping

A simple crate implementing line clipping algorithms

12 releases

Uses new Rust 2024

0.3.7 Mar 27, 2026
0.3.6 Mar 27, 2026
0.3.5 Nov 29, 2025
0.3.4 Sep 28, 2025
0.1.0 Nov 18, 2024

#144 in Algorithms

Download history 99265/week @ 2026-01-25 144533/week @ 2026-02-01 146582/week @ 2026-02-08 176704/week @ 2026-02-15 194093/week @ 2026-02-22 214719/week @ 2026-03-01 232903/week @ 2026-03-08 237665/week @ 2026-03-15 241972/week @ 2026-03-22 277827/week @ 2026-03-29 272489/week @ 2026-04-05 311289/week @ 2026-04-12 305121/week @ 2026-04-19 379814/week @ 2026-04-26 454566/week @ 2026-05-03 494830/week @ 2026-05-10

1,662,092 downloads per month
Used in 1,614 crates (3 directly)

MIT/Apache

23KB
242 lines

Line clipping

crate-badge docs-badge license-badge
github-badge build-badge codecov-badge

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:

TODO

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

Installation

cargo add line-clipping

Minimum supported Rust version

The crate is built with Rust 1.85 to match the 2024 edition. The MSRV may increase in a future minor release, but will be noted in the changelog.

Usage

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

let line = LineSegment::new(Point::new(-10.0, -10.0), Point::new(20.0, 20.0));
let window = Window::new(0.0, 10.0, 0.0, 10.0);
let clipped_line = clip_line(line, window);

License

Copyright (c) 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

~90KB