Logic/Code duplication, improve readability? I have a function that takes a point, and given its velocity, and acceleration, calculates the time(s) for the point to collide with the line:

def ParabolaLineCollision(pos, vel, acc, line):
    """A pure function that returns all intersections."""
    pass


I have another function that wants to calculate the smallest intersection time between two entities, where an entity has a velocity/acceleration, and a list of vertices.

The algorithm of entity_intersection creates lines for each objects' list of vertices, and then calls ParabolaLineCollision on each point of each object, with each line of the other object.  My current algorithm runs slowly, and thus I would like to be able to parallelize the algorithm.

My problem is that entity_intersections is a bit hard to read, and I think that there may be some code duplication, which might possibly be eliminated.  Here's the algorithm, and 

class Entity
    # ...

    @property
    def lines(self):
        """
        Get a list of lines that connect self.points.

        If self.enclosed, then the last point will connect the first point.
        """
        # type(self.enclosed) == bool

        # # I included this, as this may be where there is logic duplication with entity_intersections.
        # # It's also not very readable.

        return [(self.points[i-1], self.points[i]) for i in range((1-int(self.enclosed)), len(self.points))]

    # ...

def entity_intersections(entity, other):
    """
    Find all intersection times between two entities.

    type(entity) == type(other) == Entity
    """
    # Find relative velocity/acceleration
    a12 = entity.acceleration - other.acceleration
    a21 = other.acceleration - entity.acceleration
    v12 = entity.velocity - other.velocity
    v21 = other.velocity - entity.velocity

    entity_points, other_points = entity.points, other.points
    entity_lines, other_lines = entity.lines, other.lines

    results = []

    # Get all intersections between each object's point and the other object's line
    for point in entity_points:
        for line in other_lines:
            results.append((point, v12, a12, line))
    for point in other_points:
        for line in entity_lines:
            results.append((point, v21, a21, line))

    # Return results of ParabolaLineCollision with each list of arguments in results
    # Pseudo-code to achieve this (I haven't done the parallizing yet):
    # return min(map(ParabolaLineCollision, results))
Not a lot of changes, but maybe a bit more legible. 

a12 = entity.acceleration - other.acceleration
a21 = -a12
v12 = entity.velocity - other.velocity
v21 = -v12

result  = [ (p, v12, a12, l) for l in other.lines for p in entity.points ] +
          [ (p, v21, a21, l) for l in entity.lines for p in other.points ]


Obviously you could inline the v21 and a21 variables, but it's actually somewhat descriptive of what they represent to use those names.