NAME

TUI::Objects::Rect - rectangular area defined by two points

HIERARCHY

TRect (value type)
  composed of two TPoint objects

SYNOPSIS

use TUI::Objects;

my $r1 = TRect->new( ax => 0, ay => 0, bx => 80, by => 25 );
my $r2 = TRect->new(
  a => TPoint->new( x => 10, y => 5 ),
  b => TPoint->new( x => 40, y => 15 ),
);

my $copy = $r1->clone();
$copy->move( 2, 1 );
$copy->grow( 1, 1 );

if ( $r1 == $r2 ) {
  ...
}

DESCRIPTION

TRect represents a rectangular area defined by two corner points. The attribute a specifies the upper-left corner and b specifies the lower-right corner of the rectangle.

TRect is a lightweight value type and is not derived from TObject. It is used throughout TUI::Vision to describe screen locations and sizes of views, dialogs, and controls.

The class provides a set of geometric operations such as moving, resizing, intersection, and containment testing. Rectangles can also be compared for equality using operator overloading.

Commonly Used Features

Most code constructs rectangles directly with TRect->new using coordinate arguments, then passes them into view and dialog constructors. For incremental layout changes, move and grow are the common operations, and clone is useful when you need a temporary variant without mutating the original bounds object.

CONSTRUCTOR

new

my $rect = TRect->new();

my $rect = TRect->new(
  a => $pointA,
  b => $pointB
);

my $rect = TRect->new(
  ax => $ax,
  ay => $ay,
  bx => $bx,
  by => $by
);

Creates a new rectangle.

When point coordinates are supplied, the constructor creates internal TPoint objects automatically.

a

Upper-left corner as a TPoint.

b

Lower-right corner as a TPoint.

ax, ay, bx, by

Integer coordinates used to initialize the corner points.

new_TRect

my $rect = new_TRect($ax, $ay, $bx, $by);

Factory-style constructor using positional arguments.

This constructor is provided for compatibility with traditional Turbo Vision construction patterns.

ATTRIBUTES

The following attributes define the rectangle geometry.

a

Upper-left corner of the rectangle (TPoint).

b

Lower-right corner of the rectangle (TPoint).

METHODS

assign

$rect->assign($ax, $ay, $bx, $by);

Sets the coordinates of the rectangle corners.

clone

my $copy = $rect->clone();

Creates and returns a copy of the rectangle.

contains

my $bool = $rect->contains($point);

Returns true if the specified point lies within the rectangle.

dump

my $string = $rect->dump();

Returns a string representation of the rectangle for debugging.

equal

my $bool = $rect->equal($other, | $swap);

Implements the == operator for rectangle comparison.

grow

$rect->grow($dx, $dy);

Expands or contracts the rectangle by adjusting its corner points.

intersect

$rect->intersect($other);

Modifies the rectangle to become the intersection of itself and another rectangle.

isEmpty

my $bool = $rect->isEmpty();

Returns true if the rectangle has zero area.

move

$rect->move($dx, $dy);

Moves the rectangle by adding offsets to both corner points.

not_equal

my $bool = $rect->not_equal($other, | $swap);

Implements the != operator for rectangle comparison.

union

$rect->union($other);

Expands the rectangle so that it encompasses both rectangles.

OPERATOR OVERLOADING

TRect supports comparison operators through Perl operator overloading.

  • == maps to equal

  • != maps to not_equal

SEE ALSO

TUI::Objects::Point, TUI::Views::View

AUTHORS

  • Borland International (original Turbo Vision design)

  • J. Schneider <brickpool@cpan.org> (Perl implementation and maintenance)

COPYRIGHT AND LICENSE

Copyright (c) 1990-1994, 1997 by Borland International

Copyright (c) 2021-2026 the "AUTHORS" as listed above.

This software is licensed under the MIT license (see the LICENSE file, which is part of the distribution).