mapbox / earcut.hpp

Fast, header-only polygon triangulation
ISC License
858 stars 133 forks source link

Is this box calculated incorrectly? Is it missing a point? #115

Closed YouGuess1114 closed 2 months ago

YouGuess1114 commented 2 months ago

Node* p = outerNode->next; minX = maxX = p->x; minY = maxY = p->y; do { x = p->x; y = p->y; minX = std::min(minX, x); minY = std::min(minY, y); maxX = std::max(maxX, x); maxY = std::max(maxY, y); p = p->next; } while (p != outerNode);

Question: The node of outerNode is missing?please check

Otherwise, y here would be less than 0.

// z-order of a Vertex given coords and size of the data bounding box template int32t Earcut::zOrder(const double x, const double y_) { // coords are transformed into non-negative 15-bit integer range int32_t x = static_cast(32767.0 (x_ - minX) inv_size); int32_t y = static_cast(32767.0 (y_ - minY) inv_size);

x = (x | (x << 8)) & 0x00FF00FF;
x = (x | (x << 4)) & 0x0F0F0F0F;
x = (x | (x << 2)) & 0x33333333;
x = (x | (x << 1)) & 0x55555555;

if(y < 0)
{
    printf("");
}
y = (y | (y << 8)) & 0x00FF00FF;
y = (y | (y << 4)) & 0x0F0F0F0F;
y = (y | (y << 2)) & 0x33333333;
y = (y | (y << 1)) & 0x55555555;

return x | (y << 1);

}

YouGuess1114 commented 2 months ago

Is this the right way?

    minX = maxX = outerNode->x;
    minY = maxY = outerNode->y;
    Node* p = outerNode->next;
    do
    {
        x = p->x;
        y = p->y;
        minX = std::min<double>(minX, x);
        minY = std::min<double>(minY, y);
        maxX = std::max<double>(maxX, x);
        maxY = std::max<double>(maxY, y);
        p = p->next;
    } while (p != outerNode);
mrgreywater commented 2 months ago

Hi @YouGuess1114 . This bug has already been fixed in v2.2.4. See #56 and f4be3db809d2cf9133ef54c685fb6bb5a463c115