struct Crame::Rect2

Overview

A two-dimensional rectangle.

Defined in:

crame/rect2.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(x : Float64, y : Float64, w : Float64, h : Float64) #

Creates a new rectangle by setting its position with x and y and its size with w and h.


def self.new(position : Crame::Vector2, size : Crame::Vector2) #

Creates a new rectangle given its position and size.


def self.new #

Creates a new rectangle with its position and size equal to 0.


Instance Method Detail

def area : Float64 #

Returns the area of self.

NOTE This is equivalent to size.x * size.y.


def center : Vector2 #

Returns the center point of self.

NOTE This is equivalent to position + size / 2.


def intersection(other : Rect2) : Rect2 #

Return the intersection between self and other.

If no intersection is detected, this returns an empty rectangle instead.


def intersects?(other : Rect2, borders : Bool = false) : Bool #

Returns true if self intersects with other, false otherwise.

If borders is true, the edges of both rectangles are included as potential intersection points.


def position : Vector2 #

The position of the rectangle.


def position=(position : Vector2) #

The position of the rectangle.


def size : Vector2 #

The size of the rectangle.


def size=(size : Vector2) #

The size of the rectangle.


def to_s(io : IO) #
Description copied from struct Struct

Same as #inspect(io).


def union(other : Rect2) : Rect2 #

Returns the smallest rectangle that contains self and other.