def test_vector_generate2(): pt1 = (0, 0, 0) pt2 = (5, 3, 4) result = (5, 3, 4) result_normalized = (0.707107, 0.424264, 0.565685) to_check = linalg.vector_generate(pt1, pt2) to_check_normalized = linalg.vector_generate(pt1, pt2, normalize=True) assert abs(to_check[0] - result[0]) <= GEOMDL_DELTA assert abs(to_check[1] - result[1]) <= GEOMDL_DELTA assert abs(to_check[2] - result[2]) <= GEOMDL_DELTA assert abs(to_check_normalized[0] - result_normalized[0]) <= GEOMDL_DELTA assert abs(to_check_normalized[1] - result_normalized[1]) <= GEOMDL_DELTA assert abs(to_check_normalized[2] - result_normalized[2]) <= GEOMDL_DELTA
def make_quadtree(points, size_u, size_v, **kwargs): """ Generates a quadtree-like structure from surface control points. This function generates a 2-dimensional list of control point coordinates. Considering the object-oriented representation of a quadtree data structure, first dimension of the generated list corresponds to a list of *QuadTree* classes. Second dimension of the generated list corresponds to a *QuadTree* data structure. The first element of the 2nd dimension is the mid-point of the bounding box and the remaining elements are corner points of the bounding box organized in counter-clockwise order. To maintain stability for the data structure on the edges and corners, the function accepts ``extrapolate`` keyword argument. If it is *True*, then the function extrapolates the surface on the corners and edges to complete the quad-like structure for each control point. If it is *False*, no extrapolation will be applied. By default, ``extrapolate`` is set to *True*. Please note that this function's intention is not generating a real quadtree structure but reorganizing the control points in a very similar fashion to make them available for various geometric operations. :param points: 1-dimensional array of surface control points :type points: list, tuple :param size_u: number of control points on the u-direction :type size_u: int :param size_v: number of control points on the v-direction :type size_v: int :return: control points organized in a quadtree-like structure :rtype: tuple """ # Get keyword arguments extrapolate = kwargs.get('extrapolate', True) # Convert control points array into 2-dimensional form points2d = [] for i in range(0, size_u): row_list = [] for j in range(0, size_v): row_list.append(points[j + (i * size_v)]) points2d.append(row_list) # Traverse 2-dimensional control points to find neighbors qtree = [] for u in range(size_u): for v in range(size_v): temp = [points2d[u][v]] # Note: negative indexing actually works in Python, so we need explicit checking if u + 1 < size_u: temp.append(points2d[u + 1][v]) else: if extrapolate: extrapolated_edge = linalg.vector_generate( points2d[u - 1][v], points2d[u][v]) translated_point = linalg.point_translate( points2d[u][v], extrapolated_edge) temp.append(translated_point) if v + 1 < size_v: temp.append(points2d[u][v + 1]) else: if extrapolate: extrapolated_edge = linalg.vector_generate( points2d[u][v - 1], points2d[u][v]) translated_point = linalg.point_translate( points2d[u][v], extrapolated_edge) temp.append(translated_point) if u - 1 >= 0: temp.append(points2d[u - 1][v]) else: if extrapolate: extrapolated_edge = linalg.vector_generate( points2d[u + 1][v], points2d[u][v]) translated_point = linalg.point_translate( points2d[u][v], extrapolated_edge) temp.append(translated_point) if v - 1 >= 0: temp.append(points2d[u][v - 1]) else: if extrapolate: extrapolated_edge = linalg.vector_generate( points2d[u][v + 1], points2d[u][v]) translated_point = linalg.point_translate( points2d[u][v], extrapolated_edge) temp.append(translated_point) qtree.append(tuple(temp)) # Return generated quad-tree return tuple(qtree)
def test_vector_generate3(): with pytest.raises(TypeError): linalg.vector_generate(5, 9.7)
def test_vector_generate1(): with pytest.raises(ValueError): pt1 = () pt2 = (1, 2, 3) linalg.vector_generate(pt1, pt2)
def make_quadtree(points, size_u, size_v, **kwargs): """ Generates a quadtree-like structure from surface control points. This function generates a 2-dimensional list of control point coordinates. Considering the object-oriented representation of a quadtree data structure, first dimension of the generated list corresponds to a list of *QuadTree* classes. Second dimension of the generated list corresponds to a *QuadTree* data structure. The first element of the 2nd dimension is the mid-point of the bounding box and the remaining elements are corner points of the bounding box organized in counter-clockwise order. To maintain stability for the data structure on the edges and corners, the function accepts ``extrapolate`` keyword argument. If it is *True*, then the function extrapolates the surface on the corners and edges to complete the quad-like structure for each control point. If it is *False*, no extrapolation will be applied. By default, ``extrapolate`` is set to *True*. Please note that this function's intention is not generating a real quadtree structure but reorganizing the control points in a very similar fashion to make them available for various geometric operations. :param points: 1-dimensional array of surface control points :type points: list, tuple :param size_u: number of control points on the u-direction :type size_u: int :param size_v: number of control points on the v-direction :type size_v: int :return: control points organized in a quadtree-like structure :rtype: tuple """ # Get keyword arguments extrapolate = kwargs.get('extrapolate', True) # Convert control points array into 2-dimensional form points2d = [] for i in range(0, size_u): row_list = [] for j in range(0, size_v): row_list.append(points[j + (i * size_v)]) points2d.append(row_list) # Traverse 2-dimensional control points to find neighbors qtree = [] for u in range(size_u): for v in range(size_v): temp = [points2d[u][v]] # Note: negative indexing actually works in Python, so we need explicit checking if u + 1 < size_u: temp.append(points2d[u+1][v]) else: if extrapolate: extrapolated_edge = linalg.vector_generate(points2d[u - 1][v], points2d[u][v]) translated_point = linalg.point_translate(points2d[u][v], extrapolated_edge) temp.append(translated_point) if v + 1 < size_v: temp.append(points2d[u][v+1]) else: if extrapolate: extrapolated_edge = linalg.vector_generate(points2d[u][v - 1], points2d[u][v]) translated_point = linalg.point_translate(points2d[u][v], extrapolated_edge) temp.append(translated_point) if u - 1 >= 0: temp.append(points2d[u-1][v]) else: if extrapolate: extrapolated_edge = linalg.vector_generate(points2d[u + 1][v], points2d[u][v]) translated_point = linalg.point_translate(points2d[u][v], extrapolated_edge) temp.append(translated_point) if v - 1 >= 0: temp.append(points2d[u][v-1]) else: if extrapolate: extrapolated_edge = linalg.vector_generate(points2d[u][v + 1], points2d[u][v]) translated_point = linalg.point_translate(points2d[u][v], extrapolated_edge) temp.append(translated_point) qtree.append(tuple(temp)) # Return generated quad-tree return tuple(qtree)