Issue #3 new

Comparing the same line for equality returns False.

Panagiotis Mavrogiorgos avatarPanagiotis Mavrogiorgos created an issue

I know that planar is not maintained anymore, but I thought I would mention the following, in case someone decides to use it.

When you define the same line using opposite direction vectors the comparison returns False. For example line y=x:

In [1]: from planar.py import Line

In [2]: l1 = Line((0, 0), (1, 1))

In [3]: l2 = Line((0, 0), (-1, -1))

In [4]: l1.almost_equals(l2)
Out[4]: False

In [5]: l1 == l2
Out[5]: False

Something like this could fix it

    def almost_equals(self, other):
        """ Return True if this line is approximately equal to another line, within precision limits."""
        return (self.__class__ is other.__class__ and
                abs(self.offset - other.offset) < planar.EPSILON and
                (self.direction.almost_equals(other.direction) or
                 self.direction.almost_equals(-other.direction)))

Comments (1)

  1. Casey Duncan

    I think that use case is valid, but I think it may require an additional method that specifically ignores the direction of the line. Reason being that lines divide the plane into two half planes, and the direction of the line is used to discriminate between the "left" and "right" half planes. Some operations, such as determining which side of a line a point falls on will differ for lines in different directions. Also the direction and normal vectors will be inverted, of course. Those differences may be important in some applications.

    Perhaps the right answer is to add an "is_congruent" api or somesuch to compare shapes in such a way that directional considerations are ignored. Of course polygons already play fast and loose in this regard with equals, though.

  2. Log in to comment
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.