Skip to content

compare_positions could take an optional epsilon parameter #5

@timbunce

Description

@timbunce

compare_positions could take an optional epsilon parameter to avoid problems that naturally occur when trying to compare floating point values.

In other words, simply replace

( $pos1->[$dim] != $pos2->[$dim] )

with

( abs($pos1->[$dim] - $pos2->[$dim]) > $epsilon * $pos1->[$dim] )

If $epsilon defaults to 0 then you'd have the same behaviour as now, but that's a little buggy. A better default would be 2.22044604925031e-16. I grabbed that as a typical epsilon value from here.

As an extra optional parameter users could pass in larger values to compare polygons to see if they're 'near enough' the same, e.g., after round-tripping through storage that might use single precision floating point values, or conversion to numeric strings with a limited number of decimal places.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions