Skip to content

Commit

Permalink
get rid of symbol area errors
Browse files Browse the repository at this point in the history
  • Loading branch information
andreas committed Feb 12, 2024
1 parent 55836a3 commit 41c4957
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 8 deletions.
2 changes: 2 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
"-k",
"-d",
"2",
"-c",
"0",
"-g",
"${workspaceFolder}/gui/build/debug",
"-t",
Expand Down
11 changes: 11 additions & 0 deletions provider/include/Coordinates.h
Original file line number Diff line number Diff line change
Expand Up @@ -246,11 +246,22 @@ namespace Coord
return rt;
}

//be careful when using this:
//as the world coordinates are shifted the returned pixel are shifted too
//so normally it only make sense to call this for relative coordinates (e.g. relative to a tile)
static inline Pixel worldToPixel(World c, uint32_t zoom){
if (zoom > COORD_ZOOM_LEVEL) return c;
return bitshift(c,-((COORD_ZOOM_LEVEL-zoom)+SUB_PIXEL_BITS));
}

//convert to 0 based Pixel coordinates
static inline Pixel worldToAbsPixel(World c, uint32_t zoom){
while (c > worldLimits.max()) c=worldLimits.shift(c,-worldLimits.worldShift());
while (c < worldLimits.min()) c=worldLimits.shift(c,worldLimits.worldShift());
c=worldLimits.clip(c);
return worldToPixel(worldLimits.shift(c,-worldLimits.halfshift()),zoom);
}

typedef Point<Pixel> PixelXy;
static inline PixelXy worldToPixel(const WorldXy &c, uint32_t zoom){
return PixelXy(worldToPixel(c.x,zoom),worldToPixel(c.y,zoom));
Expand Down
2 changes: 1 addition & 1 deletion provider/include/requestHandler/ChartRequestHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ class ChartRequestHandler : public RequestHandler {
chartUrl=res.url;
}
else{
return new HTTPErrorResponse(400,"unencryped url "+url);
;//return new HTTPErrorResponse(400,"unencryped url "+url);
}
}
TileInfo tile(chartUrl, chartSetKey);
Expand Down
6 changes: 3 additions & 3 deletions provider/src/DrawingContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1043,12 +1043,12 @@ void DrawingContext::drawTriangle(const Coord::PixelXy &p00, const Coord::PixelX
if (pyRaster > 0 && pxRaster > 0)
{
Coord::Pixel patterny = (y + pattern->yoffset) % pyRaster;
if (patterny < pattern->height)
if (patterny < pattern->height && patterny >= 0)
{
Coord::Pixel pxOffset = 0;
if (pattern->stagger)
{
if (((y + pattern->yoffset) / pyRaster) & 1)
if (((y + pattern->yoffset) / pyRaster) & 1) //shift pattern in every second row
{
pxOffset=pxRaster/2;
}
Expand All @@ -1057,7 +1057,7 @@ void DrawingContext::drawTriangle(const Coord::PixelXy &p00, const Coord::PixelX
ColorAndAlpha *ptr = buffer.get() + y * linelen;
for (Coord::Pixel x=xmin;x <= xmax; x++){
Coord::Pixel patternx= (x+pattern->xoffset+pxOffset)%pxRaster;
if (patternx < pattern->width){
if (patternx < pattern->width && patternx >= 0){
ColorAndAlpha *target = ptr + x;
ColorAndAlpha src= *(psrc+patternx);
hasDrawn=true;
Expand Down
10 changes: 6 additions & 4 deletions provider/src/RenderHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,10 +249,12 @@ DrawingContext::PatternSpec *RenderHelper::createPatternSpec(s52::SymbolPtr symb
symbol->height);
pattern->distance = symbol->minDist;
pattern->stagger = symbol->stagger;
Coord::World xraster = pattern->width + pattern->distance;
Coord::World yraster = pattern->height + pattern->distance;
Coord::World xoffset = Coord::worldToPixel(tile.xmin,tile.zoom) % xraster;
Coord::World yoffset = Coord::worldToPixel(tile.ymin,tile.zoom) % yraster;
Coord::Pixel xraster = pattern->width + pattern->distance;
Coord::Pixel yraster = pattern->height + pattern->distance;
//we need some absolute pixel values for the %
//as our world coordinates are shifted we have to shift back
Coord::Pixel xoffset = Coord::worldToAbsPixel(tile.xmin,tile.zoom) % xraster;
Coord::Pixel yoffset = Coord::worldToAbsPixel(tile.ymin,tile.zoom) % yraster;
pattern->xoffset = xoffset;
pattern->yoffset = yoffset;
return pattern;
Expand Down

0 comments on commit 41c4957

Please sign in to comment.