summaryrefslogtreecommitdiff
path: root/Data/BuiltIn/Libraries/GameLab/Engine/Math/Rect.lua
blob: afadee8db596bcea16e4885614a6373616f734d2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
local Rect = GameLab.GlobalClass("GameLab.Engine.Math.Rect")
local Vector2 = GameLab.Include("GameLab.Engine.Math.Vector2")

Rect.Ctor = function(self, x, y, width, height)
    self.x = x or 0
    self.y = y or 0
    self.width = width or 0
    self.height = height or 0
end

Rect.Set = function(self, rect)
    if rect.Is and rect:Is(Rect) then 
        self.x = rect.x or rect.x
        self.y = rect.y or rect.y
        self.width = rect.z or rect.width
        self.height = rect.w or rect.height
    else
        self.x = rect.x or rect[1]
        self.y = rect.y or rect[2]
        self.width = rect.z or rect[3]
        self.height = rect.w or rect[4]
    end
end

Rect.get_xy = function(self)
    local v = Vector2(self.x, self.y)
    return v
end 

Rect.get_location = function(self)
    local v = Vector2(self.x, self.y)
    return v
end 

Rect.get_position = Rect.get_location

Rect.get_wh = function(self)
    local v = Vector2(self.width, self.height)
    return v
end 

Rect.get_size = function(self)
    local v = Vector2(self.width, self.height)
    return v
end 

Rect.get_w = function(self)
    return self.width 
end

Rect.set_w = function(self, w)
    self.width = w
end

Rect.get_h = function(self)
    return self.height 
end

Rect.set_h = function(self, h)
    self.height = h
end

Rect.GetSize = function(self)
    local v = Vector2(self.width, self.height)
    return v
end 

Rect.CopyFrom = function(self, rect)
    self.x = rect.x 
    self.y = rect.y 
    self.width = rect.width 
    self.height = rect.height
end 

Rect.Contains = function(self, point)
    return point.x >= self.x and point.x <= self.x + self.width
    and point.y >= self.y and point.y <= self.y + self.height
end

return Rect