Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make arc merge commutative #244

Open
jazminlaila opened this issue May 2, 2017 · 0 comments
Open

Make arc merge commutative #244

jazminlaila opened this issue May 2, 2017 · 0 comments

Comments

@jazminlaila
Copy link
Contributor

can_be_merged_with's implementation could be replaced by:

def can_be_merged_with(self, other):
        if self.__class__ is other.__class__ and \
           self.center_point().almost_equal_to(other.center_point(), 5) and \
           self.radius() == other.radius():
            return (self.end_heading() == other.start_heading() and
                    self.end_point().almost_equal_to(other.start_point(), 5)) or \
                (other.end_heading() == self.start_heading() and
                    other.end_point().almost_equal_to(self.start_point(), 5))

In that case, merge's implementation should be changed to merge in one order or the other depending on which order they can be appended one to the other.

Here are some tests:

def test_can_be_merged_with(self):
        arc1 = Arc(Point(1, 0), 90, 1, 90)
        arc2 = Arc(Point(0, 1), 180, 1, 90)
        arc3 = Arc(Point(0, 1), 0, 1, -90)
        arc4 = Arc(Point(-1, 0), 270, 1, 90)
        self.assertTrue(arc1.can_be_merged_with(arc2))
        self.assertTrue(arc2.can_be_merged_with(arc1))
        self.assertFalse(arc1.can_be_merged_with(arc3))
        self.assertFalse(arc1.can_be_merged_with(arc4))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants