Skip to content

Commit

Permalink
Issue Framstag#1045 - Cleanup of MapPainter
Browse files Browse the repository at this point in the history
- Further deprecations, cleanups and transformation of APIs to Vertex2D
  • Loading branch information
Framstag authored and DerKleinePunk committed Jul 16, 2023
1 parent 6586fd6 commit ebed0f3
Show file tree
Hide file tree
Showing 29 changed files with 158 additions and 132 deletions.
3 changes: 1 addition & 2 deletions Demos/include/DrawMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -362,8 +362,7 @@ class DrawMapDemo
return true;
}

osmscout::GeoBox boundingBox;
projection.GetDimensions(boundingBox);
osmscout::GeoBox boundingBox(projection.GetDimensions());
if (!waterIndex->GetRegions(boundingBox,
projection.GetMagnification(),
tiles)) {
Expand Down
3 changes: 1 addition & 2 deletions Demos/src/Tiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,6 @@ int main(int argc, char* argv[])
for (uint32_t x=xTileStart; x<=xTileEnd; x++) {
agg::pixfmt_rgb24 pf(rbuf);
osmscout::StopClock timer;
osmscout::GeoBox boundingBox;
osmscout::MapData data;

projection.Set(osmscout::OSMTileId(x,y),
Expand All @@ -368,7 +367,7 @@ int main(int argc, char* argv[])
tileWidth,
tileHeight);

projection.GetDimensions(boundingBox);
osmscout::GeoBox boundingBox(projection.GetDimensions());

std::cout << "Drawing tile " << level << "." << y << "." << x << " " << boundingBox.GetDisplayText() << std::endl;

Expand Down
3 changes: 1 addition & 2 deletions OSMScoutOpenGL/src/OSMScoutOpenGL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,7 @@ static void cursor_position_callback(GLFWwindow */*window*/, double xpos, double
loadData = 1;
lastEvent = std::chrono::steady_clock::now();

osmscout::GeoBox boundingBox;
renderer->GetProjection().GetDimensions(boundingBox);
osmscout::GeoBox boundingBox(renderer->GetProjection().GetDimensions());
osmscout::log.Info() << "BoundingBox: [" << boundingBox.GetMinLon() << " " << boundingBox.GetMinLat() << " "
<< boundingBox.GetMaxLon() << " " << boundingBox.GetMaxLat() << "]";
osmscout::log.Info() << "Center: [" << renderer->GetCenter().GetLon() << " " << renderer->GetCenter().GetLat() << "]";
Expand Down
8 changes: 4 additions & 4 deletions Tests/src/CoordBufferTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ TEST_CASE("Check bounding box of generated parallel way")
CoordBuffer buffer;
CoordBufferRange range;

buffer.PushCoord(0,0);
buffer.PushCoord(10,0);
buffer.PushCoord(5,1);
buffer.PushCoord(0,0);
buffer.PushCoord(osmscout::Vertex2D(0.0,0.0));
buffer.PushCoord(osmscout::Vertex2D(10.0,0.0));
buffer.PushCoord(osmscout::Vertex2D(5.0,1.0));
buffer.PushCoord(osmscout::Vertex2D(0.0,0.0));

range=buffer.GenerateParallelWay(CoordBufferRange(buffer,0,3), /*offset*/-1);
REQUIRE(range.GetEnd() - range.GetStart() >= 3);
Expand Down
2 changes: 1 addition & 1 deletion Tests/src/DrawTextQt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ void DrawWindow::paintEvent(QPaintEvent* /* event */)
for (int x=startOffset;(x+startOffset)<width();x++){
//int y=std::cos(((double)(x+sinStart)/(double)width()) *3*M_PI) * (height()/2-44) + height()/2;
int y=std::sin(((double)(x+sinStart+moveOffset)/(double)width()) *2*M_PI) * (height()/2-44) + height()/2;
p.AddPoint(x,y);
p.AddPoint(osmscout::Vertex2D(x,y));
}
sinStart+=30;

Expand Down
24 changes: 12 additions & 12 deletions Tests/src/LabelPathTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ using namespace osmscout;
TEST_CASE("Angle variance with low angle")
{
LabelPath path;
path.AddPoint(0, 0);
path.AddPoint(10, 0);
path.AddPoint(20, 4);
path.AddPoint(osmscout::Vertex2D(0.0, 0.0));
path.AddPoint(osmscout::Vertex2D(10.0, 0.0));
path.AddPoint(osmscout::Vertex2D(20.0, 4.0));

REQUIRE(path.TestAngleVariance(0, 20, DegToRad(45)));
REQUIRE_FALSE(path.TestAngleVariance(0, 20, DegToRad(10)));
Expand All @@ -20,9 +20,9 @@ TEST_CASE("Angle variance with low angle")
TEST_CASE("Angle variance with low angle 2")
{
LabelPath path;
path.AddPoint(10, 0);
path.AddPoint(0, 0);
path.AddPoint(-10, 4);
path.AddPoint(osmscout::Vertex2D(10.0, 0.0));
path.AddPoint(osmscout::Vertex2D(0.0, 0.0));
path.AddPoint(osmscout::Vertex2D(-10.0, 4.0));

REQUIRE(path.TestAngleVariance(0, 20, DegToRad(25)));
REQUIRE_FALSE(path.TestAngleVariance(0, 20, DegToRad(10)));
Expand All @@ -31,9 +31,9 @@ TEST_CASE("Angle variance with low angle 2")
TEST_CASE("Angle variance with low angle 3")
{
LabelPath path;
path.AddPoint(-10, 0);
path.AddPoint(0, 0);
path.AddPoint(10, 4);
path.AddPoint(osmscout::Vertex2D(-10.0, 0.0));
path.AddPoint(osmscout::Vertex2D(0.0, 0.0));
path.AddPoint(osmscout::Vertex2D(10.0, 4.0));

REQUIRE(path.TestAngleVariance(0, 20, DegToRad(25)));
REQUIRE_FALSE(path.TestAngleVariance(0, 20, DegToRad(10)));
Expand All @@ -42,8 +42,8 @@ TEST_CASE("Angle variance with low angle 3")
TEST_CASE("Angle variance with high angle")
{
LabelPath path;
path.AddPoint(10,0);
path.AddPoint(0,0);
path.AddPoint(10,5);
path.AddPoint(osmscout::Vertex2D(10.0,0.0));
path.AddPoint(osmscout::Vertex2D(0.0,0.0));
path.AddPoint(osmscout::Vertex2D(10.0,5.0));
REQUIRE_FALSE(path.TestAngleVariance(0, 20, DegToRad(45)));
}
4 changes: 2 additions & 2 deletions Tests/src/PerformanceTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -835,7 +835,6 @@ int main(int argc, char* argv[])
osmscout::MapData data;
osmscout::OSMTileIdBox tileBox(osmscout::OSMTileId(tile.GetX()-1,tile.GetY()-1),
osmscout::OSMTileId(tile.GetX()+1,tile.GetY()+1));
osmscout::GeoBox boundingBox;

if ((current % delta)==0) {
std::cout << current*100/tileCount << "% " << current;
Expand All @@ -854,7 +853,8 @@ int main(int argc, char* argv[])
args.TileWidth(),
args.TileHeight());

projection.GetDimensions(boundingBox);
osmscout::GeoBox boundingBox(projection.GetDimensions());

projection.SetLinearInterpolationUsage(level.Get() >= 10);

for (size_t i=0; i<args.loadRepeat; i++) {
Expand Down
3 changes: 1 addition & 2 deletions libosmscout-client-qt/src/osmscoutclientqt/DBJob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,7 @@ void DBLoadJob::Run(const osmscout::BasemapDatabaseRef& basemapDatabase,
const std::list<DBInstanceRef> &databases,
QReadLocker *locker)
{
osmscout::GeoBox lookupBox;
lookupProjection.GetDimensions(lookupBox);
osmscout::GeoBox lookupBox(lookupProjection.GetDimensions());
std::list<DBInstanceRef> relevantDatabases;
for (const auto &db:databases){
if (!db->IsOpen() || (!db->GetStyleConfig())) {
Expand Down
3 changes: 1 addition & 2 deletions libosmscout-client-qt/src/osmscoutclientqt/MapRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -363,8 +363,7 @@ bool DBRenderJob::addBasemapData(MapDataRef data) const
if (!waterIndex) {
return false;
}
osmscout::GeoBox boundingBox;
renderProjection.GetDimensions(boundingBox);
osmscout::GeoBox boundingBox(renderProjection.GetDimensions());
return waterIndex->GetRegions(boundingBox,
renderProjection.GetMagnification(),
data->baseMapTiles);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -379,8 +379,7 @@ void PlaneMapRenderer::DrawMap()

// overlay objects
std::vector<OverlayObjectRef> overlayObjects;
osmscout::GeoBox renderBox;
projection.GetDimensions(renderBox);
osmscout::GeoBox renderBox(projection.GetDimensions());
getOverlayObjects(overlayObjects, renderBox);

bool success;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -464,8 +464,7 @@ void TiledMapRenderer::onLoadJobFinished(QMap<QString,QMap<osmscout::TileKey,osm

// overlay ways
std::vector<OverlayObjectRef> overlayObjects;
osmscout::GeoBox renderBox;
projection.GetDimensions(renderBox);
osmscout::GeoBox renderBox(projection.GetDimensions());
getOverlayObjects(overlayObjects, renderBox);

//DrawMap(p, tileVisualCenter, loadZ, canvas.width(), canvas.height());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,7 @@ bool TiledRenderingHelper::RenderTiles(QPainter &painter,
width,
height);

osmscout::GeoBox boundingBox;

projection.GetDimensions(boundingBox);
osmscout::GeoBox boundingBox(projection.GetDimensions());

QColor grey2 = QColor::fromRgbF(0.8,0.8,0.8);

Expand Down
7 changes: 5 additions & 2 deletions libosmscout-map-agg/src/osmscoutmapagg/MapPainterAgg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ namespace osmscout {
for (const auto &nativeGlyph : label.glyphs) {
MapPainterAgg::AggGlyph glyph{};
glyph.glyph=nativeGlyph;
glyph.position.Set(nativeGlyph.x, nativeGlyph.y);
glyph.position=Vertex2D(nativeGlyph.x, nativeGlyph.y);
result.emplace_back(glyph);
}
return result;
Expand Down Expand Up @@ -422,7 +422,10 @@ namespace osmscout {
const PathLabelData &label,
const LabelPath &labelPath)
{
labelLayouter.RegisterContourLabel(projection, parameter, label, labelPath);
labelLayouter.RegisterContourLabel(projection,
parameter,
label,
labelPath);
}

void MapPainterAgg::DrawLabels(const Projection& projection,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -714,8 +714,8 @@ namespace osmscout {
result.back().glyph.font = font;


result.back().position.SetX(((double)glyphInfo.geometry.x_offset/(double)PANGO_SCALE) + horizontalOffset);
result.back().position.SetY((double)glyphInfo.geometry.y_offset/(double)PANGO_SCALE);
result.back().position=Vertex2D(((double)glyphInfo.geometry.x_offset/(double)PANGO_SCALE) + horizontalOffset,
(double)glyphInfo.geometry.y_offset/(double)PANGO_SCALE);

if constexpr (debugLabelLayouter) {
std::cout << " " << glyphInfo.glyph << ": " << result.back().position.GetX() << " x "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -415,8 +415,7 @@ namespace osmscout {
double yMin = std::min(minPixel.GetY(), maxPixel.GetY()) - pixelOffset;
double yMax = std::max(minPixel.GetY(), maxPixel.GetY()) + pixelOffset;

osmscout::GeoBox gb;
projection.GetDimensions(gb);
osmscout::GeoBox gb(projection.GetDimensions());
double areaMinDimension = projection.ConvertWidthToPixel(parameter.GetAreaMinDimensionMM());

if (xMax - xMin <= areaMinDimension &&
Expand Down
14 changes: 8 additions & 6 deletions libosmscout-map-qt/src/osmscoutmapqt/MapPainterQt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -523,8 +523,7 @@ namespace osmscout {
}

hnd.direction=(hnd.transStart < hnd.transEnd) ? 1 : -1;
origin.Set(coordRange.Get(hnd.transStart).GetX(),
coordRange.Get(hnd.transStart).GetY());
origin=coordRange.Get(hnd.transStart);
}

bool MapPainterQt::FollowPath(FollowPathHandle &hnd,
Expand Down Expand Up @@ -553,8 +552,8 @@ namespace osmscout {
double fracToGo=l/len;

if (fracToGo<=1.0) {
origin.Set(x + deltaX*fracToGo,
y + deltaY*fracToGo);
origin=Vertex2D(x + deltaX*fracToGo,
y + deltaY*fracToGo);
return true;
}

Expand Down Expand Up @@ -882,7 +881,10 @@ namespace osmscout {
const PathLabelData &label,
const LabelPath &labelPath)
{
GetLayouter().RegisterContourLabel(projection, parameter, label, labelPath);
GetLayouter().RegisterContourLabel(projection,
parameter,
label,
labelPath);
}

void MapPainterQt::DrawLabels(const Projection& projection,
Expand Down Expand Up @@ -1074,7 +1076,7 @@ namespace osmscout {

QtGlyph glyph;
glyph.glyph=std::move(orphanGlyph);
glyph.position.Set(pos.x(), pos.y());
glyph.position=Vertex2D(pos.x(), pos.y());
result.push_back(std::move(glyph));
}
}
Expand Down
9 changes: 6 additions & 3 deletions libosmscout-map-svg/src/osmscoutmapsvg/MapPainterSVG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,8 @@ namespace osmscout {

result.back().glyph.character = WStringToUTF8String(label.substr(ch,1));

result.back().position.SetX(horizontalOffset);
result.back().position.SetY(0);
result.back().position=Vertex2D(horizontalOffset,
0.0);

horizontalOffset += (double)(height * MapPainterSVG::AverageCharacterWidth);
}
Expand Down Expand Up @@ -731,7 +731,10 @@ namespace osmscout {
const PathLabelData &label,
const LabelPath &labelPath)
{
labelLayouter.RegisterContourLabel(projection, parameter, label, labelPath);
labelLayouter.RegisterContourLabel(projection,
parameter,
label,
labelPath);
}

void MapPainterSVG::IconData(const Projection& projection,
Expand Down
3 changes: 2 additions & 1 deletion libosmscout-map/include/osmscoutmap/LabelLayouter.h
Original file line number Diff line number Diff line change
Expand Up @@ -916,7 +916,8 @@ constexpr bool debugLabelLayouter = false;
maxY = std::max(maxY, y[i]);
}
// setup glyph top-left position and dimension after rotation
glyphCopy.trPosition.Set(minX+glyphCopy.position.GetX(), minY+glyphCopy.position.GetY());
glyphCopy.trPosition=Vertex2D(minX+glyphCopy.position.GetX(),
minY+glyphCopy.position.GetY());
glyphCopy.trWidth = maxX - minX;
glyphCopy.trHeight = maxY - minY;

Expand Down
5 changes: 3 additions & 2 deletions libosmscout-map/include/osmscoutmap/LabelPath.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@
*/

#include <osmscoutmap/MapImportExport.h>
#include <osmscout/Pixel.h>

#include <vector>

#include <osmscout/Pixel.h>

namespace osmscout {
struct Segment
{
Expand Down Expand Up @@ -52,7 +53,7 @@ namespace osmscout {
public:
explicit LabelPath(double minSegmentLength=5);
virtual ~LabelPath();
void AddPoint(double x,double y);
void AddPoint(const Vertex2D& point);
double GetLength() const {
return length+endDistance;
}
Expand Down
4 changes: 2 additions & 2 deletions libosmscout-map/include/osmscoutmap/MapPainter.h
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ namespace osmscout {

std::vector<TextStyleRef> textStyles; //!< Temporary storage for StyleConfig return value
std::vector<LineStyleRef> lineStyles; //!< Temporary storage for StyleConfig return value
std::vector<PathSymbolStyleRef> symbolStyles; //!< Temporary storage for StyleConfig return value

/** L
Precalculations
Expand Down Expand Up @@ -337,8 +338,7 @@ namespace osmscout {
const IconStyleRef& iconStyle,
const std::vector<TextStyleRef>& textStyles,
const Vertex2D& screenPos,
double objectWidth=0,
double objectHeight=0);
const ScreenBox& objectBox);

bool DrawWayDecoration(const StyleConfig& styleConfig,
const Projection& projection,
Expand Down
11 changes: 6 additions & 5 deletions libosmscout-map/src/osmscoutmap/LabelPath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,21 @@ namespace osmscout {
{
}

void LabelPath::AddPoint(double x,double y)
void LabelPath::AddPoint(const Vertex2D& point)
{
if (segments.empty()){
end.Set(x,y);
end=point;
Segment s={end,0,0,0};
segments.push_back(s);
}else{
end.Set(x,y);
end=point;
Segment last=segments.back();
double endDistance = last.start.DistanceTo(Vertex2D(x,y)); // QVector2D(last.start).distanceToPoint(QVector2D(x,y));
double endDistance = last.start.DistanceTo(point); // QVector2D(last.start).distanceToPoint(QVector2D(x,y));
if (endDistance>minSegmentLength){
length+=endDistance;
last.length=endDistance;
last.angle=std::atan2(last.start.GetY()-y,x-last.start.GetX());
last.angle=std::atan2(last.start.GetY()-point.GetY(),
point.GetX()-last.start.GetX());
segments[segments.size()-1]=last;

// fill offsetIndex
Expand Down
Loading

0 comments on commit ebed0f3

Please sign in to comment.