def test_merge_hulls_4_nodes_with_one_inside(self): h1 = graph.convexHull() h2 = graph.convexHull() nodes1 = [ {'x': 0, 'y': 4}, {'x': 2, 'y': 0} ] nodes2 = [ {'x': 2, 'y': 2}, {'x': 3, 'y': 3} ] h1['0-4'] = [nodes1[1]] h1['2-0'] = [nodes1[0]] h2['2-2'] = [nodes2[1]] h2['3-3'] = [nodes2[0]] (hull, upperTangent, lowerTangent) = graph.convexHull.merge( h1, h2, nodes1[1], nodes2[0] ) expected = graph.convexHull() expected['0-4'] = [nodes1[1], nodes2[1]] expected['2-0'] = [nodes2[1], nodes1[0]] expected['3-3'] = [nodes1[0], nodes1[1]] self.assertEquals(hull, expected) self.assertEquals(upperTangent, [nodes1[1], nodes2[1]]) self.assertEquals(lowerTangent, [nodes1[0], nodes2[1]])
def test_clean_hull_one_node_counter_clockwise(self): h = graph.convexHull() nodes = [ {'x': 0, 'y': 2}, {'x': 1, 'y': 1}, {'x': 3, 'y': 0}, {'x': 4, 'y': 2}, {'x': 3, 'y': 4}, {'x': 2, 'y': 5}, {'x': 0, 'y': 4} ] h['0-2'] = [nodes[1], nodes[6]] h['1-1'] = [nodes[2], nodes[0]] h['3-0'] = [nodes[3], nodes[1]] h['4-2'] = [nodes[4], nodes[2]] h['3-4'] = [nodes[5], nodes[3]] h['2-5'] = [nodes[6], nodes[4]] h['0-4'] = [nodes[0], nodes[5]] h._clean(nodes[4], nodes[3], False) expected = graph.convexHull() expected['0-2'] = [nodes[1], nodes[6]] expected['1-1'] = [nodes[2], nodes[0]] expected['3-0'] = [nodes[3], nodes[1]] expected['4-2'] = [None, nodes[2]] expected['3-4'] = [nodes[5], None] expected['2-5'] = [nodes[6], nodes[4]] expected['0-4'] = [nodes[0], nodes[5]] self.assertEquals(h, expected)
def test_find_lower_tangent_between_hulls(self): h1 = graph.convexHull() h2 = graph.convexHull() nodes1 = [ {'x': 0, 'y': 4}, {'x': 1, 'y': 1}, {'x': 2, 'y': 3} ] h1['0-4'] = [nodes1[1], nodes1[2]] h1['1-1'] = [nodes1[2], nodes1[0]] h1['2-3'] = [nodes1[0], nodes1[1]] nodes2 = [ {'x': 4, 'y': 2}, {'x': 6, 'y': 1}, {'x': 6, 'y': 4} ] h2['4-2'] = [nodes2[1], nodes2[2]] h2['6-1'] = [nodes2[2], nodes2[0]] h2['6-4'] = [nodes2[0], nodes2[1]] upperTangent = graph.convexHull.findTangent( h1, h2, nodes1[2], nodes2[0], isUpperTangent=False ) self.assertEquals(upperTangent, [nodes1[0], nodes2[2]])
def test_clean_line_hull_one_node_counter_clockwise(self): h = graph.convexHull() nodes = [{'x': 0, 'y': 2}, {'x': 1, 'y': 1}] h['0-2'] = [nodes[1]] h['1-1'] = [nodes[0]] h._clean(nodes[1], nodes[1], False) expected = graph.convexHull() expected['1-1'] = [None] expected['0-2'] = [None] self.assertEquals(h, expected)
def test_joinNodesClockwise_join_hulls(self): h = graph.convexHull() nodes = [{ 'x': 0, 'y': 2 }, { 'x': 1, 'y': 1 }, { 'x': 3, 'y': 0 }, { 'x': 4, 'y': 2 }, { 'x': 3, 'y': 4 }, { 'x': 2, 'y': 5 }, { 'x': 0, 'y': 4 }] # 012345 # 0...2.. # 1.1.... # 20...3. # 3...... # 46..4.. # 5..5... # The 2nodes hull is the [0, 6] # [1, 2, 3, 4, 5] is the second hull h['0-2'] = [nodes[1], nodes[6]] h['1-1'] = [None, nodes[0]] h['3-0'] = [nodes[3], None] h['4-2'] = [nodes[4], nodes[2]] h['3-4'] = [nodes[5], nodes[3]] h['2-5'] = [None, nodes[4]] h['0-4'] = [nodes[0], None] h._joinNodesClockwise(nodes[5], nodes[6]) expected = graph.convexHull() expected['0-2'] = [nodes[1], nodes[6]] expected['1-1'] = [None, nodes[0]] expected['3-0'] = [nodes[3], None] expected['4-2'] = [nodes[4], nodes[2]] expected['3-4'] = [nodes[5], nodes[3]] expected['2-5'] = [nodes[6], nodes[4]] expected['0-4'] = [nodes[0], nodes[5]] self.assertEquals(h, expected)
def test_clean_hull_one_node_clockwise(self): h = graph.convexHull() nodes = [{ 'x': 0, 'y': 2 }, { 'x': 1, 'y': 1 }, { 'x': 3, 'y': 0 }, { 'x': 4, 'y': 2 }, { 'x': 3, 'y': 4 }, { 'x': 2, 'y': 5 }, { 'x': 0, 'y': 4 }] # 012345 # 0...2.. # 1.1.... # 20...3. # 3...... # 46..4.. # 5..5... h['0-2'] = [nodes[1], nodes[6]] h['1-1'] = [nodes[2], nodes[0]] h['3-0'] = [nodes[3], nodes[1]] h['4-2'] = [nodes[4], nodes[2]] h['3-4'] = [nodes[5], nodes[3]] h['2-5'] = [nodes[6], nodes[4]] h['0-4'] = [nodes[0], nodes[5]] h._clean(nodes[3], nodes[4], True) expected = graph.convexHull() expected['0-2'] = [nodes[1], nodes[6]] expected['1-1'] = [nodes[2], nodes[0]] expected['3-0'] = [nodes[3], nodes[1]] expected['4-2'] = [None, nodes[2]] expected['3-4'] = [nodes[5], None] expected['2-5'] = [nodes[6], nodes[4]] expected['0-4'] = [nodes[0], nodes[5]] self.assertEquals(h, expected)
def test_clean_line_hull_one_node_counter_clockwise(self): h = graph.convexHull() nodes = [ {'x': 0, 'y': 2}, {'x': 1, 'y': 1} ] h['0-2'] = [nodes[1]] h['1-1'] = [nodes[0]] h._clean(nodes[1], nodes[1], False) expected = graph.convexHull() expected['1-1'] = [None] expected['0-2'] = [None] self.assertEquals(h, expected)
def test_fail_joinNodesClockwise_to_on_full_node(self): h = graph.convexHull() nodes = [{ 'x': 0, 'y': 2 }, { 'x': 1, 'y': 1 }, { 'x': 3, 'y': 0 }, { 'x': 4, 'y': 2 }, { 'x': 3, 'y': 4 }, { 'x': 2, 'y': 5 }, { 'x': 0, 'y': 4 }] h['0-2'] = [nodes[1], nodes[6]] h['1-1'] = [nodes[2], nodes[0]] h['3-0'] = [None, nodes[1]] h['4-2'] = [nodes[4], None] h['3-4'] = [nodes[5], nodes[3]] h['2-5'] = [nodes[6], nodes[4]] h['0-4'] = [nodes[0], nodes[5]] with self.assertRaises(graph.exception): h._joinNodesClockwise(nodes[2], nodes[4])
def test_generate_hull_2_nodes(self): h = graph.convexHull() nodes = [{'x': 0, 'y': 0}, {'x': 0, 'y': 1}] h.generate(nodes[0], nodes[1]) expected = {'0-0': [nodes[1]], '0-1': [nodes[0]]} self.assertEquals(dict(h), expected)
def test_find_lower_tangent_between_hulls(self): h1 = graph.convexHull() h2 = graph.convexHull() nodes1 = [{'x': 0, 'y': 4}, {'x': 1, 'y': 1}, {'x': 2, 'y': 3}] h1['0-4'] = [nodes1[1], nodes1[2]] h1['1-1'] = [nodes1[2], nodes1[0]] h1['2-3'] = [nodes1[0], nodes1[1]] nodes2 = [{'x': 4, 'y': 2}, {'x': 6, 'y': 1}, {'x': 6, 'y': 4}] h2['4-2'] = [nodes2[1], nodes2[2]] h2['6-1'] = [nodes2[2], nodes2[0]] h2['6-4'] = [nodes2[0], nodes2[1]] upperTangent = graph.convexHull.findTangent(h1, h2, nodes1[2], nodes2[0], isUpperTangent=False) self.assertEquals(upperTangent, [nodes1[0], nodes2[2]])
def test_clean_hull_one_node_counter_clockwise(self): h = graph.convexHull() nodes = [{ 'x': 0, 'y': 2 }, { 'x': 1, 'y': 1 }, { 'x': 3, 'y': 0 }, { 'x': 4, 'y': 2 }, { 'x': 3, 'y': 4 }, { 'x': 2, 'y': 5 }, { 'x': 0, 'y': 4 }] h['0-2'] = [nodes[1], nodes[6]] h['1-1'] = [nodes[2], nodes[0]] h['3-0'] = [nodes[3], nodes[1]] h['4-2'] = [nodes[4], nodes[2]] h['3-4'] = [nodes[5], nodes[3]] h['2-5'] = [nodes[6], nodes[4]] h['0-4'] = [nodes[0], nodes[5]] h._clean(nodes[4], nodes[3], False) expected = graph.convexHull() expected['0-2'] = [nodes[1], nodes[6]] expected['1-1'] = [nodes[2], nodes[0]] expected['3-0'] = [nodes[3], nodes[1]] expected['4-2'] = [None, nodes[2]] expected['3-4'] = [nodes[5], None] expected['2-5'] = [nodes[6], nodes[4]] expected['0-4'] = [nodes[0], nodes[5]] self.assertEquals(h, expected)
def test_hull_getNextNode_counter_clockwise(self): h = graph.convexHull() nodes = [{'x': 0, 'y': 4}, {'x': 1, 'y': 1}, {'x': 2, 'y': 3}] h['0-4'] = [nodes[1], nodes[2]] h['1-1'] = [nodes[2], nodes[0]] h['2-3'] = [nodes[0], nodes[1]] self.assertEquals(h.getNextNode(nodes[0], clockwise=False), nodes[2]) self.assertEquals(h.getNextNode(nodes[1], clockwise=False), nodes[0]) self.assertEquals(h.getNextNode(nodes[2], clockwise=False), nodes[1])
def test_merge_hulls_4_nodes_with_one_inside(self): h1 = graph.convexHull() h2 = graph.convexHull() nodes1 = [{'x': 0, 'y': 4}, {'x': 2, 'y': 0}] nodes2 = [{'x': 2, 'y': 2}, {'x': 3, 'y': 3}] h1['0-4'] = [nodes1[1]] h1['2-0'] = [nodes1[0]] h2['2-2'] = [nodes2[1]] h2['3-3'] = [nodes2[0]] (hull, upperTangent, lowerTangent) = graph.convexHull.merge(h1, h2, nodes1[1], nodes2[0]) expected = graph.convexHull() expected['0-4'] = [nodes1[1], nodes2[1]] expected['2-0'] = [nodes2[1], nodes1[0]] expected['3-3'] = [nodes1[0], nodes1[1]] self.assertEquals(hull, expected) self.assertEquals(upperTangent, [nodes1[1], nodes2[1]]) self.assertEquals(lowerTangent, [nodes1[0], nodes2[1]])
def test_generate_hull_3_nodes_counter_clockwise(self): h = graph.convexHull() nodes = [{'x': 0, 'y': 1}, {'x': 1, 'y': 0}, {'x': 0, 'y': 0}] h.generate(nodes[0], nodes[1], nodes[2]) expected = { '0-0': [nodes[1], nodes[0]], '0-1': [nodes[2], nodes[1]], '1-0': [nodes[0], nodes[2]] } self.assertEquals(dict(h), expected)
def test_joinNodesClockwise_join_hulls(self): h = graph.convexHull() nodes = [ {'x': 0, 'y': 2}, {'x': 1, 'y': 1}, {'x': 3, 'y': 0}, {'x': 4, 'y': 2}, {'x': 3, 'y': 4}, {'x': 2, 'y': 5}, {'x': 0, 'y': 4} ] # 012345 # 0...2.. # 1.1.... # 20...3. # 3...... # 46..4.. # 5..5... # The 2nodes hull is the [0, 6] # [1, 2, 3, 4, 5] is the second hull h['0-2'] = [nodes[1], nodes[6]] h['1-1'] = [None, nodes[0]] h['3-0'] = [nodes[3], None] h['4-2'] = [nodes[4], nodes[2]] h['3-4'] = [nodes[5], nodes[3]] h['2-5'] = [None, nodes[4]] h['0-4'] = [nodes[0], None] h._joinNodesClockwise(nodes[5], nodes[6]) expected = graph.convexHull() expected['0-2'] = [nodes[1], nodes[6]] expected['1-1'] = [None, nodes[0]] expected['3-0'] = [nodes[3], None] expected['4-2'] = [nodes[4], nodes[2]] expected['3-4'] = [nodes[5], nodes[3]] expected['2-5'] = [nodes[6], nodes[4]] expected['0-4'] = [nodes[0], nodes[5]] self.assertEquals(h, expected)
def test_hull_is_tangent(self): h = graph.convexHull() nodes = [ {'x': 0, 'y': 4}, {'x': 1, 'y': 1}, {'x': 2, 'y': 3} ] h['0-4'] = [nodes[1], nodes[2]] h['1-1'] = [nodes[2], nodes[0]] h['2-3'] = [nodes[0], nodes[1]] edge1 = [{'x': 2, 'y': 3}, {'x': 4, 'y': 0}] # 1 == tangent and hull at the left of the edge self.assertEquals(h.isTangent(edge1), 1) edge1 = [{'x': 0, 'y': 2}, {'x': 1, 'y': 1}] # -1 == tangent and hull at the right of the edge self.assertEquals(h.isTangent(edge1), -1) edge1 = [{'x': 1, 'y': 4}, {'x': 7, 'y': 2}] # None == none of the nodes of the edge belong to the hull self.assertEquals(h.isTangent(edge1), None) edge1 = [{'x': 1, 'y': 1}, {'x': 1, 'y': 4}] # 0 == not tangent self.assertEquals(h.isTangent(edge1), 0) edge1 = [nodes[1], nodes[2]] # -1 == hull at the right of the edge, edge cotangent with a side of the hull self.assertEquals(h.isTangent(edge1), -1) edge1 = [{'x': 0, 'y': -1}, nodes[2]] # -1 == hull at the right of the edge, edge cotangent with a side of the hull self.assertEquals(h.isTangent(edge1), -1) edge1 = [nodes[1], {'x': 3, 'y': 5}] # -1 == hull at the right of the edge, edge cotangent with a side of the hull self.assertEquals(h.isTangent(edge1), -1) edge1 = [nodes[0], nodes[2]] # -1 == hull at the right of the edge, edge cotangent with a side of the hull self.assertEquals(h.isTangent(edge1), 1) edge1 = [{'x': -2, 'y': 5}, nodes[2]] # -1 == hull at the right of the edge, edge cotangent with a side of the hull self.assertEquals(h.isTangent(edge1), 1) edge1 = [nodes[0], {'x': 2, 'y': 4}] # -1 == hull at the right of the edge, edge cotangent with a side of the hull self.assertEquals(h.isTangent(edge1), 1)
def test_generate_hull_2_nodes(self): h = graph.convexHull() nodes = [ {'x': 0, 'y': 0}, {'x': 0, 'y': 1} ] h.generate(nodes[0], nodes[1]) expected = { '0-0': [nodes[1]], '0-1': [nodes[0]] } self.assertEquals(dict(h), expected)
def test_hull_isUpperTangent(self): h = graph.convexHull() nodes = [{'x': 0, 'y': 4}, {'x': 1, 'y': 1}, {'x': 2, 'y': 3}] h['0-4'] = [nodes[1], nodes[2]] h['1-1'] = [nodes[2], nodes[0]] h['2-3'] = [nodes[0], nodes[1]] edge1 = [{'x': 0, 'y': 2}, {'x': 1, 'y': 1}] # -1 == tangent and hull at the right of the edge self.assertEquals(h.isUpperTangent(edge1), True) edge1 = [{'x': 2, 'y': 3}, {'x': 4, 'y': 0}] # 1 == tangent and hull at the left of the edge self.assertEquals(h.isUpperTangent(edge1), False)
def test_clean_hull_one_node_clockwise(self): h = graph.convexHull() nodes = [ {'x': 0, 'y': 2}, {'x': 1, 'y': 1}, {'x': 3, 'y': 0}, {'x': 4, 'y': 2}, {'x': 3, 'y': 4}, {'x': 2, 'y': 5}, {'x': 0, 'y': 4} ] # 012345 # 0...2.. # 1.1.... # 20...3. # 3...... # 46..4.. # 5..5... h['0-2'] = [nodes[1], nodes[6]] h['1-1'] = [nodes[2], nodes[0]] h['3-0'] = [nodes[3], nodes[1]] h['4-2'] = [nodes[4], nodes[2]] h['3-4'] = [nodes[5], nodes[3]] h['2-5'] = [nodes[6], nodes[4]] h['0-4'] = [nodes[0], nodes[5]] h._clean(nodes[3], nodes[4], True) expected = graph.convexHull() expected['0-2'] = [nodes[1], nodes[6]] expected['1-1'] = [nodes[2], nodes[0]] expected['3-0'] = [nodes[3], nodes[1]] expected['4-2'] = [None, nodes[2]] expected['3-4'] = [nodes[5], None] expected['2-5'] = [nodes[6], nodes[4]] expected['0-4'] = [nodes[0], nodes[5]] self.assertEquals(h, expected)
def test_generate_hull_3_nodes_counter_clockwise(self): h = graph.convexHull() nodes = [ {'x': 0, 'y': 1}, {'x': 1, 'y': 0}, {'x': 0, 'y': 0} ] h.generate(nodes[0], nodes[1], nodes[2]) expected = { '0-0': [nodes[1], nodes[0]], '0-1': [nodes[2], nodes[1]], '1-0': [nodes[0], nodes[2]] } self.assertEquals(dict(h), expected)
def test_hull_is_tangent(self): h = graph.convexHull() nodes = [{'x': 0, 'y': 4}, {'x': 1, 'y': 1}, {'x': 2, 'y': 3}] h['0-4'] = [nodes[1], nodes[2]] h['1-1'] = [nodes[2], nodes[0]] h['2-3'] = [nodes[0], nodes[1]] edge1 = [{'x': 2, 'y': 3}, {'x': 4, 'y': 0}] # 1 == tangent and hull at the left of the edge self.assertEquals(h.isTangent(edge1), 1) edge1 = [{'x': 0, 'y': 2}, {'x': 1, 'y': 1}] # -1 == tangent and hull at the right of the edge self.assertEquals(h.isTangent(edge1), -1) edge1 = [{'x': 1, 'y': 4}, {'x': 7, 'y': 2}] # None == none of the nodes of the edge belong to the hull self.assertEquals(h.isTangent(edge1), None) edge1 = [{'x': 1, 'y': 1}, {'x': 1, 'y': 4}] # 0 == not tangent self.assertEquals(h.isTangent(edge1), 0) edge1 = [nodes[1], nodes[2]] # -1 == hull at the right of the edge, edge cotangent with a side of the hull self.assertEquals(h.isTangent(edge1), -1) edge1 = [{'x': 0, 'y': -1}, nodes[2]] # -1 == hull at the right of the edge, edge cotangent with a side of the hull self.assertEquals(h.isTangent(edge1), -1) edge1 = [nodes[1], {'x': 3, 'y': 5}] # -1 == hull at the right of the edge, edge cotangent with a side of the hull self.assertEquals(h.isTangent(edge1), -1) edge1 = [nodes[0], nodes[2]] # -1 == hull at the right of the edge, edge cotangent with a side of the hull self.assertEquals(h.isTangent(edge1), 1) edge1 = [{'x': -2, 'y': 5}, nodes[2]] # -1 == hull at the right of the edge, edge cotangent with a side of the hull self.assertEquals(h.isTangent(edge1), 1) edge1 = [nodes[0], {'x': 2, 'y': 4}] # -1 == hull at the right of the edge, edge cotangent with a side of the hull self.assertEquals(h.isTangent(edge1), 1)
def test_hull_isUpperTangent(self): h = graph.convexHull() nodes = [ {'x': 0, 'y': 4}, {'x': 1, 'y': 1}, {'x': 2, 'y': 3} ] h['0-4'] = [nodes[1], nodes[2]] h['1-1'] = [nodes[2], nodes[0]] h['2-3'] = [nodes[0], nodes[1]] edge1 = [{'x': 0, 'y': 2}, {'x': 1, 'y': 1}] # -1 == tangent and hull at the right of the edge self.assertEquals(h.isUpperTangent(edge1), True) edge1 = [{'x': 2, 'y': 3}, {'x': 4, 'y': 0}] # 1 == tangent and hull at the left of the edge self.assertEquals(h.isUpperTangent(edge1), False)
def test_flat_hull_is_tangent(self): h = graph.convexHull() nodes = [ {'x': 0, 'y': 4}, {'x': 1, 'y': 1} ] h['0-4'] = [nodes[1]] h['1-1'] = [nodes[0]] edge1 = [nodes[0], nodes[1]] # 1 == tangent and hull parallel of the edge self.assertEquals(h.isTangent(edge1), 1) edge1 = [{'x': -1, 'y': 7}, nodes[0]] # 1 == tangent and hull parallel of the edge self.assertEquals(h.isTangent(edge1), 1) edge1 = [nodes[1], {'x': 2, 'y': -2}] # 1 == tangent and hull parallel of the edge self.assertEquals(h.isTangent(edge1), 1) edge1 = [nodes[0], {'x': 2, 'y': 3}] # 1 == tangent and hull at the left of the edge self.assertEquals(h.isTangent(edge1), 1) edge1 = [nodes[1], {'x': 1, 'y': 0}] # 1 == tangent and hull at the left of the edge self.assertEquals(h.isTangent(edge1), 1) edge1 = [{'x': 1, 'y': 3}, nodes[1]] # 1 == tangent and hull at the left of the edge self.assertEquals(h.isTangent(edge1), 1) edge1 = [nodes[1], {'x': 3, 'y': 2}] # -1 == tangent and hull at the right of the edge self.assertEquals(h.isTangent(edge1), -1) edge1 = [nodes[0], {'x': 0, 'y': 0}] # -1 == tangent and hull at the right of the edge self.assertEquals(h.isTangent(edge1), -1)
def test_fail_joinNodesClockwise_to_on_full_node(self): h = graph.convexHull() nodes = [ {'x': 0, 'y': 2}, {'x': 1, 'y': 1}, {'x': 3, 'y': 0}, {'x': 4, 'y': 2}, {'x': 3, 'y': 4}, {'x': 2, 'y': 5}, {'x': 0, 'y': 4} ] h['0-2'] = [nodes[1], nodes[6]] h['1-1'] = [nodes[2], nodes[0]] h['3-0'] = [None, nodes[1]] h['4-2'] = [nodes[4], None] h['3-4'] = [nodes[5], nodes[3]] h['2-5'] = [nodes[6], nodes[4]] h['0-4'] = [nodes[0], nodes[5]] with self.assertRaises(graph.exception): h._joinNodesClockwise(nodes[2], nodes[4])
def test_flat_hull_is_tangent(self): h = graph.convexHull() nodes = [{'x': 0, 'y': 4}, {'x': 1, 'y': 1}] h['0-4'] = [nodes[1]] h['1-1'] = [nodes[0]] edge1 = [nodes[0], nodes[1]] # 1 == tangent and hull parallel of the edge self.assertEquals(h.isTangent(edge1), 1) edge1 = [{'x': -1, 'y': 7}, nodes[0]] # 1 == tangent and hull parallel of the edge self.assertEquals(h.isTangent(edge1), 1) edge1 = [nodes[1], {'x': 2, 'y': -2}] # 1 == tangent and hull parallel of the edge self.assertEquals(h.isTangent(edge1), 1) edge1 = [nodes[0], {'x': 2, 'y': 3}] # 1 == tangent and hull at the left of the edge self.assertEquals(h.isTangent(edge1), 1) edge1 = [nodes[1], {'x': 1, 'y': 0}] # 1 == tangent and hull at the left of the edge self.assertEquals(h.isTangent(edge1), 1) edge1 = [{'x': 1, 'y': 3}, nodes[1]] # 1 == tangent and hull at the left of the edge self.assertEquals(h.isTangent(edge1), 1) edge1 = [nodes[1], {'x': 3, 'y': 2}] # -1 == tangent and hull at the right of the edge self.assertEquals(h.isTangent(edge1), -1) edge1 = [nodes[0], {'x': 0, 'y': 0}] # -1 == tangent and hull at the right of the edge self.assertEquals(h.isTangent(edge1), -1)
def test_hull_getNextNode_counter_clockwise(self): h = graph.convexHull() nodes = [ {'x': 0, 'y': 4}, {'x': 1, 'y': 1}, {'x': 2, 'y': 3} ] h['0-4'] = [nodes[1], nodes[2]] h['1-1'] = [nodes[2], nodes[0]] h['2-3'] = [nodes[0], nodes[1]] self.assertEquals( h.getNextNode(nodes[0], clockwise=False), nodes[2] ) self.assertEquals( h.getNextNode(nodes[1], clockwise=False), nodes[0] ) self.assertEquals( h.getNextNode(nodes[2], clockwise=False), nodes[1] )