Sign in to follow this  

std::set and Point3

This topic is 4841 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I have a polygon class where I like to insert points on the fly using an add function. I might happen that my calculations create a point that already exists and therefore should not be inserted again. My idea was to use a std::set since it seems the right tool for in this case. How do I define a comparison for a Point3 class such that equal points are rejected? Ordering is not important so can I pass std::equal_to in the constructor? Maybe I need a "fuzzy" compare later where the points are nearly equal - how would I implement this and what is a good "epsilon" value here? A short code example for illustrations:
class Point3
{
    float x, y, z;
}

class Polygon
{
public:
    void Add( const Point3& p ) 
    { 
        m_VtxCoords.insert( p ); 
        // This should fail if "p" was already inserted before!
    }

private:
    std::set<Point3, Comparison > m_VtxCoords;
}

class comparison
{
    // What goes here?
}

Best regards,

Dirk


Share this post


Link to post
Share on other sites
It depends on what you define as "equal points". It varies from application to application. Depending on how often you add points to the set, you could use a squared distance (no need to bother with the root), where if two points are closer than a certain epsilon, they're considered the same point. That's personally what I'd do, or you could use a rough taxi approximation (which is basically the sum of all the component deltas). As for a good epsilon value, I can't tell you what would be good. 0.001 or 0.0001 could both be winners.

Share this post


Link to post
Share on other sites

This topic is 4841 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this