{"id":20608108,"url":"https://github.com/tirithen/clipper2","last_synced_at":"2025-04-15T04:10:00.039Z","repository":{"id":225656966,"uuid":"766528178","full_name":"tirithen/clipper2","owner":"tirithen","description":"A polygon Clipping and Offsetting library for Rust.","archived":false,"fork":false,"pushed_at":"2024-07-30T09:00:39.000Z","size":222,"stargazers_count":8,"open_issues_count":1,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-10-31T12:02:01.415Z","etag":null,"topics":["2d-graphics","algorithm","algorithms","boolean","cnc","game-development","geometry","geospatial","gis","offsetting","path-tracing","rust"],"latest_commit_sha":null,"homepage":"https://crates.io/crates/clipper2","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tirithen.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE-APACHE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-03-03T14:16:41.000Z","updated_at":"2024-10-12T15:41:36.000Z","dependencies_parsed_at":"2024-06-01T10:29:36.026Z","dependency_job_id":"ba3ba2d4-b8a9-4f7c-92eb-b801c7920ea3","html_url":"https://github.com/tirithen/clipper2","commit_stats":null,"previous_names":["tirithen/clipper2"],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tirithen%2Fclipper2","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tirithen%2Fclipper2/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tirithen%2Fclipper2/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tirithen%2Fclipper2/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tirithen","download_url":"https://codeload.github.com/tirithen/clipper2/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224901289,"owners_count":17388950,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["2d-graphics","algorithm","algorithms","boolean","cnc","game-development","geometry","geospatial","gis","offsetting","path-tracing","rust"],"created_at":"2024-11-16T10:09:28.653Z","updated_at":"2024-11-16T10:09:29.381Z","avatar_url":"https://github.com/tirithen.png","language":"Rust","readme":"# clipper2\n\n[![crate.io](https://img.shields.io/crates/v/clipper2.svg)](https://crates.io/crates/clipper2)\n[![docs.rs](https://docs.rs/clipper2/badge.svg)](https://docs.rs/clipper2)\n\nA path/polygon clipping and offsetting library for Rust.\n\nThe focus of this crate is to provide an easy to use API, staying as close to\nthe core `Vec` and `fn` types as possible.\n\nThe create uses the [clipper2c-sys](https://crates.io/crates/clipper2c-sys)\ncrate that in turn is a Rust wrapper around the C++ version of\n[Clipper2](https://github.com/AngusJohnson/Clipper2).\n\n## Example\n\nThe below example uses macroquad to visualize the result of the operations and\nsome helpers from the `examples/` directory. See the examples directory for more\nexamples.\n\n```rust\nuse clipper2::*;\nuse helpers::{circle_path, draw_paths};\nuse macroquad::prelude::*;\n\nmod helpers;\n\n#[macroquad::main(\"Difference and inflate\")]\nasync fn main() -\u003e Result\u003c(), ClipperError\u003e {\n    let circle = circle_path((5.0, 5.0), 3.0, 32);\n    let circle2 = circle_path((7.0, 7.0), 1.0, 32);\n    let rectangle = vec![(0.0, 0.0), (5.0, 0.0), (5.0, 6.0), (0.0, 6.0)];\n\n    let result = circle\n        .to_clipper_subject()\n        .add_clip(circle2)\n        .add_clip(rectangle)\n        .difference(FillRule::default())?;\n\n    let result2 = result\n        .inflate(1.0, JoinType::Round, EndType::Polygon, 0.0)\n        .simplify(0.01, false);\n\n    loop {\n        clear_background(BLACK);\n        draw_paths(\u0026result, SKYBLUE);\n        draw_paths(\u0026result2, GREEN);\n        next_frame().await\n    }\n}\n```\n\nThis is how the resulting shapes looks:\n\n![Image displaying the result of the difference and inflate example](https://raw.githubusercontent.com/tirithen/clipper2/main/doc-assets/difference-and-inflate.png)\n\n## API uses f64, but i64 under the hood\n\nThe Clipper2 library is [using `i64` values](https://www.angusj.com/clipper2/Docs/Robustness.htm)\nto guarantee the robustness of all calculations. The C++ library exposes both\n`int64_t`/`i64` and `double`/`f64` versions of several types. This crate\ntherefore internally uses the `int64_t`/`i64` types only, but for now only\nexposes an `f64` API.\n\nThe types `Point`, `Path`, and `Paths` therefore offers a `PointScaler` trait\nand generic parameter that allows the user to choose the scaling is used when\nit interally converts from `f64` to `i64`. By default it uses the `Centi` struct\nthat will scale the values by `100`.\n\n## Early days\n\nThis project is in a super early stage and has for now only opened up a small\npart of what the C++ Clipper2 library has to offer. Expect breaking changes now\nand then for some more time to come as we find and explore more eregonomic ways\nof exposing the API in a Rust ideomatic way.\n\nPlease also feel free to come with suggestions on how the API can be simplified\nor send code contributions directly. See\n[CONTRIBUTING.md](https://github.com/tirithen/clipper2/blob/main/CONTRIBUTING.md)\nfor more details.\n\n## License\n\nLicensed under either of [Apache License, Version 2.0](https://github.com/tirithen/clipper2/blob/main/LICENSE-APACHE.md)\nor [MIT license](https://github.com/tirithen/clipper2/blob/main/LICENSE-MIT.md)\nat your option.\n\nUnless you explicitly state otherwise, any contribution intentionally submitted\nfor inclusion in Serde by you, as defined in the Apache-2.0 license, shall be\ndual licensed as above, without any additional terms or conditions.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftirithen%2Fclipper2","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftirithen%2Fclipper2","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftirithen%2Fclipper2/lists"}