Polygon.h
1/* Copyright (C) 2017 Marc Boris Duerner
2 Copyright (C) 2017 Aloysius Indrayanto
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
8
9 As a special exception, you may use this file as part of a free
10 software library without restriction. Specifically, if other files
11 instantiate templates or use macros or inline functions from this
12 file, or you compile this file and link it with other files to
13 produce an executable, this file does not by itself cause the
14 resulting executable to be covered by the GNU General Public
15 License. This exception does not however invalidate any other
16 reasons why the executable file might be covered by the GNU Library
17 General Public License.
18
19 This library is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 Lesser General Public License for more details.
23
24 You should have received a copy of the GNU Lesser General Public
25 License along with this library; if not, write to the Free Software
26 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
27 MA 02110-1301 USA
28*/
29
30#ifndef PT_GFX_PPOLYGON_H
31#define PT_GFX_PPOLYGON_H
32
33#include <Pt/Gfx/Api.h>
34#include <Pt/Gfx/Point.h>
35#include <vector>
36
37namespace Pt {
38
39namespace Gfx {
40
41/* @brief A polygon consisting of multiple points.
42*/
43class Polygon
44{
45 public:
46 Polygon(const PointF* ps, std::size_t n)
47 : _points(ps, ps + n)
48 {
49 }
50
51 Polygon()
52 {
53 }
54
55 void assign(const PointF* ps, std::size_t n)
56 {
57 _points.assign(ps, ps+n);
58 }
59
60 const PointF& operator[](std::size_t n) const
61 {
62 return _points[n];
63 }
64
65 PointF& operator[](std::size_t n)
66 {
67 return _points[n];
68 }
69
70 const PointF& at(std::size_t n) const
71 {
72 return _points[n];
73 }
74
75 PointF& at(std::size_t n)
76 {
77 return _points[n];
78 }
79
80 const PointF* points() const
81 {
82 return _points.empty() ? 0 : &_points[0];
83 }
84
85 void clear()
86 {
87 _points.clear();
88 }
89
90 bool empty() const
91 {
92 return _points.empty();
93 }
94
95 std::size_t size() const
96 {
97 return _points.size();
98 }
99
100 void push_back(const PointF& p)
101 {
102 _points.push_back(p);
103 }
104
105 void pop_back()
106 {
107 _points.pop_back();
108 }
109
110 private:
111 std::vector<PointF> _points;
112};
113
114} // namespace
115
116} // namespace
117
118#endif
Graphics and imaging services.
Definition Api-Argb32Image.h:12
Core module.
Definition Allocator.h:33