Comparing the same line for equality returns False.

Issue #3 new
panos 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 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

Comments (1)

  1. Casey Duncan repo owner

    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