@@ -2,6 +2,11 @@ Area = { __class = 'Area' }
22AreaMT = { __index = Area }
33
44function Area :new (firstCorner , width , height )
5+ -- Special handling for rect
6+ if type (firstCorner ) == ' userdata' and firstCorner .objtype == ' rect' then
7+ return Area :new (Point :new (firstCorner .left , firstCorner .top ), firstCorner .width , firstCorner .height )
8+ end
9+
510 firstCorner = Point :new (firstCorner )
611
712 local secondCorner = Point :new (width )
@@ -21,6 +26,56 @@ function Area:new(firstCorner, width, height)
2126 return newObj
2227end
2328
29+ function Area :createFromWaypoint (waypoint )
30+ local topLeft = Point :new (get (waypoint , ' Coordinates' ):match (REGEX_COORDS ))
31+ local width , height = get (waypoint , ' Range' ):match (REGEX_RANGE )
32+
33+ return Area :new (topLeft , width , height )
34+ end
35+
36+ function Area :createFromSpecialArea (specialArea )
37+ local topLeft = Point :new (get (specialArea , ' Coordinates' ):match (REGEX_COORDS ))
38+ local width , height = get (specialArea , ' Size' ):match (REGEX_RANGE )
39+
40+ return Area :new (topLeft , width , height )
41+ end
42+
43+ function Area :extend (top , right , bottom , left )
44+ -- This gives us a CSS-like workflow; the one that usually works in margin
45+ -- and padding shorthands
46+ top = top or 0
47+ right = right or top
48+ bottom = bottom or top
49+ left = left or right
50+
51+ self .topLeft = self .topLeft - Point :new (top , left )
52+ self .botRight = self .botRight + Point :new (bottom , right )
53+ end
54+
55+ function Area :getLeft ()
56+ return self .topLeft .x
57+ end
58+
59+ function Area :getTop ()
60+ return self .topLeft .y
61+ end
62+
63+ function Area :getRight ()
64+ return self .botRight .x
65+ end
66+
67+ function Area :getBottom ()
68+ return self .botRight .y
69+ end
70+
71+ function Area :getWidth ()
72+ return self .botRight .x - self .topLeft .x
73+ end
74+
75+ function Area :getHeight ()
76+ return self .botRight .y - self .topLeft .y
77+ end
78+
2479function Area :hasPoint (point , y )
2580 point = Point :new (point , y )
2681
@@ -30,6 +85,13 @@ function Area:hasPoint(point, y)
3085 point .y <= self .botRight .y
3186end
3287
88+ function Area :move (point , y )
89+ point = Point :new (point , y )
90+
91+ self .topLeft = self .topLeft + point
92+ self .botRight = self .botRight + point
93+ end
94+
3395function AreaMT :__tostring ()
3496 return ' {topLeft = ' .. tostring (self .topLeft ) .. ' , botRight = ' .. tostring (self .botRight ) .. ' }'
3597end
0 commit comments