1Tickit::Rect(3) User Contributed Perl Documentation Tickit::Rect(3)
2
3
4
6 "Tickit::Rect" - a lightweight data structure representing a rectangle
7
9 use Tickit::Rect;
10
11 my $rect = Tickit::Rect->new(
12 top => 0, left => 5, lines => 3, cols => 10
13 );
14
16 Objects in this class represent a rectangle, by storing the top left
17 corner coordinate and the size in lines and columns. This data
18 structure is purely abstract and not tied to a particular window or
19 coordinate system. It exists simply as a convenient data store
20 containing some useful utility methods.
21
23 new
24 $rect = Tickit::Rect->new( %args )
25
26 Construct a new rectangle of the given geometry, given by "top", "left"
27 and either "lines" and "cols", or "bottom" and "right".
28
29 $rect = Tickit::Rect->new( $str )
30
31 If given a single string, this will be parsed in the form
32
33 (left,top)..(right,bottom)
34
35 intersect
36 $rect = $existing_rect->intersect( $other_rect )
37
38 If there is an intersection between the given rectangles, return it. If
39 not, return "undef".
40
41 translate
42 $rect = $existing_rect->translate( $downward, $rightward )
43
44 Returns a new rectangle of the same size as the given one, moved down
45 and to the right by the given argmuents (which may be negative)
46
48 top
49 left
50 bottom
51 right
52 $top = $rect->top
53
54 $left = $rect->left
55
56 $bottom = $rect->bottom
57
58 $right = $rect->right
59
60 Return the edge boundaries of the rectangle.
61
62 lines
63 cols
64 $lines = $rect->lines
65
66 $cols = $rect->cols
67
68 Return the size of the rectangle.
69
70 linerange
71 @lines = $rect->linerange( $min, $max )
72
73 A convenient shortcut to generate the list of lines covered that are
74 within the given bounds (either bound may be given as "undef"). Without
75 bounds, equivalent to:
76
77 $rect->top .. $rect->bottom - 1
78
80 equals
81 $bool = $rect->equals( $other )
82
83 $bool = ( $rect == $other )
84
85 Returns true if $other represents the same area as $rect. This method
86 overloads the numerical equality operator ("==").
87
88 contains
89 $bool = $rect->contains( $other )
90
91 Returns true if $other is entirely contained within the bounds of
92 $rect.
93
94 intersects
95 $bool = $rect->intersects( $other )
96
97 Returns true if $other and $rect intersect at all, even if they
98 overlap.
99
100 add
101 @r = $rect->add( $other )
102
103 Returns a list of the non-overlapping regions covered by either $rect
104 or $other.
105
106 In the trivial case that the two given rectangles do not touch, the
107 result will simply be a list of the two initial rectangles. Otherwise a
108 list of newly-constructed rectangles will be returned that covers the
109 same area as the original two. This list will contain anywhere between
110 1 and 3 rectangles.
111
112 subtract
113 @r = $rect->subtract( $other )
114
115 Returns a list of the non-overlapping regions covered by $rect but not
116 by $other.
117
118 In the trivial case that $other completely covers $rect then the empty
119 list is returned. In the trivial case that $other and $rect do not
120 intersect then a list containing $rect is returned. Otherwise, a list
121 of newly-constructed rectangles will be returned that covers the
122 required area. This list will contain anywhere between 1 and 4
123 rectangles.
124
126 Paul Evans <leonerd@leonerd.org.uk>
127
128
129
130perl v5.36.0 2023-01-20 Tickit::Rect(3)