Efficient scan conversion of a line segment with clipping to a rectangular window.

Overview

✂️ clipline 📏

Rust crates.io docs.rs

clipline is a Rust crate for efficient scan conversion of a line segment with clipping to a rectangular window. It is an implementation of the 1995 paper by YP Kuzmin.

The key advantage of this algorithm over vanilla Bresenham is that it eliminates the need for bounds checking on every pixel, which speeds up line drawing. Furthermore, the clipping is done via integer arithmetic, producing accurate clipped endpoints. This sets it apart from floating-point clipping algorithms like Cohen-Sutherland, which may distort the line due to rounding errors.

clipline in action

Installation

To use clipline, add it to your Cargo.toml file:

[dependencies]
clipline = "0.1.0"

Usage

use clipline::clipline;

fn draw_pixel(x: isize, y: isize) {
    // Your custom pixel drawing logic
    // No bounds checks necessary here
}

let line = ((0, 0), (10, 10));
let clip_rect = ((2, 2), (8, 8));

let (start, end) = clipline(line, clip_rect, draw_pixel)
    .expect("line intersects the clipping rectangle");

// Perform any additional logic with the clipped line segment.
// `start` and `end` represent the visible portion of the line.

In this example, clipline takes a line defined by two endpoints, line, and corners of a clipping rectangle, clip_rect. The closure draw_pixel handles each pixel within the clipped region, and the visible portion of the line is represented by the start and end variables.

You might also like...
Fixed point to floating point (and back) conversion utility

fixed2float Simple utility for fixed point to real number conversions, using the VisSim (Fxm.b) and Q (Qm.n) notations. Usage as a dependency of your

Core Fiberplane data models and methods for transforming them (templates, providers, markdown conversion)

fiberplane This repository is a monorepo for Rust code that is used throughout Fiberplane's product. Overview base64uuid - A utility for working with

SVG to PDF file conversion based on "svg2pdf" and "resvg" Rust projects

pysvg2pdf Blazingly Fast ™️ SVG to PDF file conversion for Python. This project is based on Rust's svg2pdf and resvg projects. The project uses pyo3 a

Command line tool for cheap and efficient email automation written in Rust

Pigeon Pigeon is a command line tool for automating your email workflow in a cheap and efficient way. Utilize your most efficient dev tools you are al

A robust, customizable, blazingly-fast, efficient and easy-to-use command line application to uwu'ify your text!
A robust, customizable, blazingly-fast, efficient and easy-to-use command line application to uwu'ify your text!

uwuifyy A robust, customizable, blazingly-fast, efficient and easy-to-use command line application to uwu'ify your text! Logo Credits: Jade Nelson Tab

A library that creates a terminal-like window with feature-packed drawing of text and easy input handling. MIRROR.

BearLibTerminal provides a pseudoterminal window with a grid of character cells and a simple yet powerful API for flexible textual output and uncompli

My Window Manager
My Window Manager

mwm My window manager that is a work in progress. Currently hacky Installation Clone this repo then: cargo build --release Put the binary in your pat

A small Rust library that let's you get position and size of the active window on Windows and MacOS

active-win-pos-rs A small Rust library that let's you get position and size of the active window on Windows and MacOS Build % git clone https://github

Comments
  • Allow excluding the ending point of the line

    Allow excluding the ending point of the line

    The algorithm used in clipline includes both endpoints of the line in the scan conversion. Some use cases may require excluding the second endpoint. Simply subtracting 1 from the coordinates of the endpoint is incorrect, so a more rigorous modification of the algorithm is needed.

    opened by nxsaken 0
Owner
Nurzhan Sakén
Nurzhan Sakén
Rust TUI library - Clipping region is a set of min/max x/y values applied to the existing region

TinyBit Clipping region is a set of min/max x/y values applied to the existing region A TUI lib This is not yet production ready T O D O TODO: bugs: T

Togglebit 13 May 3, 2022
Scan your Rust crate for semver violations.

cargo-semver-checks Scan your Rust crate for semver violations. Queries rustdoc-generated crate documentation using the trustfall "query everything" e

Predrag Gruevski 293 Jan 6, 2023
scan markdown files and execute `console` blocks

exec-commands − scan markdown files and execute console blocks exec-commands is a utility to update command-line-tool examples embedded in markdown fi

Hajime Suzuki 3 Nov 27, 2022
Fast tool to scan for valid 7-long imgur ids for the ArchiveTeam imgur efforts (not affiliated or endorsed)

imgur_id7 Fast tool to scan for valid 7-long imgur ids for the ArchiveTeam imgur efforts (not affiliated or endorsed) Optionally uses supplied http pr

Robin Rolf 6 Jun 3, 2023
Socket Monitor: A prettier and simpler alternative to netstat or ss for socket monitoring with the ability to scan for malicious IP addresses.

?? Somo A prettier alternative to netstat or ss for socket monitoring. ⬇️ Installation: 1. Install cargo: From crates.io. 2. Install the somo crate: c

Theodor Peifer 13 Jun 6, 2023
Scan the symbols of all ELF binaries in all Arch Linux packages for usage of malloc_usable_size

Scan the symbols of all ELF binaries in all Arch Linux packages for usage of malloc_usable_size (-D_FORTIFY_SOURCE=3 compatibility)

null 3 Sep 9, 2023
Fast conversion between linear float and 8-bit sRGB

fast-srgb8 Small crate implementing fast conversion between linear float and 8-bit sRGB. Includes API for performing 4 simultaneous conversions, which

Thom Chiovoloni 13 Sep 3, 2022
Tiny color conversion library for TUI application builders

Definition of ANSI, RGB and HSL color types and all the conversions between them. There are many other color conversion crates. This one may be useful

Canop 8 Dec 15, 2022
Rust implementation of custom numeric base conversion.

base_custom Use any characters as your own numeric base and convert to and from decimal. This can be taken advantage of in various ways: Mathematics:

Daniel P. Clark 5 Dec 28, 2021
An abstract, safe, and concise color conversion library for rust nightly This requires the feature adt_const_params

colortypes A type safe color conversion library This crate provides many methods for converting between color types. Everything is implemented abstrac

Jacob 13 Dec 7, 2022