1// LAF Gfx Library
2// Copyright (C) 2019 Igara Studio S.A.
3//
4// This file is released under the terms of the MIT license.
5// Read LICENSE.txt for more information.
6
7#ifdef HAVE_CONFIG_H
8#include "config.h"
9#endif
10
11#include "gfx/region.h"
12
13namespace gfx {
14
15inline Rect to_rect(const SkIRect& rc)
16{
17 return Rect(rc.x(), rc.y(), rc.width(), rc.height());
18}
19
20Region::Region()
21{
22}
23
24Region::Region(const Region& copy)
25 : m_region(copy.m_region)
26{
27}
28
29Region::Region(const Rect& rect)
30 : m_region(SkIRect::MakeXYWH(rect.x, rect.y, rect.w, rect.h))
31{
32}
33
34Region& Region::operator=(const Rect& rect)
35{
36 m_region.setRect(SkIRect::MakeXYWH(rect.x, rect.y, rect.w, rect.h));
37 return *this;
38}
39
40Region& Region::operator=(const Region& copy)
41{
42 m_region = copy.m_region;
43 return *this;
44}
45
46Region::iterator Region::begin()
47{
48 iterator it;
49 it.m_it = SkRegion::Iterator(m_region);
50 return it;
51}
52
53Region::iterator Region::end()
54{
55 return iterator();
56}
57
58Region::const_iterator Region::begin() const
59{
60 iterator it;
61 it.m_it = SkRegion::Iterator(m_region);
62 return it;
63}
64
65Region::const_iterator Region::end() const
66{
67 return iterator();
68}
69
70Rect Region::bounds() const
71{
72 return to_rect(m_region.getBounds());
73}
74
75Region::Overlap Region::contains(const Rect& rect) const
76{
77 auto rc = SkIRect::MakeXYWH(rect.x, rect.y, rect.w, rect.h);
78 if (m_region.contains(rc))
79 return In;
80 else if (m_region.intersects(rc))
81 return Part;
82 else
83 return Out;
84}
85
86} // namespace gfx
87