pax_global_header00006660000000000000000000000064150662015350014515gustar00rootroot0000000000000052 comment=5394ebf7b17bd210dcf69fbdca00182a2faebcde joshka-line-clipping-464d84b/000077500000000000000000000000001506620153500160655ustar00rootroot00000000000000joshka-line-clipping-464d84b/.github/000077500000000000000000000000001506620153500174255ustar00rootroot00000000000000joshka-line-clipping-464d84b/.github/dependabot.yml000066400000000000000000000006541506620153500222620ustar00rootroot00000000000000version: 2 updates: # Maintain dependencies for Cargo - package-ecosystem: "cargo" directory: "/" schedule: interval: "weekly" groups: rust-dependencies: patterns: - "*" # Maintain dependencies for GitHub Actions - package-ecosystem: "github-actions" directory: "/" schedule: interval: "weekly" groups: github-actions: patterns: - "*" joshka-line-clipping-464d84b/.github/workflows/000077500000000000000000000000001506620153500214625ustar00rootroot00000000000000joshka-line-clipping-464d84b/.github/workflows/ci.yml000066400000000000000000000025351506620153500226050ustar00rootroot00000000000000name: Continuous Integration on: push: branches: [main] pull_request: branches: [main] jobs: ci: runs-on: ubuntu-latest steps: - uses: actions/checkout@v5 - uses: dtolnay/rust-toolchain@stable - run: cargo build - run: cargo test no_std: runs-on: ubuntu-latest steps: - uses: actions/checkout@v5 - uses: dtolnay/rust-toolchain@stable with: targets: x86_64-unknown-none - run: cargo build --target x86_64-unknown-none clippy: runs-on: ubuntu-latest steps: - uses: actions/checkout@v5 - uses: dtolnay/rust-toolchain@stable - run: cargo clippy --all-targets --all-features -- -D warnings fmt: runs-on: ubuntu-latest steps: - uses: actions/checkout@v5 - uses: dtolnay/rust-toolchain@nightly with: components: rustfmt - run: cargo fmt -- --check coverage: runs-on: ubuntu-latest steps: - uses: actions/checkout@v5 - uses: dtolnay/rust-toolchain@stable with: components: llvm-tools - uses: taiki-e/install-action@cargo-llvm-cov - run: cargo llvm-cov --lcov --output-path target/lcov.info - uses: codecov/codecov-action@v5 with: token: ${{ secrets.CODECOV_TOKEN }} slug: joshka/line-clipping fail_ci_if_error: false joshka-line-clipping-464d84b/.github/workflows/release-plz.yml000066400000000000000000000013241506620153500244300ustar00rootroot00000000000000# see https://release-plz.ieni.dev/docs/github for more information name: Release-plz permissions: pull-requests: write contents: write on: push: branches: - main workflow_dispatch: jobs: release-plz: name: Release-plz runs-on: ubuntu-latest if: ${{ github.repository == 'joshka/line-clipping' }} concurrency: group: release-plz-${{ github.ref }} cancel-in-progress: false steps: - uses: actions/checkout@v5 with: fetch-depth: 0 - uses: dtolnay/rust-toolchain@stable - uses: release-plz/action@v0.5 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} joshka-line-clipping-464d84b/.gitignore000066400000000000000000000000101506620153500200440ustar00rootroot00000000000000/target joshka-line-clipping-464d84b/CHANGELOG.md000066400000000000000000000047441506620153500177070ustar00rootroot00000000000000# Changelog All notable changes to this project will be documented in this file. ## [unreleased] ## [0.3.4](https://github.com/joshka/line-clipping/compare/v0.3.3...v0.3.4) - 2025-09-28 ### Other - *(deps)* bump bitflags in the rust-dependencies group ([#17](https://github.com/joshka/line-clipping/pull/17)) - *(deps)* bump actions/checkout in the github-actions group ([#16](https://github.com/joshka/line-clipping/pull/16)) - *(deps)* bump rstest in the rust-dependencies group ([#14](https://github.com/joshka/line-clipping/pull/14)) ## [0.3.3](https://github.com/joshka/line-clipping/compare/v0.3.2...v0.3.3) - 2025-05-19 ### Other - *(deps)* use bitflags 2.9 instead of 2.9.0 ([#12](https://github.com/joshka/line-clipping/pull/12)) ## [0.3.2](https://github.com/joshka/line-clipping/compare/v0.3.1...v0.3.2) - 2025-05-13 ### Other - add badges to readme ([#10](https://github.com/joshka/line-clipping/pull/10)) - update readme from lib.rs - fix lints and docs ([#9](https://github.com/joshka/line-clipping/pull/9)) - add CI for no_std ([#7](https://github.com/joshka/line-clipping/pull/7)) ## [0.3.1](https://github.com/joshka/line-clipping/compare/v0.3.0...v0.3.1) - 2025-05-13 ### Other - add better tests ([#5](https://github.com/joshka/line-clipping/pull/5)) ## [0.3.0](https://github.com/joshka/line-clipping/compare/v0.2.2...v0.3.0) - 2025-05-11 ### Other - tidy up tests and impl of cohen_sutherland ## [0.2.2](https://github.com/joshka/line-clipping/compare/v0.2.1...v0.2.2) - 2025-05-11 ### Added - *(no_std)* make the crate `no_std`-compatible ### Fixed - cleanup doc tests and formatting ### Other - add rustfmt config - add git-cliff generated changelog - *(deps)* bump bitflags in the rust-dependencies group ([#2](https://github.com/joshka/line-clipping/pull/2)) - add ci and release workflows ### ๐Ÿš€ Features - *(no_std)* Make the crate `no_std`-compatible ### ๐Ÿ› Bug Fixes - Cleanup doc tests and formatting ### ๐Ÿ’ผ Other - Merge pull request #1 from j-g00da/no_std feat(no_std): make the crate `no_std`-compatible ### โš™๏ธ Miscellaneous Tasks - Add ci and release workflows ## [0.2.1] - 2024-11-20 ### ๐Ÿ’ผ Other - Update readme ## [0.2.0] - 2024-11-20 ### ๐Ÿ’ผ Other - Rename Line to LineSegment, make fields public This makes it a little easier to use with Ratatui which already has two types named Line. - Bump version to 0.2.0 ## [0.1.0] - 2024-11-18 ### ๐Ÿ’ผ Other - Initial implementation of Cohen Sutherland algorithm joshka-line-clipping-464d84b/Cargo.lock000066400000000000000000000166001506620153500177750ustar00rootroot00000000000000# This file is automatically @generated by Cargo. # It is not intended for manual editing. version = 4 [[package]] name = "aho-corasick" version = "1.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" dependencies = [ "memchr", ] [[package]] name = "autocfg" version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" [[package]] name = "bitflags" version = "2.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6a65b545ab31d687cff52899d4890855fec459eb6afe0da6417b8a18da87aa29" [[package]] name = "cfg-if" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "equivalent" version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" [[package]] name = "futures-core" version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "05f29059c0c2090612e8d742178b0580d2dc940c837851ad723096f87af6663e" [[package]] name = "futures-macro" version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650" dependencies = [ "proc-macro2", "quote", "syn", ] [[package]] name = "futures-task" version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f90f7dce0722e95104fcb095585910c0977252f286e354b5e3bd38902cd99988" [[package]] name = "futures-timer" version = "3.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f288b0a4f20f9a56b5d1da57e2227c661b7b16168e2f72365f57b63326e29b24" [[package]] name = "futures-util" version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9fa08315bb612088cc391249efdc3bc77536f16c91f6cf495e6fbe85b20a4a81" dependencies = [ "futures-core", "futures-macro", "futures-task", "pin-project-lite", "pin-utils", "slab", ] [[package]] name = "glob" version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a8d1add55171497b4705a648c6b583acafb01d58050a51727785f0b2c8e0a2b2" [[package]] name = "hashbrown" version = "0.15.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "84b26c544d002229e640969970a2e74021aadf6e2f96372b9c58eff97de08eb3" [[package]] name = "indexmap" version = "2.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cea70ddb795996207ad57735b50c5982d8844f38ba9ee5f1aedcfb708a2aa11e" dependencies = [ "equivalent", "hashbrown", ] [[package]] name = "line-clipping" version = "0.3.4" dependencies = [ "bitflags", "rstest", ] [[package]] name = "memchr" version = "2.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" [[package]] name = "pin-project-lite" version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3b3cff922bd51709b605d9ead9aa71031d81447142d828eb4a6eba76fe619f9b" [[package]] name = "pin-utils" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] name = "proc-macro-crate" version = "3.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "edce586971a4dfaa28950c6f18ed55e0406c1ab88bbce2c6f6293a7aaba73d35" dependencies = [ "toml_edit", ] [[package]] name = "proc-macro2" version = "1.0.95" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "02b3e5e68a3a1a02aad3ec490a98007cbc13c37cbe84a3cd7b8e406d76e7f778" dependencies = [ "unicode-ident", ] [[package]] name = "quote" version = "1.0.40" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d" dependencies = [ "proc-macro2", ] [[package]] name = "regex" version = "1.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191" dependencies = [ "aho-corasick", "memchr", "regex-automata", "regex-syntax", ] [[package]] name = "regex-automata" version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908" dependencies = [ "aho-corasick", "memchr", "regex-syntax", ] [[package]] name = "regex-syntax" version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" [[package]] name = "relative-path" version = "1.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ba39f3699c378cd8970968dcbff9c43159ea4cfbd88d43c00b22f2ef10a435d2" [[package]] name = "rstest" version = "0.26.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f5a3193c063baaa2a95a33f03035c8a72b83d97a54916055ba22d35ed3839d49" dependencies = [ "futures-timer", "futures-util", "rstest_macros", ] [[package]] name = "rstest_macros" version = "0.26.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c845311f0ff7951c5506121a9ad75aec44d083c31583b2ea5a30bcb0b0abba0" dependencies = [ "cfg-if", "glob", "proc-macro-crate", "proc-macro2", "quote", "regex", "relative-path", "rustc_version", "syn", "unicode-ident", ] [[package]] name = "rustc_version" version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cfcb3a22ef46e85b45de6ee7e79d063319ebb6594faafcf1c225ea92ab6e9b92" dependencies = [ "semver", ] [[package]] name = "semver" version = "1.0.26" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "56e6fa9c48d24d85fb3de5ad847117517440f6beceb7798af16b4a87d616b8d0" [[package]] name = "slab" version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" dependencies = [ "autocfg", ] [[package]] name = "syn" version = "2.0.101" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ce2b7fc941b3a24138a0a7cf8e858bfc6a992e7978a068a5c760deb0ed43caf" dependencies = [ "proc-macro2", "quote", "unicode-ident", ] [[package]] name = "toml_datetime" version = "0.6.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3da5db5a963e24bc68be8b17b6fa82814bb22ee8660f192bb182771d498f09a3" [[package]] name = "toml_edit" version = "0.22.26" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "310068873db2c5b3e7659d2cc35d21855dbafa50d1ce336397c666e3cb08137e" dependencies = [ "indexmap", "toml_datetime", "winnow", ] [[package]] name = "unicode-ident" version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512" [[package]] name = "winnow" version = "0.7.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c06928c8748d81b05c9be96aad92e1b6ff01833332f281e8cfca3be4b35fc9ec" dependencies = [ "memchr", ] joshka-line-clipping-464d84b/Cargo.toml000066400000000000000000000011421506620153500200130ustar00rootroot00000000000000[package] name = "line-clipping" description = "A simple crate implementing line clipping algorithms." authors = ["Josh McKinney"] license = "MIT OR Apache-2.0" version = "0.3.4" edition = "2021" documentation = "https://docs.rs/line-clipping" repository = "https://github.com/joshka/line-clipping" readme = "README.md" keywords = ["line", "clipping", "algorithm"] categories = ["algorithms", "graphics"] [dependencies] bitflags = "2.9" [dev-dependencies] rstest = "0.26.1" [lints.clippy] nursery = { level = "warn" } pedantic = { level = "warn" } [lints.rust] unsafe_code = "forbid" missing_docs = "warn" joshka-line-clipping-464d84b/LICENSE-APACHE000066400000000000000000000261171506620153500200200ustar00rootroot00000000000000 Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright 2024 Josh McKinney Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. joshka-line-clipping-464d84b/LICENSE-MIT000066400000000000000000000020561506620153500175240ustar00rootroot00000000000000MIT License Copyright (c) 2024 Josh McKinney Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. joshka-line-clipping-464d84b/README.md000066400000000000000000000051631506620153500173510ustar00rootroot00000000000000# Line clipping [![crate-badge]][crate] [![docs-badge]][docs] [![license-badge]][license] \ [![github-badge]][github] [![build-badge]][build] [![codecov-badge]][codecov] [crate-badge]: https://img.shields.io/crates/v/line-clipping?logo=rust [docs-badge]: https://img.shields.io/badge/docs.rs-line_clipping-blue?logo=rust [license-badge]: https://img.shields.io/crates/l/line-clipping?logo=apache [github-badge]: https://img.shields.io/badge/github-joshka%2Fline_clipping-blue?logo=github [build-badge]: https://github.com/joshka/line-clipping/actions/workflows/ci.yml/badge.svg?logo=github [codecov-badge]: https://img.shields.io/codecov/c/github/joshka/line-clipping?logo=codecov [github]: https://github.com/joshka/line-clipping [crate]: https://crates.io/crates/line-clipping [license]: #license [docs]: https://docs.rs/line-clipping [build]: https://github.com/joshka/line-clipping/actions/workflows/ci.yml [codecov]: https://codecov.io/gh/joshka/line-clipping A rust crate to implement several line clipping algorithms. See the [documentation](https://docs.rs/line_clipping) 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](https://pmc.ncbi.nlm.nih.gov/articles/PMC9605407/). J Imaging. 2022 Oct 17;8(10):286. doi: 10.3390/jimaging8100286. PMID: 36286380; PMCID: PMC9605407. Supports: - [x] [Cohen-Sutherland](https://docs.rs/line-clipping/latest/line_clipping/cohen_sutherland/) TODO - [ ] Cyrus-Beck - [ ] Liang-Barsky - [ ] Nicholl-Lee-Nicholl - [ ] More comprehensive testing ## Installation ```shell cargo add line-clipping ``` ## Usage ```rust 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 - MIT license ([LICENSE-MIT](LICENSE-MIT) or ) - Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or ) 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. joshka-line-clipping-464d84b/cliff.toml000066400000000000000000000062521506620153500200520ustar00rootroot00000000000000# git-cliff ~ default configuration file # https://git-cliff.org/docs/configuration # # Lines starting with "#" are comments. # Configuration options are organized into tables and keys. # See documentation for more information on available options. [changelog] # template for the changelog header header = """ # Changelog\n All notable changes to this project will be documented in this file.\n """ # template for the changelog body # https://keats.github.io/tera/docs/#introduction body = """ {% if version %}\ ## [{{ version | trim_start_matches(pat="v") }}] - {{ timestamp | date(format="%Y-%m-%d") }} {% else %}\ ## [unreleased] {% endif %}\ {% for group, commits in commits | group_by(attribute="group") %} ### {{ group | striptags | trim | upper_first }} {% for commit in commits %} - {% if commit.scope %}*({{ commit.scope }})* {% endif %}\ {% if commit.breaking %}[**breaking**] {% endif %}\ {{ commit.message | upper_first }}\ {% endfor %} {% endfor %}\n """ # template for the changelog footer footer = """ """ # remove the leading and trailing s trim = true # postprocessors postprocessors = [ # { pattern = '', replace = "https://github.com/orhun/git-cliff" }, # replace repository URL ] # render body even when there are no releases to process # render_always = true # output file path # output = "test.md" [git] # parse the commits based on https://www.conventionalcommits.org conventional_commits = true # filter out the commits that are not conventional filter_unconventional = false # process each line of a commit as an individual commit split_commits = false # regex for preprocessing the commit messages commit_preprocessors = [ # Replace issue numbers #{ pattern = '\((\w+\s)?#([0-9]+)\)', replace = "([#${2}](/issues/${2}))"}, # Check spelling of the commit with https://github.com/crate-ci/typos # If the spelling is incorrect, it will be automatically fixed. #{ pattern = '.*', replace_command = 'typos --write-changes -' }, ] # regex for parsing and grouping commits commit_parsers = [ { message = "^feat", group = "๐Ÿš€ Features" }, { message = "^fix", group = "๐Ÿ› Bug Fixes" }, { message = "^doc", group = "๐Ÿ“š Documentation" }, { message = "^perf", group = "โšก Performance" }, { message = "^refactor", group = "๐Ÿšœ Refactor" }, { message = "^style", group = "๐ŸŽจ Styling" }, { message = "^test", group = "๐Ÿงช Testing" }, { message = "^chore\\(release\\): prepare for", skip = true }, { message = "^chore\\(deps.*\\)", skip = true }, { message = "^chore\\(pr\\)", skip = true }, { message = "^chore\\(pull\\)", skip = true }, { message = "^chore|^ci", group = "โš™๏ธ Miscellaneous Tasks" }, { body = ".*security", group = "๐Ÿ›ก๏ธ Security" }, { message = "^revert", group = "โ—€๏ธ Revert" }, { message = ".*", group = "๐Ÿ’ผ Other" }, ] # filter out the commits that are not matched by commit parsers filter_commits = false # sort the tags topologically topo_order = false # sort the commits inside sections by oldest/newest order sort_commits = "oldest" joshka-line-clipping-464d84b/clippy.toml000066400000000000000000000000461506620153500202620ustar00rootroot00000000000000doc-valid-idents = ["McKinney", ".."] joshka-line-clipping-464d84b/rustfmt.toml000066400000000000000000000004711506620153500204700ustar00rootroot00000000000000# configuration for https://rust-lang.github.io/rustfmt/ use_field_init_shorthand = true # unstable options comment_width = 100 format_code_in_doc_comments = true format_macro_matchers = true group_imports = "StdExternalCrate" imports_granularity = "Module" normalize_doc_attributes = true wrap_comments = true joshka-line-clipping-464d84b/src/000077500000000000000000000000001506620153500166545ustar00rootroot00000000000000joshka-line-clipping-464d84b/src/cohen_sutherland.rs000066400000000000000000000322671506620153500225610ustar00rootroot00000000000000//! Implements the Cohen-Sutherland line clipping algorithm. //! //! Returns the clipped line if the original line intersects the clipping window, or `None` if the //! original line is completely outside the clipping window. //! //! Reference: [Cohen-Sutherland algorithm](https://en.wikipedia.org/wiki/Cohen%E2%80%93Sutherland_algorithm) //! //! The Cohen-Sutherland algorithm is a line clipping algorithm that divides the 2D plane into 9 //! regions and then determines the region in which the line lies. If the line lies completely //! outside the clipping window, it is rejected. If the line lies completely inside the clipping //! window, it is accepted. If the line lies partially inside the clipping window, it is clipped. //! //! The regions are defined as follows: //! //! ```plain //! 1001 | 1000 | 1010 //! -----|------|----- //! 0001 | 0000 | 0010 //! -----|------|----- //! 0101 | 0100 | 0110 //! ``` //! //! The algorithm works as follows: //! //! 1. Determine the region in which the line's starting point lies. //! 2. Determine the region in which the line's ending point lies. //! 3. If both points lie in region 0000, the line is completely inside the clipping window and //! should be accepted. //! 4. If both points lie in the same region that is not 0000, the line is completely outside the //! clipping window and should be rejected. //! 5. If the points lie in different regions, the line is partially inside the clipping window and //! should be clipped. //! 6. Clip the line using the Cohen-Sutherland algorithm. //! 7. Repeat the process for the clipped line. //! //! The Cohen-Sutherland algorithm is commonly used in computer graphics to clip lines against a //! rectangular window. //! //! # Examples //! //! ``` //! 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); //! ``` use bitflags::bitflags; use crate::{LineSegment, Point, Window}; /// Clips a line segment against a rectangular window using the Cohen-Sutherland algorithm. /// /// See the [module-level documentation](crate::cohen_sutherland) for more details on the algorithm. /// /// # Examples /// /// ``` /// 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); /// ``` #[must_use] pub fn clip_line(mut line: LineSegment, window: Window) -> Option { let mut region_1 = Region::from_point(line.p1, window); let mut region_2 = Region::from_point(line.p2, window); while region_1.is_outside() || region_2.is_outside() { if region_1.intersects(region_2) { // The line is completely outside the clipping window. return None; } if region_1.is_outside() { line.p1 = calculate_intersection(line.p1, line.p2, region_1, window); region_1 = Region::from_point(line.p1, window); } else { line.p2 = calculate_intersection(line.p2, line.p1, region_2, window); region_2 = Region::from_point(line.p2, window); } } Some(line) } fn calculate_intersection(p1: Point, p2: Point, region: Region, window: Window) -> Point { let dx = p2.x - p1.x; let dy = p2.y - p1.y; if region.contains(Region::LEFT) { let y = p1.y + (window.x_min - p1.x) * dy / dx; Point::new(window.x_min, y) } else if region.contains(Region::RIGHT) { let y = p1.y + (window.x_max - p1.x) * dy / dx; Point::new(window.x_max, y) } else if region.contains(Region::BOTTOM) { let x = p1.x + (window.y_min - p1.y) * dx / dy; Point::new(x, window.y_min) } else if region.contains(Region::TOP) { let x = p1.x + (window.y_max - p1.y) * dx / dy; Point::new(x, window.y_max) } else { p1 } } bitflags! { /// Represents the regions in the Cohen-Sutherland algorithm. #[derive(Debug, Clone, Copy, PartialEq, Eq)] struct Region: u8 { const LEFT = 0b0001; const RIGHT = 0b0010; const BOTTOM = 0b0100; const TOP = 0b1000; } } impl Region { const fn is_outside(self) -> bool { !self.is_empty() } /// Determines the region in which a point lies. fn from_point(point: Point, window: Window) -> Self { let mut region = Self::empty(); if point.x < window.x_min { region |= Self::LEFT; } else if point.x > window.x_max { region |= Self::RIGHT; } if point.y < window.y_min { region |= Self::BOTTOM; } else if point.y > window.y_max { region |= Self::TOP; } region } } #[cfg(test)] mod tests { use rstest::rstest; use super::*; #[rstest] #[case::left(Point::new(-2.0, 0.0), Region::LEFT)] #[case::right(Point::new(2.0, 0.0), Region::RIGHT)] #[case::top(Point::new(0.0, 2.0), Region::TOP)] #[case::bottom(Point::new(0.0, -2.0), Region::BOTTOM)] #[case::top_left(Point::new(-2.0, 2.0), Region::LEFT | Region::TOP)] #[case::top_right(Point::new(2.0, 2.0), Region::RIGHT | Region::TOP)] #[case::bottom_left(Point::new(-2.0, -2.0), Region::LEFT | Region::BOTTOM)] #[case::bottom_right(Point::new(2.0, -2.0), Region::RIGHT | Region::BOTTOM)] #[case::inside(Point::new(0.0, 0.0), Region::empty())] #[case::inside_left(Point::new(-1.0, 0.0), Region::empty())] #[case::inside_right(Point::new(1.0, 0.0), Region::empty())] #[case::inside_top(Point::new(0.0, 1.0), Region::empty())] #[case::inside_bottom(Point::new(0.0, -1.0), Region::empty())] #[case::inside_top_left(Point::new(-1.0, 1.0), Region::empty())] #[case::inside_top_right(Point::new(1.0, 1.0), Region::empty())] #[case::inside_bottom_left(Point::new(-1.0, -1.0), Region::empty())] #[case::inside_bottom_right(Point::new(1.0, -1.0), Region::empty())] fn region_from_point(#[case] point: Point, #[case] expected: Region) { let window = Window::new(-1.0, 1.0, -1.0, 1.0); assert_eq!(Region::from_point(point, window), expected); } #[rstest] #[case::top_left(Point::new(-2.0, 2.0), Point::new(-3.0, 3.0))] #[case::top_right(Point::new(2.0, 2.0), Point::new(3.0, 3.0))] #[case::bottom_left(Point::new(-2.0, -2.0), Point::new(-3.0, -3.0))] #[case::bottom_right(Point::new(2.0, -2.0), Point::new(3.0, -3.0))] #[case::left(Point::new(-2.0, 0.0), Point::new(-3.0, 0.0))] #[case::right(Point::new(2.0, 0.0), Point::new(3.0, 0.0))] #[case::top(Point::new(0.0, 2.0), Point::new(0.0, 2.0))] #[case::bottom(Point::new(0.0, -2.0), Point::new(0.0, -3.0))] fn outside(#[case] p1: Point, #[case] p2: Point) { let line = LineSegment::new(p1, p2); let window = Window::new(-1.0, 1.0, -1.0, 1.0); assert_eq!(clip_line(line, window), None); } #[rstest] #[case::left_border(Point::new(-1.0, -1.0), Point::new(-1.0, 1.0))] #[case::right_border(Point::new(1.0, -1.0), Point::new(1.0, 1.0))] #[case::top_border(Point::new(-1.0, 1.0), Point::new(1.0, 1.0))] #[case::bottom_border(Point::new(-1.0, -1.0), Point::new(1.0, -1.0))] #[case::corners_up(Point::new(-1.0, -1.0), Point::new(1.0, 1.0))] #[case::corners_down(Point::new(-1.0, 1.0), Point::new(1.0, -1.0))] #[case::horizontal(Point::new(-0.5, 0.0), Point::new(0.5, 0.0))] #[case::vertical(Point::new(0.0, -0.5), Point::new(0.0, 0.5))] #[case::diagonal_up(Point::new(-0.5, -0.5), Point::new(0.5, 0.5))] #[case::diagonal_down(Point::new(-0.5, 0.5), Point::new(0.5, -0.5))] fn inside(#[case] p1: Point, #[case] p2: Point) { let line = LineSegment::new(p1, p2); let window = Window::new(-1.0, 1.0, -1.0, 1.0); assert_eq!(clip_line(line, window), Some(line)); } /// Test cases for lines that point to the origin and intersect the window. The cases move /// clockwise around the window. This makes sure that we test the intersection of the line with /// the window from all regions. /// /// ``` /// 1 2 3 4 5 6 7 8 1 /// 8 2 /// 7 โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” 3 /// 6 โ”‚ โ”‚ 4 /// 5 โ”‚ . โ”‚ 5 /// 4 โ”‚ โ”‚ 6 /// 3 โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ 7 /// 2 8 /// 1 8 7 6 5 4 3 2 1 /// ``` #[rstest] #[case::top_1(Point::new(-2.0, 2.0), Point::new(-1.0, 1.0))] #[case::top_2(Point::new(-1.5, 2.0), Point::new(-0.75, 1.0))] #[case::top_3(Point::new(-1.0, 2.0), Point::new(-0.5, 1.0))] #[case::top_4(Point::new(-0.5, 2.0), Point::new(-0.25, 1.0))] #[case::top_5(Point::new(0.0, 2.0), Point::new(0.0, 1.0))] #[case::top_6(Point::new(0.5, 2.0), Point::new(0.25, 1.0))] #[case::top_7(Point::new(1.0, 2.0), Point::new(0.5, 1.0))] #[case::top_8(Point::new(1.5, 2.0), Point::new(0.75, 1.0))] #[case::right_1(Point::new(2.0, 2.0), Point::new(1.0, 1.0))] #[case::right_2(Point::new(2.0, 1.5), Point::new(1.0, 0.75))] #[case::right_3(Point::new(2.0, 1.0), Point::new(1.0, 0.5))] #[case::right_4(Point::new(2.0, 0.5), Point::new(1.0, 0.25))] #[case::right_5(Point::new(2.0, 0.0), Point::new(1.0, 0.0))] #[case::right_6(Point::new(2.0, -0.5), Point::new(1.0, -0.25))] #[case::right_7(Point::new(2.0, -1.0), Point::new(1.0, -0.5))] #[case::right_8(Point::new(2.0, -1.5), Point::new(1.0, -0.75))] #[case::bottom_1(Point::new(2.0, -2.0), Point::new(1.0, -1.0))] #[case::bottom_2(Point::new(1.5, -2.0), Point::new(0.75, -1.0))] #[case::bottom_3(Point::new(1.0, -2.0), Point::new(0.5, -1.0))] #[case::bottom_4(Point::new(0.5, -2.0), Point::new(0.25, -1.0))] #[case::bottom_5(Point::new(0.0, -2.0), Point::new(0.0, -1.0))] #[case::bottom_6(Point::new(-0.5, -2.0), Point::new(-0.25, -1.0))] #[case::bottom_7(Point::new(-1.0, -2.0), Point::new(-0.5, -1.0))] #[case::bottom_8(Point::new(-1.5, -2.0), Point::new(-0.75, -1.0))] #[case::left_1(Point::new(-2.0, -2.0), Point::new(-1.0, -1.0))] #[case::left_2(Point::new(-2.0, -1.5), Point::new(-1.0, -0.75))] #[case::left_3(Point::new(-2.0, -1.0), Point::new(-1.0, -0.5))] #[case::left_4(Point::new(-2.0, -0.5), Point::new(-1.0, -0.25))] #[case::left_5(Point::new(-2.0, 0.0), Point::new(-1.0, 0.0))] #[case::left_6(Point::new(-2.0, 0.5), Point::new(-1.0, 0.25))] #[case::left_7(Point::new(-2.0, 1.0), Point::new(-1.0, 0.5))] #[case::left_8(Point::new(-2.0, 1.5), Point::new(-1.0, 0.75))] fn one_intersection(#[case] p1: Point, #[case] expected: Point) { let line = LineSegment::new(p1, Point::ORIGIN); let window = Window::new(-1.0, 1.0, -1.0, 1.0); let expected = LineSegment::new(expected, Point::ORIGIN); assert_eq!(clip_line(line, window), Some(expected)); } const A: Point = Point::new(-2.0, 2.0); const B: Point = Point::new(0.0, 2.0); const C: Point = Point::new(2.0, 2.0); const D: Point = Point::new(2.0, 0.0); const E: Point = Point::new(2.0, -2.0); const F: Point = Point::new(0.0, -2.0); const G: Point = Point::new(-2.0, -2.0); const H: Point = Point::new(-2.0, 0.0); /// Test cases for lines that intersect the window twice. The cases move clockwise around the /// window. This makes sure that we test every region to each other region. /// ``` /// A B C /// /// โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” /// โ”‚ โ”‚ /// H โ”‚ . โ”‚ D /// โ”‚ โ”‚ /// โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ /// /// G F E /// ``` #[rstest] #[case::a_to_d(A, D, Point::new(0.0, 1.0), Point::new(1.0, 0.5))] #[case::a_to_e(A, E, Point::new(-1.0, 1.0), Point::new(1.0, -1.0))] #[case::a_to_k(A, F, Point::new(-1.0, 0.0), Point::new(-0.5, -1.0))] #[case::b_to_d(B, D, Point::new(1.0, 1.0), Point::new(1.0, 1.0))] #[case::b_to_e(B, E, Point::new(0.5, 1.0), Point::new(1.0, 0.0))] #[case::b_to_f(B, F, Point::new(0.0, 1.0), Point::new(0.0, -1.0))] #[case::b_to_g(B, G, Point::new(-0.5, 1.0), Point::new(-1.0, -0.0))] #[case::b_to_h(B, H, Point::new(-1.0, 1.0), Point::new(-1.0, 1.0))] #[case::c_to_f(C, F, Point::new(1.0, 0.0), Point::new(0.5, -1.0))] #[case::c_to_g(C, G, Point::new(1.0, 1.0), Point::new(-1.0, -1.0))] #[case::c_to_h(C, H, Point::new(0.0, 1.0), Point::new(-1.0, 0.5))] #[case::d_to_f(D, F, Point::new(1.0, -1.0), Point::new(1.0, -1.0))] #[case::d_to_g(D, G, Point::new(1.0, -0.5), Point::new(0.0, -1.0))] #[case::d_to_h(D, H, Point::new(1.0, 0.0), Point::new(-1.0, 0.0))] #[case::e_to_h(E, H, Point::new(0.0, -1.0), Point::new(-1.0, -0.5))] #[case::f_to_h(F, H, Point::new(-1.0, -1.0), Point::new(-1.0, -1.0))] fn two_intersections( #[case] p1: Point, #[case] p2: Point, #[case] expected_p1: Point, #[case] expected_p2: Point, ) { let line = LineSegment::new(p1, p2); let window = Window::new(-1.0, 1.0, -1.0, 1.0); let expected = LineSegment::new(expected_p1, expected_p2); assert_eq!(clip_line(line, window).unwrap(), expected); } } joshka-line-clipping-464d84b/src/lib.rs000066400000000000000000000063251506620153500177760ustar00rootroot00000000000000#![no_std] //! A rust crate to implement several line clipping algorithms. See the //! [documentation](https://docs.rs/line_clipping) 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](https://pmc.ncbi.nlm.nih.gov/articles/PMC9605407/). J Imaging. 2022 Oct //! 17;8(10):286. doi: 10.3390/jimaging8100286. PMID: 36286380; PMCID: PMC9605407. //! //! Supports: //! //! - [x] [Cohen-Sutherland](crate::cohen_sutherland) //! //! TODO //! //! - [ ] Cyrus-Beck //! - [ ] Liang-Barsky //! - [ ] Nicholl-Lee-Nicholl //! - [ ] More comprehensive testing //! //! # Installation //! //! ```shell //! cargo add line-clipping //! ``` //! //! # Usage //! //! ```rust //! 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 //! //! - MIT license ([LICENSE-MIT](LICENSE-MIT) or ) //! - Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or ) //! //! 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. pub mod cohen_sutherland; /// A point in 2D space. #[derive(Debug, Clone, Copy, PartialEq)] pub struct Point { /// The x coordinate of the point. pub x: f64, /// The y coordinate of the point. pub y: f64, } impl Point { /// A point at the origin (0.0, 0.0). pub const ORIGIN: Self = Self { x: 0.0, y: 0.0 }; /// Creates a new point. #[must_use] pub const fn new(x: f64, y: f64) -> Self { Self { x, y } } } /// A line segment in 2D space. #[derive(Debug, Clone, Copy, PartialEq)] pub struct LineSegment { /// The first point of the line segment. pub p1: Point, /// The second point of the line segment. pub p2: Point, } impl LineSegment { /// Creates a new line segment. #[must_use] pub const fn new(p1: Point, p2: Point) -> Self { Self { p1, p2 } } } /// A rectangular region to clip lines against. #[derive(Debug, Clone, Copy)] pub struct Window { /// The minimum x coordinate of the window. pub x_min: f64, /// The maximum x coordinate of the window. pub x_max: f64, /// The minimum y coordinate of the window. pub y_min: f64, /// The maximum y coordinate of the window. pub y_max: f64, } impl Window { /// Creates a new window. #[must_use] pub const fn new(x_min: f64, x_max: f64, y_min: f64, y_max: f64) -> Self { Self { x_min, x_max, y_min, y_max, } } }