Skip to content

Commit

Permalink
feat!: rework clipline (#16)
Browse files Browse the repository at this point in the history
* feat!: add `SignedAxis`, `Axis` and `Octant` iterators
* feat!: add `Diagonal` iterators
* feat!: add `Clip` and the new clipping algorithm
* feat: special-case diagonals
* feat: support all signed and unsigned integer coordinates
* fix: remove overflow and division by zero
* feat: gate `Octant<int64>` behind `octant_64`, add compile-time tests
* test: check clipping matches naive clipping via `proptest`
* ci: set up new CI workflow
* docs: update CI badge
* chore: ignore `.DS_Store`
---------
Signed-off-by: Nurzhan Sakén <[email protected]>
  • Loading branch information
nxsaken authored Aug 11, 2024
1 parent 2edb5a8 commit d42cde7
Show file tree
Hide file tree
Showing 27 changed files with 4,033 additions and 2,120 deletions.
115 changes: 115 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
name: CI
on:
workflow_dispatch:
merge_group:
pull_request:
paths-ignore:
- "img/**"
- "**.md"
- LICENSE-APACHE
- LICENSE-MIT
- .gitignore
push:
branches: [ main ]
paths-ignore:
- "img/**"
- "**.md"
- LICENSE-APACHE
- LICENSE-MIT
- .gitignore

env:
CARGO_TERM_COLOR: always

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
build:
name: cargo build
runs-on: ubuntu-latest
strategy:
matrix:
rust: [ stable, beta, nightly ]
steps:
- name: Checkout sources
uses: actions/checkout@v4
- name: Install toolchain
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.rust }}
- name: Default features
run: cargo build --all-targets
- name: Nightly features
if: matrix.rust == 'nightly'
run: cargo build --all-targets -F "nightly try_fold is_empty"

clippy:
name: cargo clippy
runs-on: ubuntu-latest
strategy:
matrix:
rust: [ stable, beta, nightly ]
env:
RUSTFLAGS: -Dwarnings
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.rust }}
components: clippy
- run: cargo clippy --all-targets
- if: matrix.rust == 'nightly'
run: cargo clippy --all-targets --all-features

fmt:
name: cargo fmt
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt
- run: cargo fmt --all -- --check

doc:
name: cargo rustdoc
runs-on: ubuntu-latest
env:
RUSTDOCFLAGS: -Dwarnings
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@nightly
- uses: dtolnay/install@cargo-docs-rs
- run: cargo docs-rs

test:
name: cargo test
runs-on: ubuntu-latest
strategy:
matrix:
rust: [ stable, beta, nightly ]
steps:
- name: Checkout sources
uses: actions/checkout@v4
- name: Install toolchain
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.rust }}
- name: Default features
run: cargo test --no-fail-fast -- --skip proptest
- name: Nightly features
if: matrix.rust == 'nightly'
run: cargo test --no-fail-fast -F "nightly try_fold is_empty" -- --skip proptest

proptest:
name: proptest
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v4
- name: Install toolchain
uses: dtolnay/rust-toolchain@stable
- name: Default features
run: cargo test --no-fail-fast proptest
22 changes: 0 additions & 22 deletions .github/workflows/rust.yml

This file was deleted.

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.DS_Store
.idea
/target
/Cargo.lock
151 changes: 0 additions & 151 deletions BENCHMARKS.md

This file was deleted.

38 changes: 22 additions & 16 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,29 +1,35 @@
[package]
name = "clipline"
version = "0.2.0"
version = "0.3.0"
authors = ["Nurzhan Sakén <[email protected]>"]
edition = "2021"
description = "Efficient scan conversion (rasterization) of line segments with clipping to a rectangular window."
readme = "README.md"
description = "Efficient rasterization of line segments with pixel-perfect clipping."
keywords = ["line", "clipping", "bresenham", "rasterization", "grid"]
categories = ["graphics", "rendering", "algorithms", "game-development"]
repository = "https://github.com/nxsaken/clipline/"
license = "MIT OR Apache-2.0"
keywords = ["graphics", "clipping", "line", "bresenham", "rasterization"]
categories = ["graphics", "rendering", "algorithms", "game-development", "rendering"]
readme = "README.md"
rust-version = "1.66.0"
edition = "2021"
include = [
"**/*.rs",
"Cargo.toml",
]

[features]
default = ["func", "iter"]
iter = []
func = []
default = []
# Enable Octant<i64/u64> for all targets
# and Octant<isize/usize> for 64-bit targets.
octant_64 = []

[dev-dependencies]
criterion = { version = "0.5.1"}
bresenham = "0.1.1"
line_drawing = "1.0.0"
# Enable unstable features.
nightly = []
# Enable optimized `try_fold` implementations.
# Requires the unstable `try_trait_v2` feature.
try_fold = ["nightly"]
# Enable optimized `is_empty` implementations.
# Requires the unstable `exact_size_is_empty` feature.
is_empty = ["nightly"]

[[bench]]
name = "bresenham_comparison"
harness = false
[dev-dependencies]
static_assertions = "1.1.0"
proptest = "1.5.0"
Loading

0 comments on commit d42cde7

Please sign in to comment.