[core] Look the other way when placing icon at start of line

When an anchor is at the beginning of a line, its segment’s coordinates match its own coordinates, resulting in an angle of 0°. When the segment’s coordinates match the anchor’s coordinates, consider the next segment instead.

Fixes #2474.
This commit is contained in:
Minh Nguyễn
2015-10-05 14:52:10 -07:00
committed by Minh Nguyễn
parent 3bbb87c6d7
commit 9482649ae5

View File

@@ -28,7 +28,13 @@ SymbolQuads getIconQuads(Anchor &anchor, const PositionedIcon &shapedIcon,
if (alongLine) {
assert(static_cast<unsigned int>(anchor.segment) < line.size());
const Coordinate &prev= line[anchor.segment];
angle += std::atan2(anchor.y - prev.y, anchor.x - prev.x);
if (anchor.y == prev.y && anchor.x == prev.x &&
static_cast<unsigned int>(anchor.segment + 1) < line.size()) {
const Coordinate &next= line[anchor.segment + 1];
angle += std::atan2(anchor.y - next.y, anchor.x - next.x) + M_PI;
} else {
angle += std::atan2(anchor.y - prev.y, anchor.x - prev.x);
}
}