module

CrImage::BoundsCheck

BoundsCheck provides common bounds checking and clipping operations to reduce code duplication across draw operations

Class methods

clamp(value : Int32, min : Int32, max : Int32) : Int32

Clamp a value to a range

Source
clamp_point(x : Int32, y : Int32, bounds : Rectangle) : Tuple(Int32, Int32)

Clamp coordinates to bounds

Source
clamp_u8(value : Int32 | Float64) : UInt8

Clamp color value to 0-255 range

Source
clip_line(x0 : Int32, y0 : Int32, x1 : Int32, y1 : Int32, bounds : Rectangle) : Tuple(Int32, Int32, Int32, Int32) | Nil

Clip a line to rectangle bounds using Cohen-Sutherland algorithm Returns nil if line is completely outside, otherwise returns clipped coordinates

Source
clip_rect(rect : Rectangle, bounds : Rectangle) : Rectangle

Clip a rectangle to image bounds

Source
in_bounds?(x : Int32, y : Int32, bounds : Rectangle) : Bool

Check if a point is within bounds

Source
in_bounds?(point : Point, bounds : Rectangle) : Bool

Check if a point is within bounds

Source
overlap(r1 : Rectangle, r2 : Rectangle) : Rectangle | Nil

Get the overlapping region between two rectangles

Source
validate_rect!(rect : Rectangle, bounds : Rectangle)

Validate that a rectangle is within bounds, raise error if not

Source