libosmscout 1.1.1
Loading...
Searching...
No Matches
LabelLayouterHelper.h
Go to the documentation of this file.
1#ifndef OSMSCOUT_MAP_LABELLAYOUTERHELPER_H
2#define OSMSCOUT_MAP_LABELLAYOUTERHELPER_H
3
4/*
5 This source is part of the libosmscout-map library
6 Copyright (C) 2018 Lukas Karas
7 Copyright (C) 2024 Tim Teulngs
8
9 This library is free software; you can redistribute it and/or
10 modify it under the terms of the GNU Lesser General Public
11 License as published by the Free Software Foundation; either
12 version 2.1 of the License, or (at your option) any later version.
13
14 This library is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 Lesser General Public License for more details.
18
19 You should have received a copy of the GNU Lesser General Public
20 License along with this library; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22*/
23
24#include <memory>
25#include <set>
26#include <array>
27
29
33
34#include <iostream>
35
36namespace osmscout {
37
39 int x;
40 int y;
41 int width;
42 int height;
43
44 // not initialised viewport
46
47 ScreenPixelRectangle(int x, int y, int width, int height)
48 : x(x),
49 y(y),
50 width(width),
52 {
53 }
54
62 bool Intersects(const ScreenPixelRectangle &other) const
63 {
64 return !(
65 (x + width-1) < other.x ||
66 x > (other.x + other.width-1) ||
67 (y + height-1) < other.y ||
68 y > (other.y + other.height-1)
69 );
70 }
71 };
72
74 double x;
75 double y;
76 double width;
77 double height;
78
79 // not initialised viewport
81
82 ScreenVectorRectangle(double x, double y, double width, double height)
83 : x(x),
84 y(y),
85 width(width),
87 {
88 }
89
90 ScreenVectorRectangle& Set(double nx, double ny, double nw, double nh)
91 {
92 x = nx;
93 y = ny;
94 width = nw;
95 height = nh;
96
97 return *this;
98 }
99
100 bool Intersects(const ScreenVectorRectangle &other) const
101 {
102 return !(
103 (x + width) < other.x ||
104 x > (other.x + other.width) ||
105 (y + height) < other.y ||
106 y > (other.y + other.height)
107 );
108 }
109 };
110
117 class OSMSCOUT_MAP_API ScreenRectMask CLASS_FINAL
118 {
119 private:
120 int cellFrom{0}; // First used byte of mask
121 int cellTo{0}; // Last used byte of mask
122 int rowFrom{0}; // First row of mask
123 int rowTo{0}; // Last row of mask
124 std::vector<uint64_t> bitmask; // bitmask for one row
125
126 public:
127 ScreenRectMask() = default;
128 ScreenRectMask(size_t screenWidth,
129 const ScreenPixelRectangle &rect);
130
131 bool Intersects(const ScreenRectMask& other) const;
132
137 int GetFirstRow() const {
138 return rowFrom;
139 }
140
145 int GetLastRow() const {
146 return rowTo;
147 }
148
153 int GetFirstCell() const {
154 return cellFrom;
155 }
156
161 int GetLastCell() const {
162 return cellTo;
163 }
164
174 uint64_t GetCell(size_t idx) const;
175 };
176
177 class OSMSCOUT_MAP_API ScreenMask CLASS_FINAL
178 {
179 private:
180 std::vector<uint64_t> bitmask;
181 size_t rowLength;
182 size_t height;
183
184 public:
185 ScreenMask(size_t width, size_t height);
186
187 void AddMask(const ScreenRectMask& mask);
188 bool HasCollision(const ScreenRectMask& mask) const;
189 };
190}
191
192#endif
#define CLASS_FINAL
Definition Compiler.h:26
#define OSMSCOUT_MAP_API
Definition MapImportExport.h:45
Definition Area.h:88
int GetLastCell() const
Definition LabelLayouterHelper.h:161
bool HasCollision(const ScreenRectMask &mask) const
int GetFirstRow() const
Definition LabelLayouterHelper.h:137
uint64_t GetCell(size_t idx) const
bool Intersects(const ScreenRectMask &other) const
int GetLastRow() const
Definition LabelLayouterHelper.h:145
ScreenMask(size_t width, size_t height)
ScreenRectMask(size_t screenWidth, const ScreenPixelRectangle &rect)
void AddMask(const ScreenRectMask &mask)
int GetFirstCell() const
Definition LabelLayouterHelper.h:153
Definition Area.h:39
Definition LabelLayouterHelper.h:38
int y
Definition LabelLayouterHelper.h:40
int x
Definition LabelLayouterHelper.h:39
int height
Definition LabelLayouterHelper.h:42
ScreenPixelRectangle(int x, int y, int width, int height)
Definition LabelLayouterHelper.h:47
bool Intersects(const ScreenPixelRectangle &other) const
Definition LabelLayouterHelper.h:62
int width
Definition LabelLayouterHelper.h:41
ScreenVectorRectangle(double x, double y, double width, double height)
Definition LabelLayouterHelper.h:82
double x
Definition LabelLayouterHelper.h:74
double y
Definition LabelLayouterHelper.h:75
double width
Definition LabelLayouterHelper.h:76
ScreenVectorRectangle & Set(double nx, double ny, double nw, double nh)
Definition LabelLayouterHelper.h:90
bool Intersects(const ScreenVectorRectangle &other) const
Definition LabelLayouterHelper.h:100
double height
Definition LabelLayouterHelper.h:77