erincatto / box2d

Box2D is a 2D physics engine for games
https://box2d.org
MIT License
7.44k stars 1.47k forks source link

unnecessary compassion in b2_collision.cpp #748

Open kritma opened 1 year ago

kritma commented 1 year ago
    if (count < 3 || count > b2_maxPolygonVertices)
    {
        // check your data
        return hull;
    }

    count = b2Min(count, b2_maxPolygonVertices); //this line is unnecessary
krabhi1 commented 9 months ago

How?

HughPH commented 9 months ago

count must always be less than or equal to b2_maxPolygonVertices according to the preceding if statement, so the call to b2Min is not required.

kritma commented 9 months ago

@krabhi7 this is same as

if(count < 3) {
    return hull;
}

if(count > b2_maxPolygonVertices) {
    return hull;
}

count = b2Min(count, b2_maxPolygonVertices); // count <= b2_maxPolygonVertices because of early return