code
string
signature
string
docstring
string
loss_without_docstring
float64
loss_with_docstring
float64
factor
float64
'''Transform image data to latent space. Parameters ---------- data : array-like shape (n_images, image_width, image_height, n_colors) Input numpy array of images. test [optional] : bool Controls the test boolean for bat...
def transform(self, data, test=False)
Transform image data to latent space. Parameters ---------- data : array-like shape (n_images, image_width, image_height, n_colors) Input numpy array of images. test [optional] : bool Controls the test boolean for batch normaliz...
2.383936
1.878823
1.268845
'''Loads in model as a class instance with with the specified model and optimizer states. Parameters ---------- enc : str Path to the encoder state file. dec : str Path to the decoder/generator state file. disc : str Path to...
def load(cls, enc, dec, disc, enc_opt, dec_opt, disc_opt, meta, flag_gpu=None)
Loads in model as a class instance with with the specified model and optimizer states. Parameters ---------- enc : str Path to the encoder state file. dec : str Path to the decoder/generator state file. disc : str Path to the discri...
1.778296
1.375379
1.29295
r # The indices where the corner nodes in a surface are. corner_indices = (0, degree, -1) sub_polys = [poly_surface] signs = set() for _ in six.moves.xrange(_MAX_POLY_SUBDIVISIONS): undecided = [] for poly in sub_polys: # First add all the signs of the corner nodes. ...
def polynomial_sign(poly_surface, degree)
r"""Determine the "sign" of a polynomial on the reference triangle. .. note:: This is used **only** by :meth:`Surface._compute_valid` (which is in turn used to compute / cache the :attr:`Surface.is_valid` property). Checks if a polynomial :math:`p(s, t)` is positive, negative or mixe...
4.595675
4.16776
1.102673
r # First evaluate the Jacobian at each of the 6 nodes. jac_parts = _helpers.matrix_product(nodes, _QUADRATIC_JACOBIAN_HELPER) jac_at_nodes = np.empty((1, 6), order="F") jac_at_nodes[0, 0] = two_by_two_det(jac_parts[:, :2]) jac_at_nodes[0, 1] = two_by_two_det(jac_parts[:, 2:4]) jac_at_nodes[...
def quadratic_jacobian_polynomial(nodes)
r"""Compute the Jacobian determinant of a quadratic surface. .. note:: This is used **only** by :meth:`Surface._compute_valid` (which is in turn used to compute / cache the :attr:`Surface.is_valid` property). Converts :math:`\det(J(s, t))` to a polynomial on the reference triangle an...
2.418468
2.205463
1.096581
r # First evaluate the Jacobian at each of the 15 nodes # in the quartic triangle. jac_parts = _helpers.matrix_product(nodes, _CUBIC_JACOBIAN_HELPER) jac_at_nodes = np.empty((1, 15), order="F") jac_at_nodes[0, 0] = two_by_two_det(jac_parts[:, :2]) jac_at_nodes[0, 1] = two_by_two_det(jac_part...
def cubic_jacobian_polynomial(nodes)
r"""Compute the Jacobian determinant of a cubic surface. .. note:: This is used **only** by :meth:`Surface._compute_valid` (which is in turn used to compute / cache the :attr:`Surface.is_valid` property). Converts :math:`\det(J(s, t))` to a polynomial on the reference triangle and re...
1.644831
1.564228
1.051529
r dimension, num_nodes = nodes.shape num_new_nodes = num_nodes - degree - 1 new_nodes = np.empty((dimension, num_new_nodes), order="F") index = 0 # parent_i1 = index + k # parent_i2 = index + k + 1 # parent_i3 = index + degree + 1 parent_i1 = 0 parent_i2 = 1 parent_i3 = degre...
def _de_casteljau_one_round(nodes, degree, lambda1, lambda2, lambda3)
r"""Performs one "round" of the de Casteljau algorithm for surfaces. .. note:: There is also a Fortran implementation of this function, which will be used if it can be built. .. note:: This is a helper function, used by :func:`make_transform` and :func:`_specialize_surface` (and ...
2.690704
2.680858
1.003673
num_nodes = ((degree + 1) * (degree + 2)) // 2 id_mat = np.eye(num_nodes, order="F") # Pre-compute the matrices that do the reduction so we don't # have to **actually** perform the de Casteljau algorithm # every time. transform = { 0: de_casteljau_one_round(id_mat, degree, *weights_...
def make_transform(degree, weights_a, weights_b, weights_c)
Compute matrices corresponding to the de Casteljau algorithm. .. note:: This is a helper used only by :func:`_specialize_surface`. Applies the de Casteljau to the identity matrix, thus effectively caching the algorithm in a transformation matrix. .. note:: This is premature optimizati...
3.512221
3.319868
1.05794
r result = np.empty(shape, order="F") index = 0 for k in six.moves.xrange(degree + 1): for j in six.moves.xrange(degree + 1 - k): i = degree - j - k key = (0,) * i + (1,) * j + (2,) * k result[:, index] = vals_by_weight[key][:, 0] index += 1 re...
def reduced_to_matrix(shape, degree, vals_by_weight)
r"""Converts a reduced values dictionary into a matrix. .. note:: This is a helper used only by :func:`_specialize_surface`. The ``vals_by_weight`` mapping has keys of the form: ``(0, ..., 1, ..., 2, ...)`` where the ``0`` corresponds to the number of times the first set of barycentric wei...
3.023195
3.033837
0.996492
# Uses A-->0, B-->1, C-->2 to represent the specialization used. partial_vals = { (0,): de_casteljau_one_round(nodes, degree, *weights_a), (1,): de_casteljau_one_round(nodes, degree, *weights_b), (2,): de_casteljau_one_round(nodes, degree, *weights_c), } for reduced_deg in s...
def _specialize_surface(nodes, degree, weights_a, weights_b, weights_c)
Specialize a surface to a reparameterization .. note:: There is also a Fortran implementation of this function, which will be used if it can be built. Does so by taking three points (in barycentric form) within the reference triangle and then reparameterizing the surface onto the triang...
4.036499
4.308245
0.936924
if degree == 1: nodes_a = _helpers.matrix_product(nodes, LINEAR_SUBDIVIDE_A) nodes_b = _helpers.matrix_product(nodes, LINEAR_SUBDIVIDE_B) nodes_c = _helpers.matrix_product(nodes, LINEAR_SUBDIVIDE_C) nodes_d = _helpers.matrix_product(nodes, LINEAR_SUBDIVIDE_D) elif degree == ...
def _subdivide_nodes(nodes, degree)
Subdivide a surface into four sub-surfaces. .. note:: There is also a Fortran implementation of this function, which will be used if it can be built. Does so by taking the unit triangle (i.e. the domain of the surface) and splitting it into four sub-triangles by connecting the midpoints of ...
1.344967
1.327699
1.013006
r num_nodes = (degree * (degree + 1)) // 2 result = np.empty((dimension, num_nodes), order="F") index = 0 i = 0 for num_vals in six.moves.xrange(degree, 0, -1): for _ in six.moves.xrange(num_vals): result[:, index] = nodes[:, i + 1] - nodes[:, i] # Update the indi...
def jacobian_s(nodes, degree, dimension)
r"""Compute :math:`\frac{\partial B}{\partial s}`. .. note:: This is a helper for :func:`_jacobian_both`, which has an equivalent Fortran implementation. Args: nodes (numpy.ndarray): Array of nodes in a surface. degree (int): The degree of the surface. dimension (int): T...
4.466238
4.760866
0.938115
r _, num_nodes = nodes.shape result = np.empty((2 * dimension, num_nodes - degree - 1), order="F") result[:dimension, :] = jacobian_s(nodes, degree, dimension) result[dimension:, :] = jacobian_t(nodes, degree, dimension) return result
def _jacobian_both(nodes, degree, dimension)
r"""Compute :math:`s` and :math:`t` partial of :math:`B`. .. note:: There is also a Fortran implementation of this function, which will be used if it can be built. Args: nodes (numpy.ndarray): Array of nodes in a surface. degree (int): The degree of the surface. dimensio...
3.551148
3.605769
0.984852
r jac_nodes = jacobian_both(nodes, degree, 2) if degree == 1: num_vals, _ = st_vals.shape bs_bt_vals = np.repeat(jac_nodes, num_vals, axis=1) else: bs_bt_vals = evaluate_cartesian_multi( jac_nodes, degree - 1, st_vals, 4 ) # Take the determinant for each (...
def _jacobian_det(nodes, degree, st_vals)
r"""Compute :math:`\det(D B)` at a set of values. This requires that :math:`B \in \mathbf{R}^2`. .. note:: This assumes but does not check that each ``(s, t)`` in ``st_vals`` is inside the reference triangle. .. warning:: This relies on helpers in :mod:`bezier` for computing the ...
4.15946
4.374942
0.950746
# Each array is 2 x 1 (i.e. a column vector), we want the vector # dot product. dot_prod = np.vdot(tangent1[:, 0], tangent2[:, 0]) # NOTE: When computing curvatures we assume that we don't have lines # here, because lines that are tangent at an intersection are # parallel and we...
def classify_tangent_intersection( intersection, nodes1, tangent1, nodes2, tangent2 )
Helper for func:`classify_intersection` at tangencies. .. note:: This is a helper used only by :func:`classify_intersection`. Args: intersection (.Intersection): An intersection object. nodes1 (numpy.ndarray): Control points for the first curve at the intersection. ...
3.534699
3.366757
1.049883
cross_prod = _helpers.cross_product( edge_tangent.ravel(order="F"), corner_tangent.ravel(order="F") ) # A negative cross product indicates that ``edge_tangent`` is # "inside" / "to the left" of ``corner_tangent`` (due to right-hand rule). if cross_prod > 0.0: return False #...
def ignored_edge_corner(edge_tangent, corner_tangent, corner_previous_edge)
Check ignored when a corner lies **inside** another edge. .. note:: This is a helper used only by :func:`ignored_corner`, which in turn is only used by :func:`classify_intersection`. Helper for :func:`ignored_corner` where one of ``s`` and ``t`` are ``0``, but **not both**. Args: ...
3.666406
3.665839
1.000154
if intersection.s == 0.0: if intersection.t == 0.0: # Double corner. return ignored_double_corner( intersection, tangent_s, tangent_t, edge_nodes1, edge_nodes2 ) else: # s-only corner. prev_index = (intersection.index_...
def ignored_corner( intersection, tangent_s, tangent_t, edge_nodes1, edge_nodes2 )
Check if an intersection is an "ignored" corner. .. note:: This is a helper used only by :func:`classify_intersection`. An "ignored" corner is one where the surfaces just "kiss" at the point of intersection but their interiors do not meet. We can determine this by comparing the tangent lines ...
2.185323
2.214419
0.98686
edge_end = False if s == 1.0: s = 0.0 index1 = (index1 + 1) % 3 edge_end = True # NOTE: This is not a typo, the values can be updated twice if both ``s`` # and ``t`` are ``1.0`` if t == 1.0: t = 0.0 index2 = (index2 + 1) % 3 edge_end = True ...
def handle_ends(index1, s, index2, t)
Updates intersection parameters if it is on the end of an edge. .. note:: This is a helper used only by :meth:`.Surface.intersect`. Does nothing if the intersection happens in the middle of two edges. If the intersection occurs at the end of the first curve, moves it to the beginning of t...
3.495098
2.926946
1.194111
if intersection.s == 1.0: next_index = (intersection.index_first + 1) % 3 # Make sure we haven't accidentally ignored an existing intersection. for other_int in intersections: if other_int.s == 0.0 and other_int.index_first == next_index: if other_int in unus...
def to_front(intersection, intersections, unused)
Rotates a node to the "front". .. note:: This is a helper used only by :func:`basic_interior_combine`, which in turn is only used by :func:`combine_intersections`. If a node is at the end of a segment, moves it to the beginning of the next segment (at the exact same point). We assume that ...
2.762402
2.497996
1.105847
along_edge = None index_first = intersection.index_first s = intersection.s for other_int in intersections: other_s = other_int.s if other_int.index_first == index_first and other_s > s: if along_edge is None or other_s < along_edge.s: along_edge = other_...
def get_next_first(intersection, intersections, to_end=True)
Gets the next node along the current (first) edge. .. note:: This is a helper used only by :func:`get_next`, which in turn is only used by :func:`basic_interior_combine`, which itself is only used by :func:`combine_intersections`. Along with :func:`get_next_second`, this function does th...
3.991067
4.091576
0.975435
along_edge = None index_second = intersection.index_second t = intersection.t for other_int in intersections: other_t = other_int.t if other_int.index_second == index_second and other_t > t: if along_edge is None or other_t < along_edge.t: along_edge = ot...
def get_next_second(intersection, intersections, to_end=True)
Gets the next node along the current (second) edge. .. note:: This is a helper used only by :func:`get_next`, which in turn is only used by :func:`basic_interior_combine`, which itself is only used by :func:`combine_intersections`. Along with :func:`get_next_first`, this function does th...
4.016376
4.011793
1.001142
# Moving along the first or second edge will produce the same result, but # since we "rotate" all intersections to the beginning of an edge, the # index may not match the first or second (or both). along_first = get_next_first(intersection, intersections, to_end=False) if along_first is None: ...
def get_next_coincident(intersection, intersections)
Gets the next node along the current (coincident) edge. .. note:: This is a helper used only by :func:`get_next`, which in turn is only used by :func:`basic_interior_combine`, which itself is only used by :func:`combine_intersections`. Along with :func:`get_next_first` and :func:`get_nex...
6.259302
5.557586
1.126263
result = None if is_first(intersection.interior_curve): result = get_next_first(intersection, intersections) elif is_second(intersection.interior_curve): result = get_next_second(intersection, intersections) elif intersection.interior_curve == CLASSIFICATION_T.COINCIDENT: re...
def get_next(intersection, intersections, unused)
Gets the next node along a given edge. .. note:: This is a helper used only by :func:`basic_interior_combine`, which in turn is only used by :func:`combine_intersections`. This function does the majority of the heavy lifting for :func:`basic_interior_combine`. .. note:: This fun...
3.680158
2.979748
1.235056
if is_first(start_node.interior_curve): if end_node.index_first != start_node.index_first: raise ValueError(_WRONG_CURVE) return start_node.index_first, start_node.s, end_node.s elif is_second(start_node.interior_curve): if end_node.index_second != start_node.index_sec...
def ends_to_curve(start_node, end_node)
Convert a "pair" of intersection nodes to a curve segment. .. note:: This is a helper used only by :func:`basic_interior_combine`, which in turn is only used by :func:`combine_intersections`. .. note:: This function could specialize to the first or second segment attached to ``st...
2.491799
1.922313
1.29625
r # NOTE: This is a circular import. from bezier import _surface_intersection located = _surface_intersection.locate_point( nodes2, degree2, nodes1[0, 0], nodes1[1, 0] ) if located is not None: return None, True located = _surface_intersection.locate_point( nodes1, ...
def no_intersections(nodes1, degree1, nodes2, degree2)
r"""Determine if one surface is in the other. Helper for :func:`combine_intersections` that handles the case of no points of intersection. In this case, either the surfaces are disjoint or one is fully contained in the other. To check containment, it's enough to check if one of the corners is cont...
3.66757
3.26257
1.124135
if len(all_types) != 1: raise ValueError("Unexpected value, types should all match", all_types) point_type = all_types.pop() if point_type == CLASSIFICATION_T.OPPOSED: return [], None elif point_type == CLASSIFICATION_T.IGNORED_CORNER: return [], None elif point_type ...
def tangent_only_intersections(all_types)
Determine intersection in the case of only-tangent intersections. If the only intersections are tangencies, then either the surfaces are tangent but don't meet ("kissing" edges) or one surface is internally tangent to the other. Thus we expect every intersection to be classified as :attr:`~.Inters...
3.836232
2.611871
1.468768
unused = intersections[:] result = [] while unused: start = unused.pop() curr_node = start next_node = get_next(curr_node, intersections, unused) edge_ends = [(curr_node, next_node)] while next_node is not start: curr_node = to_front(next_node, inters...
def basic_interior_combine(intersections, max_edges=10)
Combine intersections that don't involve tangencies. .. note:: This is a helper used only by :func:`combine_intersections`. .. note:: This helper assumes ``intersections`` isn't empty, but doesn't enforce it. Args: intersections (List[.Intersection]): Intersections from eac...
4.125013
3.735479
1.10428
r if intersections: return basic_interior_combine(intersections) elif all_types: return tangent_only_intersections(all_types) else: return no_intersections(nodes1, degree1, nodes2, degree2)
def combine_intersections( intersections, nodes1, degree1, nodes2, degree2, all_types )
r"""Combine curve-curve intersections into curved polygon(s). .. note:: This is a helper used only by :meth:`.Surface.intersect`. Does so assuming each intersection lies on an edge of one of two :class:`.Surface`-s. .. note :: This assumes that each ``intersection`` has been classifie...
6.383139
8.299273
0.76912
r dimension, num_nodes = nodes.shape binom_val = 1.0 result = np.zeros((dimension, 1), order="F") index = num_nodes - 1 result[:, 0] += nodes[:, index] # curve evaluate_multi_barycentric() takes arrays. lambda1 = np.asfortranarray([lambda1]) lambda2 = np.asfortranarray([lambda2]) ...
def _evaluate_barycentric(nodes, degree, lambda1, lambda2, lambda3)
r"""Compute a point on a surface. Evaluates :math:`B\left(\lambda_1, \lambda_2, \lambda_3\right)` for a B |eacute| zier surface / triangle defined by ``nodes``. .. note:: There is also a Fortran implementation of this function, which will be used if it can be built. Args: nodes...
4.626929
4.938693
0.936873
r num_vals, _ = param_vals.shape result = np.empty((dimension, num_vals), order="F") for index, (lambda1, lambda2, lambda3) in enumerate(param_vals): result[:, index] = evaluate_barycentric( nodes, degree, lambda1, lambda2, lambda3 )[:, 0] return result
def _evaluate_barycentric_multi(nodes, degree, param_vals, dimension)
r"""Compute multiple points on the surface. .. note:: There is also a Fortran implementation of this function, which will be used if it can be built. Args: nodes (numpy.ndarray): Control point nodes that define the surface. degree (int): The degree of the surface define by ``nod...
3.552249
4.065972
0.873653
r num_vals, _ = param_vals.shape result = np.empty((dimension, num_vals), order="F") for index, (s, t) in enumerate(param_vals): result[:, index] = evaluate_barycentric( nodes, degree, 1.0 - s - t, s, t )[:, 0] return result
def _evaluate_cartesian_multi(nodes, degree, param_vals, dimension)
r"""Compute multiple points on the surface. .. note:: There is also a Fortran implementation of this function, which will be used if it can be built. Args: nodes (numpy.ndarray): Control point nodes that define the surface. degree (int): The degree of the surface define by ``nod...
4.418316
4.997027
0.884189
dimension, _ = np.shape(nodes) nodes1 = np.empty((dimension, degree + 1), order="F") nodes2 = np.empty((dimension, degree + 1), order="F") nodes3 = np.empty((dimension, degree + 1), order="F") curr2 = degree curr3 = -1 for i in six.moves.xrange(degree + 1): nodes1[:, i] = nodes[...
def _compute_edge_nodes(nodes, degree)
Compute the nodes of each edges of a surface. .. note:: There is also a Fortran implementation of this function, which will be used if it can be built. Args: nodes (numpy.ndarray): Control point nodes that define the surface. degree (int): The degree of the surface define by ``n...
2.546232
2.536885
1.003684
r _, num_nodes = nodes.shape if num_nodes == 2: shoelace = SHOELACE_LINEAR scale_factor = 2.0 elif num_nodes == 3: shoelace = SHOELACE_QUADRATIC scale_factor = 6.0 elif num_nodes == 4: shoelace = SHOELACE_CUBIC scale_factor = 20.0 elif num_nodes ==...
def shoelace_for_area(nodes)
r"""Compute an auxiliary "shoelace" sum used to compute area. .. note:: This is a helper for :func:`_compute_area`. Defining :math:`\left[i, j\right] = x_i y_j - y_i x_j` as a shoelace term illuminates the name of this helper. On a degree one curve, this function will return .. math:: ...
2.586121
2.261738
1.143422
path = os.path.join(IMAGES_DIR, filename) figure.savefig(path, bbox_inches="tight") plt.close(figure)
def save_image(figure, filename)
Save an image to the docs images directory. Args: filename (str): The name of the file (not containing directory info).
2.685164
3.942349
0.681108
result = np.empty((2, len(points)), order="F") for index, point in enumerate(points): result[:, index] = point return result
def stack1d(*points)
Fill out the columns of matrix with a series of points. This is because ``np.hstack()`` will just make another 1D vector out of them and ``np.vstack()`` will put them in the rows. Args: points (Tuple[numpy.ndarray, ...]): Tuple of 1D points (i.e. arrays with shape ``(2,)``. Return...
3.514335
4.14819
0.847197
if NO_IMAGES: return curve = bezier.Curve.from_nodes(nodes) line = bezier.Curve.from_nodes(nodes[:, (0, -1)]) midpoints = np.hstack([curve.evaluate(0.5), line.evaluate(0.5)]) ax = curve.plot(256) line.plot(256, ax=ax) ax.plot( midpoints[0, :], midpoints[1, :], color="bl...
def linearization_error(nodes)
Image for :func:`.linearization_error` docstring.
3.738782
3.565096
1.048719
if NO_IMAGES: return points = np.hstack([curve1.evaluate(s), curve2.evaluate(t)]) points_new = np.hstack([curve1.evaluate(new_s), curve2.evaluate(new_t)]) ax = curve1.plot(256) curve2.plot(256, ax=ax) ax.plot( points[0, :], points[1, :], color="black", ...
def newton_refine1(s, new_s, curve1, t, new_t, curve2)
Image for :func:`.newton_refine` docstring.
2.44752
2.315186
1.057159
if NO_IMAGES: return ax = curve1.plot(256) ax.lines[-1].zorder = 1 curve2.plot(256, ax=ax) ax.lines[-1].zorder = 1 points = curve1.evaluate_multi(np.asfortranarray(s_vals)) colors = seaborn.dark_palette("blue", 5) ax.scatter( points[0, :], points[1, :], c=colors, s=...
def newton_refine2(s_vals, curve1, curve2)
Image for :func:`.newton_refine` docstring.
3.195987
3.094117
1.032924
if NO_IMAGES: return line0 = bezier.Curve.from_nodes(stack1d(start0, end0)) line1 = bezier.Curve.from_nodes(stack1d(start1, end1)) ax = line0.plot(2) line1.plot(256, ax=ax) (x_val,), (y_val,) = line0.evaluate(s) ax.plot([x_val], [y_val], color="black", marker="o") ax.axis("...
def segment_intersection1(start0, end0, start1, end1, s)
Image for :func:`.segment_intersection` docstring.
4.496433
4.214251
1.066959
if NO_IMAGES: return line0 = bezier.Curve.from_nodes(stack1d(start0, end0)) line1 = bezier.Curve.from_nodes(stack1d(start1, end1)) ax = line0.plot(2) line1.plot(2, ax=ax) ax.axis("scaled") save_image(ax.figure, "segment_intersection2.png")
def segment_intersection2(start0, end0, start1, end1)
Image for :func:`.segment_intersection` docstring.
4.648446
4.287667
1.084143
if NO_IMAGES: return figure = plt.figure() ax = figure.gca() points = stack1d(start0, end0, start1, end1) ax.plot(points[0, :2], points[1, :2], marker="o") ax.plot(points[0, 2:], points[1, 2:], marker="o") ax.axis("scaled") _plot_helpers.add_plot_boundary(ax) save_image...
def helper_parallel_lines(start0, end0, start1, end1, filename)
Image for :func:`.parallel_lines_parameters` docstring.
3.818219
3.61279
1.056861
if NO_IMAGES: return ax = curve.plot(256) line = ax.lines[0] nodes = curve._nodes ax.plot( nodes[0, :], nodes[1, :], color="black", linestyle="None", marker="o" ) add_patch(ax, nodes, line.get_color()) ax.axis("scaled") ax.set_xlim(-0.125, 1.125) ax.set_ylim...
def curve_constructor(curve)
Image for :class`.Curve` docstring.
3.69204
3.565576
1.035468
if NO_IMAGES: return ax = curve.plot(256) points = curve.evaluate_multi(np.asfortranarray([0.75])) ax.plot( points[0, :], points[1, :], color="black", linestyle="None", marker="o" ) ax.axis("scaled") ax.set_xlim(-0.125, 1.125) ax.set_ylim(-0.0625, 0.5625) save_i...
def curve_evaluate(curve)
Image for :meth`.Curve.evaluate` docstring.
3.664225
3.503196
1.045966
if NO_IMAGES: return figure = plt.figure() ax = figure.gca() add_patch(ax, curve._nodes, "gray") ax = left.plot(256, ax=ax) line = ax.lines[-1] add_patch(ax, left._nodes, line.get_color()) right.plot(256, ax=ax) line = ax.lines[-1] add_patch(ax, right._nodes, line.g...
def curve_subdivide(curve, left, right)
Image for :meth`.Curve.subdivide` docstring.
2.95031
2.843385
1.037605
if NO_IMAGES: return ax = curve1.plot(256) curve2.plot(256, ax=ax) intersections = curve1.evaluate_multi(s_vals) ax.plot( intersections[0, :], intersections[1, :], color="black", linestyle="None", marker="o", ) ax.axis("scaled") ax.se...
def curve_intersect(curve1, curve2, s_vals)
Image for :meth`.Curve.intersect` docstring.
3.167405
3.018418
1.049359
if NO_IMAGES: return ax = surface.plot(256, with_nodes=True) line = ax.lines[0] nodes = surface._nodes add_patch(ax, nodes[:, (0, 1, 2, 5)], line.get_color()) delta = 1.0 / 32.0 ax.text( nodes[0, 0], nodes[1, 0], r"$v_0$", fontsize=20, ve...
def surface_constructor(surface)
Image for :class`.Surface` docstring.
1.86313
1.837972
1.013688
if NO_IMAGES: return ax = surface.plot(256) ax.plot( point[0, :], point[1, :], color="black", linestyle="None", marker="o" ) ax.axis("scaled") ax.set_xlim(-0.125, 1.125) ax.set_ylim(-0.125, 1.125) save_image(ax.figure, "surface_evaluate_barycentric.png")
def surface_evaluate_barycentric(surface, point)
Image for :meth`.Surface.evaluate_barycentric` docstring.
3.095528
3.001578
1.0313
if NO_IMAGES: return ax = surface.plot(256) ax.plot( points[0, :], points[1, :], color="black", linestyle="None", marker="o" ) delta = 1.0 / 32.0 font_size = 18 ax.text( points[0, 0], points[1, 0], r"$w_0$", fontsize=font_size, ve...
def surface_evaluate_cartesian_multi(surface, points)
Image for :meth`.Surface.evaluate_cartesian_multi` docstring.
2.228104
2.192629
1.016179
if NO_IMAGES: return ax = surface.plot(256) ax.axis("scaled") ax.set_xlim(-0.125, 2.125) ax.set_ylim(-0.125, 2.125) save_image(ax.figure, "surface_is_valid1.png")
def surface_is_valid1(surface)
Image for :meth`.Surface.is_valid` docstring.
3.80746
3.504253
1.086525
if NO_IMAGES: return edge1, edge2, edge3 = surface.edges N = 128 # Compute points on each edge. std_s = np.linspace(0.0, 1.0, N + 1) points1 = edge1.evaluate_multi(std_s) points2 = edge2.evaluate_multi(std_s) points3 = edge3.evaluate_multi(std_s) # Compute the actual bo...
def surface_is_valid3(surface)
Image for :meth`.Surface.is_valid` docstring.
2.510626
2.494253
1.006564
if NO_IMAGES: return surface = bezier.Surface.from_nodes( np.asfortranarray([[0.0, 1.0, 0.0], [0.0, 0.0, 1.0]]) ) surf_a, surf_b, surf_c, surf_d = surface.subdivide() figure, ((ax1, ax2), (ax3, ax4)) = plt.subplots(2, 2) for ax in (ax1, ax2, ax3, ax4): surface.plot(...
def surface_subdivide1()
Image for :meth`.Surface.subdivide` docstring.
1.70997
1.670566
1.023587
if NO_IMAGES: return # Plot set-up. figure = plt.figure() ax = figure.gca() colors = seaborn.husl_palette(6) N = 128 s_vals = np.linspace(0.0, 1.0, N + 1) # Add edges from surface. add_edges(ax, surface, s_vals, colors[4]) # Now do the same for surface B. add_ed...
def surface_subdivide2(surface, sub_surface_b)
Image for :meth`.Surface.subdivide` docstring.
3.301816
3.249138
1.016213
if NO_IMAGES: return ax = curved_poly.plot(256) ax.axis("scaled") ax.set_xlim(-0.125, 2.125) ax.set_ylim(-0.625, 1.625) save_image(ax.figure, "curved_polygon_constructor1.png")
def curved_polygon_constructor1(curved_poly)
Image for :class`.CurvedPolygon` docstring.
3.679422
3.437675
1.070323
if NO_IMAGES: return ax = curve.plot(256) interval = r"$\left[0, 1\right]$" line = ax.lines[-1] line.set_label(interval) color1 = line.get_color() new_curve.plot(256, ax=ax) interval = r"$\left[-\frac{1}{4}, \frac{3}{4}\right]$" line = ax.lines[-1] line.set_label(in...
def curve_specialize(curve, new_curve)
Image for :meth`.Curve.specialize` docstring.
2.467492
2.402143
1.027205
if NO_IMAGES: return figure, (ax1, ax2) = plt.subplots(1, 2) # Plot features of the parameter space in ax1. tri_surf = bezier.Surface.from_nodes( np.asfortranarray([[0.0, 1.0, 0.0], [0.0, 0.0, 1.0]]) ) tri_surf.plot(2, ax=ax1) ax1.plot([0.25], [0.5], marker="H") ax1...
def newton_refine_surface(surface, x_val, y_val, s, t, new_s, new_t)
Image for :func:`._surface_helpers.newton_refine` docstring.
2.322993
2.268605
1.023974
if NO_IMAGES: return surface1 = bezier.Surface.from_nodes( np.asfortranarray( [[1.0, 1.75, 2.0, 1.0, 1.5, 1.0], [0.0, 0.25, 1.0, 1.0, 1.5, 2.0]] ) ) surface2 = bezier.Surface.from_nodes( np.asfortranarray( [ [0.0, 1.6875, 2.0,...
def classify_intersection1(s, curve1, tangent1, curve2, tangent2)
Image for :func:`._surface_helpers.classify_intersection` docstring.
2.30003
2.24675
1.023715
if NO_IMAGES: return surface1 = bezier.Surface.from_nodes( np.asfortranarray( [[1.0, 1.5, 2.0, 1.25, 1.75, 1.5], [0.0, 1.0, 0.0, 1.0, 1.0, 2.0]] ) ) surface2 = bezier.Surface.from_nodes( np.asfortranarray( [[0.0, 1.5, 3.0, 0.75, 2.25, 1.5], [...
def classify_intersection2(s, curve1, curve2)
Image for :func:`._surface_helpers.classify_intersection` docstring.
2.580069
2.460809
1.048464
if NO_IMAGES: return surface1 = bezier.Surface.from_nodes( np.asfortranarray( [ [1.0, 1.5, 2.0, 1.25, 1.75, 1.5], [0.0, 1.0, 0.0, 0.9375, 0.9375, 1.875], ] ) ) surface2 = bezier.Surface.from_nodes( np.asfortran...
def classify_intersection5(s, curve1, curve2)
Image for :func:`._surface_helpers.classify_intersection` docstring.
2.283232
2.252998
1.01342
if NO_IMAGES: return surface1 = bezier.Surface.from_nodes( np.asfortranarray( [ [0.0, 4.5, 9.0, 0.0, 4.5, 0.0], [0.0, 0.0, 2.25, 1.25, 2.375, 2.5], ] ) ) surface2 = bezier.Surface.from_nodes( np.asfortranarray(...
def classify_intersection7(s, curve1a, curve1b, curve2)
Image for :func:`._surface_helpers.classify_intersection` docstring.
2.674892
2.589907
1.032814
if NO_IMAGES: return curve = bezier.Curve.from_nodes(nodes) # Find the center of the circle along the direction # perpendicular to the tangent vector (90 degree left turn). radius_dir = np.asfortranarray([[-tangent_vec[1, 0]], [tangent_vec[0, 0]]]) radius_dir /= np.linalg.norm(radi...
def get_curvature(nodes, s, tangent_vec, curvature)
Image for :func:`get_curvature` docstring.
3.420617
3.366201
1.016166
if NO_IMAGES: return ax = curve.plot(256) points = np.hstack([point1, point2, point3]) ax.plot( points[0, :], points[1, :], color="black", linestyle="None", marker="o" ) ax.axis("scaled") ax.set_xlim(-0.8125, 0.0625) ax.set_ylim(0.75, 2.0625) save_image(ax.figur...
def curve_locate(curve, point1, point2, point3)
Image for :meth`.Curve.locate` docstring.
3.558708
3.35467
1.060822
if NO_IMAGES: return ax = curve.plot(256) ax.plot(point[0, :], point[1, :], marker="H") wrong_points = curve.evaluate_multi(np.asfortranarray([s, new_s])) ax.plot( wrong_points[0, [0]], wrong_points[1, [0]], color="black", linestyle="None", marke...
def newton_refine_curve(curve, point, s, new_s)
Image for :func:`._curve_helpers.newton_refine` docstring.
3.015741
2.896041
1.041332
if NO_IMAGES: return ax = curve.plot(256) ax.lines[-1].zorder = 1 points = curve.evaluate_multi(np.asfortranarray(s_vals)) colors = seaborn.dark_palette("blue", 6) ax.scatter( points[0, :], points[1, :], c=colors, s=20, alpha=0.75, zorder=2 ) # Set the axis bounds /...
def newton_refine_curve_cusp(curve, s_vals)
Image for :func:`._curve_helpers.newton_refine` docstring.
3.928542
3.845739
1.021531
if NO_IMAGES: return ax = classify_help(s, curve1, surface1, curve2, surface2, None) ax.set_xlim(-1.125, 1.125) ax.set_ylim(-0.125, 1.125) save_image(ax.figure, "classify_intersection8.png")
def classify_intersection8(s, curve1, surface1, curve2, surface2)
Image for :func:`._surface_helpers.classify_intersection` docstring.
3.951077
3.712994
1.064121
edges1 = ( bezier.Curve.from_nodes( np.asfortranarray([[32.0, 30.0], [20.0, 25.0]]) ), bezier.Curve.from_nodes( np.asfortranarray([[30.0, 25.0, 20.0], [25.0, 20.0, 20.0]]) ), bezier.Curve.from_nodes( np.asfortranarray([[20.0, 25.0, 30....
def _edges_classify_intersection9()
The edges for the curved polygon intersection used below. Helper for :func:`classify_intersection9`.
1.53297
1.554599
0.986087
if NO_IMAGES: return surface1 = bezier.Surface.from_nodes( np.asfortranarray( [ [0.0, 20.0, 40.0, 10.0, 30.0, 20.0], [0.0, 40.0, 0.0, 25.0, 25.0, 50.0], ] ) ) surface2 = bezier.Surface.from_nodes( np.asfortrana...
def classify_intersection9(s, curve1, curve2)
Image for :func:`._surface_helpers.classify_intersection` docstring.
2.404087
2.366953
1.015688
if NO_IMAGES: return figure, (ax1, ax2) = plt.subplots(1, 2) curve.plot(256, ax=ax1) color = ax1.lines[-1].get_color() add_patch(ax1, curve._nodes, color) elevated.plot(256, ax=ax2) color = ax2.lines[-1].get_color() add_patch(ax2, elevated._nodes, color) ax1.axis("scale...
def curve_elevate(curve, elevated)
Image for :meth:`.curve.Curve.elevate` docstring.
2.855494
2.788402
1.024061
if NO_IMAGES: return nodes = np.asfortranarray([[0.0, 1.0, 0.0], [0.0, 0.0, 1.0]]) surface = bezier.Surface(nodes, degree=1) ax = surface.plot(256) ax.axis("scaled") _plot_helpers.add_plot_boundary(ax) save_image(ax.figure, "unit_triangle.png")
def unit_triangle()
Image for :class:`.surface.Surface` docstring.
4.872369
4.444444
1.096283
if NO_IMAGES: return figure, (ax1, ax2) = plt.subplots(1, 2, sharex=True, sharey=True) curve.plot(256, ax=ax1) color = ax1.lines[-1].get_color() add_patch(ax1, curve._nodes, color) reduced.plot(256, ax=ax2) color = ax2.lines[-1].get_color() add_patch(ax2, reduced._nodes, co...
def curve_reduce(curve, reduced)
Image for :meth:`.curve.Curve.reduce` docstring.
3.135743
3.030852
1.034608
if NO_IMAGES: return ax = curve.plot(256) color = ax.lines[-1].get_color() add_patch(ax, curve._nodes, color, alpha=0.25, node_color=color) reduced.plot(256, ax=ax) color = ax.lines[-1].get_color() add_patch(ax, reduced._nodes, color, alpha=0.25, node_color=color) ax.axis("...
def curve_reduce_approx(curve, reduced)
Image for :meth:`.curve.Curve.reduce` docstring.
3.991108
3.86216
1.033388
r a_val, b_val, c_val, d_val = jac_both[:, 0] # and e_val = x_val - surf_x f_val = y_val - surf_y # Now solve: denom = a_val * d_val - b_val * c_val delta_s = (d_val * e_val - c_val * f_val) / denom delta_t = (a_val * f_val - b_val * e_val) / denom return delta_s, delta_t
def newton_refine_solve(jac_both, x_val, surf_x, y_val, surf_y)
r"""Helper for :func:`newton_refine`. We have a system: .. code-block:: rest [A C][ds] = [E] [B D][dt] [F] This is not a typo, ``A->B->C->D`` matches the data in ``jac_both``. We solve directly rather than using a linear algebra utility: .. code-block:: rest ds = (D E - ...
2.659417
2.692593
0.987679
centroid_x, centroid_y, width, candidate_nodes = candidate point = np.asfortranarray([x_val, y_val]) if not _helpers.contains_nd(candidate_nodes, point): return nodes_a, nodes_b, nodes_c, nodes_d = _surface_helpers.subdivide_nodes( candidate_nodes, degree ) half_width = 0.5...
def update_locate_candidates(candidate, next_candidates, x_val, y_val, degree)
Update list of candidate surfaces during geometric search for a point. .. note:: This is used **only** as a helper for :func:`locate_point`. Checks if the point ``(x_val, y_val)`` is contained in the ``candidate`` surface. If not, this function does nothing. If the point is contaned, the four ...
2.899031
2.67844
1.082358
sum_x = 0.0 sum_y = 0.0 for centroid_x, centroid_y, _, _ in candidates: sum_x += centroid_x sum_y += centroid_y denom = 3.0 * len(candidates) return sum_x / denom, sum_y / denom
def mean_centroid(candidates)
Take the mean of all centroids in set of reference triangles. .. note:: This is used **only** as a helper for :func:`locate_point`. Args: candidates (List[Tuple[float, float, float, numpy.ndarray]): List of 4-tuples, each of which has been produced by :func:`locate_point`. ...
2.301407
2.519653
0.913383
r # We track the centroid rather than base_x/base_y/width (by storing triple # the centroid -- to avoid division by three until needed). We also need # to track the width (or rather, just the sign of the width). candidates = [(1.0, 1.0, 1.0, nodes)] for _ in six.moves.xrange(MAX_LOCATE_SUBDIVISI...
def _locate_point(nodes, degree, x_val, y_val)
r"""Locate a point on a surface. .. note:: There is also a Fortran implementation of this function, which will be used if it can be built. Does so by recursively subdividing the surface and rejecting sub-surfaces with bounding boxes that don't contain the point. After the sub-surfaces a...
5.857303
5.736057
1.021137
if intersection1.index_first != intersection2.index_first: return False if intersection1.index_second != intersection2.index_second: return False return np.allclose( [intersection1.s, intersection1.t], [intersection2.s, intersection2.t], atol=0.0, rtol=...
def same_intersection(intersection1, intersection2, wiggle=0.5 ** 40)
Check if two intersections are close to machine precision. .. note:: This is a helper used only by :func:`verify_duplicates`, which in turn is only used by :func:`generic_intersect`. Args: intersection1 (.Intersection): The first intersection. intersection2 (.Intersection): The ...
2.524396
2.495508
1.011576
for uniq1, uniq2 in itertools.combinations(uniques, 2): if same_intersection(uniq1, uniq2): raise ValueError("Non-unique intersection") counter = collections.Counter() for dupe in duplicates: matches = [] for index, uniq in enumerate(uniques): if same_in...
def verify_duplicates(duplicates, uniques)
Verify that a set of intersections had expected duplicates. .. note:: This is a helper used only by :func:`generic_intersect`. Args: duplicates (List[.Intersection]): List of intersections corresponding to duplicates that were filtered out. uniques (List[.Intersection]): Li...
3.101723
2.68301
1.156061
if edge_infos is None: return for edge_info in edge_infos: num_segments = len(edge_info) for index in six.moves.xrange(-1, num_segments - 1): index1, start1, end1 = edge_info[index] # First, verify the start and end parameters for the current # s...
def verify_edge_segments(edge_infos)
Verify that the edge segments in an intersection are valid. .. note:: This is a helper used only by :func:`generic_intersect`. Args: edge_infos (Optional[list]): List of "edge info" lists. Each list represents a curved polygon and contains 3-tuples of edge index, start ...
3.256742
2.909378
1.119395
found = None for other in intersections: if ( intersection.index_first == other.index_first and intersection.index_second == other.index_second ): if intersection.s == 0.0 and other.s == 0.0: found = other break ...
def add_edge_end_unused(intersection, duplicates, intersections)
Add intersection that is ``COINCIDENT_UNUSED`` but on an edge end. This is a helper for :func:`~._surface_intersection.add_intersection`. It assumes that * ``intersection`` will have at least one of ``s == 0.0`` or ``t == 0.0`` * A "misclassified" intersection in ``intersections`` that matches `...
2.410893
2.205808
1.092975
for other in intersections: if ( other.interior_curve == UNUSED_T and intersection.index_first == other.index_first and intersection.index_second == other.index_second ): if intersection.s == 0.0 and other.s == 0.0: duplicates.appe...
def check_unused(intersection, duplicates, intersections)
Check if a "valid" ``intersection`` is already in ``intersections``. This assumes that * ``intersection`` will have at least one of ``s == 0.0`` or ``t == 0.0`` * At least one of the intersections in ``intersections`` is classified as ``COINCIDENT_UNUSED``. Args: intersection (.Intersec...
3.396121
3.041856
1.116464
# NOTE: There is no corresponding "enable", but the disable only applies # in this lexical scope. # pylint: disable=too-many-locals edge_end, is_corner, intersection_args = _surface_helpers.handle_ends( index1, s, index2, t ) if edge_end: intersection = _intersection_h...
def add_intersection( # pylint: disable=too-many-arguments index1, s, index2, t, interior_curve, edge_nodes1, edge_nodes2, duplicates, intersections, )
Create an :class:`Intersection` and append. The intersection will be classified as either a duplicate or a valid intersection and appended to one of ``duplicates`` or ``intersections`` depending on that classification. Args: index1 (int): The index (among 0, 1, 2) of the first edge in the ...
4.668082
4.455394
1.047737
r if not coincident: return None if st_vals[0, 0] >= st_vals[0, 1] or st_vals[1, 0] >= st_vals[1, 1]: return UNUSED_T else: return CLASSIFICATION_T.COINCIDENT
def classify_coincident(st_vals, coincident)
r"""Determine if coincident parameters are "unused". .. note:: This is a helper for :func:`surface_intersections`. In the case that ``coincident`` is :data:`True`, then we'll have two sets of parameters :math:`(s_1, t_1)` and :math:`(s_2, t_2)`. If one of :math:`s1 < s2` or :math:`t1 < t2` is...
4.516881
4.285331
1.054033
if intersection.interior_curve in ACCEPTABLE_CLASSIFICATIONS: return True if intersection.interior_curve in TANGENT_CLASSIFICATIONS: return intersection.s == 0.0 or intersection.t == 0.0 return False
def should_use(intersection)
Check if an intersection can be used as part of a curved polygon. Will return :data:`True` if the intersection is classified as :attr:`~.IntersectionClassification.FIRST`, :attr:`~.IntersectionClassification.SECOND` or :attr:`~.IntersectionClassification.COINCIDENT` or if the intersection is classi...
5.639606
5.398939
1.044577
# NOTE: There is no corresponding "enable", but the disable only applies # in this lexical scope. # pylint: disable=too-many-locals intersections = [] duplicates = [] for index1, nodes1 in enumerate(edge_nodes1): for index2, nodes2 in enumerate(edge_nodes2): st_val...
def surface_intersections(edge_nodes1, edge_nodes2, all_intersections)
Find all intersections among edges of two surfaces. This treats intersections which have ``s == 1.0`` or ``t == 1.0`` as duplicates. The duplicates may be checked by the caller, e.g. by :func:`verify_duplicates`. Args: edge_nodes1 (Tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray]): The ...
4.336858
3.991359
1.086562
r bbox_int = _geometric_intersection.bbox_intersect(nodes1, nodes2) if bbox_int != INTERSECTION_T: return [], None, () # We need **all** edges (as nodes). edge_nodes1 = _surface_helpers.compute_edge_nodes(nodes1, degree1) edge_nodes2 = _surface_helpers.compute_edge_nodes(nodes2, degree2...
def generic_intersect( nodes1, degree1, nodes2, degree2, verify, all_intersections )
r"""Find all intersections among edges of two surfaces. This treats intersections which have ``s == 1.0`` or ``t == 1.0`` as duplicates. The duplicates will be checked by :func:`verify_duplicates` if ``verify`` is :data:`True`. Args: nodes1 (numpy.ndarray): The nodes defining the first surface...
5.103459
4.574571
1.115615
r all_intersections = _geometric_intersection.all_intersections return generic_intersect( nodes1, degree1, nodes2, degree2, verify, all_intersections )
def _geometric_intersect(nodes1, degree1, nodes2, degree2, verify)
r"""Find all intersections among edges of two surfaces. .. note:: There is also a Fortran implementation of this function, which will be used if it can be built. Uses :func:`generic_intersect` with the :attr:`~.IntersectionStrategy.GEOMETRIC` intersection strategy. Args: nodes1...
5.543432
8.429892
0.657592
r all_intersections = _algebraic_intersection.all_intersections return generic_intersect( nodes1, degree1, nodes2, degree2, verify, all_intersections )
def algebraic_intersect(nodes1, degree1, nodes2, degree2, verify)
r"""Find all intersections among edges of two surfaces. Uses :func:`generic_intersect` with the :attr:`~.IntersectionStrategy.ALGEBRAIC` intersection strategy. Args: nodes1 (numpy.ndarray): The nodes defining the first surface in the intersection (assumed in :math:\mathbf{R}^2`). ...
5.383819
7.802918
0.689975
# Only modify path on Windows. if os.name != "nt": return path = os.environ.get("PATH") if path is None: return try: extra_dll_dir = pkg_resources.resource_filename("bezier", "extra-dll") if os.path.isdir(extra_dll_dir): os.environ["PATH"] = path + ...
def modify_path()
Modify the module search path.
3.13184
3.175149
0.98636
for template in TEMPLATES: expected_msg = template.format(name) if caught_exc.args == (expected_msg,): return raise caught_exc
def handle_import_error(caught_exc, name)
Allow or re-raise an import error. This is to distinguish between expected and unexpected import errors. If the module is not found, it simply means the Cython / Fortran speedups were not built with the package. If the error message is different, e.g. ``... undefined symbol: __curve_intersection_MOD_al...
5.268057
6.280385
0.838811
# NOTE: NumPy may not be installed, but we don't want **this** module to # cause an import failure. from numpy.distutils.fcompiler import gnu # Only macOS. if sys.platform != MAC_OS: return False # Only ``gfortran``. if not isinstance(f90_compiler, gnu.Gnu95FCompiler): ...
def is_macos_gfortran(f90_compiler)
Checks if the current build is ``gfortran`` on macOS. Args: f90_compiler (numpy.distutils.fcompiler.FCompiler): A Fortran compiler instance. Returns: bool: Only :data:`True` if * Current OS is macOS (checked via ``sys.platform``). * ``f90_compiler`` corresponds to ...
6.622137
6.071143
1.090756
if not is_macos_gfortran(f90_compiler): return library_dirs = f90_compiler.library_dirs # ``library_dirs`` is a list (i.e. mutable), so we can update in place. library_dirs[:] = setup_helpers.gfortran_search_path(library_dirs)
def patch_f90_compiler(f90_compiler)
Patch up ``f90_compiler.library_dirs``. On macOS, a Homebrew installed ``gfortran`` needs some help. The ``numpy.distutils`` "default" constructor for ``Gnu95FCompiler`` only has a single library search path, but there are many library paths included in the full ``gcc`` install. Args: f90_...
6.391314
5.451722
1.172348
edges = [] for index, start, end in edge_info: nodes = all_edge_nodes[index] new_nodes = _curve_helpers.specialize_curve(nodes, start, end) degree = new_nodes.shape[1] - 1 edge = _curve_mod.Curve(new_nodes, degree, _copy=False) edges.append(edge) return curved_po...
def _make_intersection(edge_info, all_edge_nodes)
Convert a description of edges into a curved polygon. .. note:: This is a helper used only by :meth:`.Surface.intersect`. Args: edge_info (Tuple[Tuple[int, float, float], ...]): Information describing each edge in the curved polygon by indicating which surface / edge on...
5.799084
4.880025
1.188331
_, num_nodes = nodes.shape degree = cls._get_degree(num_nodes) return cls(nodes, degree, _copy=_copy)
def from_nodes(cls, nodes, _copy=True)
Create a :class:`.Surface` from nodes. Computes the ``degree`` based on the shape of ``nodes``. Args: nodes (numpy.ndarray): The nodes in the surface. The columns represent each node while the rows are the dimension of the ambient space. _copy (b...
5.474164
4.517871
1.211669
# 8 * num_nodes = 4(d + 1)(d + 2) # = 4d^2 + 12d + 8 # = (2d + 3)^2 - 1 d_float = 0.5 * (np.sqrt(8.0 * num_nodes + 1.0) - 3.0) d_int = int(np.round(d_float)) if (d_int + 1) * (d_int + 2) == 2 * num_nodes: return d_int ...
def _get_degree(num_nodes)
Get the degree of the current surface. Args: num_nodes (int): The number of control points for a B |eacute| zier surface. Returns: int: The degree :math:`d` such that :math:`(d + 1)(d + 2)/2` equals ``num_nodes``. Raises: ValueEr...
3.981136
3.404359
1.169423
r if self._dimension != 2: raise NotImplementedError( "2D is the only supported dimension", "Current dimension", self._dimension, ) edge1, edge2, edge3 = self._get_edges() return _surface_helpers.compute_area( ...
def area(self)
r"""The area of the current surface. For surfaces in :math:`\mathbf{R}^2`, this computes the area via Green's theorem. Using the vector field :math:`\mathbf{F} = \left[-y, x\right]^T`, since :math:`\partial_x(x) - \partial_y(-y) = 2` Green's theorem says twice the area is equal to ...
6.859772
6.463999
1.061227
nodes1, nodes2, nodes3 = _surface_helpers.compute_edge_nodes( self._nodes, self._degree ) edge1 = _curve_mod.Curve(nodes1, self._degree, _copy=False) edge2 = _curve_mod.Curve(nodes2, self._degree, _copy=False) edge3 = _curve_mod.Curve(nodes3, self._degree, _c...
def _compute_edges(self)
Compute the edges of the current surface. Returns: Tuple[~curve.Curve, ~curve.Curve, ~curve.Curve]: The edges of the surface.
3.197679
2.532955
1.26243
if self._edges is None: self._edges = self._compute_edges() return self._edges
def _get_edges(self)
Get the edges for the current surface. If they haven't been computed yet, first compute and store them. This is provided as a means for internal calls to get the edges without copying (since :attr:`.edges` copies before giving to a user to keep the stored data immutable). Retu...
3.995486
3.878136
1.030259
edge1, edge2, edge3 = self._get_edges() # NOTE: It is crucial that we return copies here. Since the edges # are cached, if they were mutable, callers could # inadvertently mutate the cached value. edge1 = edge1._copy() # pylint: disable=protected-access ...
def edges(self)
The edges of the surface. .. doctest:: surface-edges :options: +NORMALIZE_WHITESPACE >>> nodes = np.asfortranarray([ ... [0.0, 0.5 , 1.0, 0.1875, 0.625, 0.0], ... [0.0, -0.1875, 0.0, 0.5 , 0.625, 1.0], ... ]) >>> surface = bezier.S...
3.65394
3.803087
0.960783
weights_total = lambda1 + lambda2 + lambda3 if not np.allclose(weights_total, 1.0, atol=0.0): raise ValueError( "Weights do not sum to 1", lambda1, lambda2, lambda3 ) if lambda1 < 0.0 or lambda2 < 0.0 or lambda3 < 0.0: raise ValueErro...
def _verify_barycentric(lambda1, lambda2, lambda3)
Verifies that weights are barycentric and on the reference triangle. I.e., checks that they sum to one and are all non-negative. Args: lambda1 (float): Parameter along the reference triangle. lambda2 (float): Parameter along the reference triangle. lambda3 (float): ...
2.207757
2.47741
0.891155
r if _verify: if param_vals.ndim != 2: raise ValueError("Parameter values must be 2D array") for lambda1, lambda2, lambda3 in param_vals: self._verify_barycentric(lambda1, lambda2, lambda3) return _surface_helpers.evaluate_barycentric_mult...
def evaluate_barycentric_multi(self, param_vals, _verify=True)
r"""Compute multiple points on the surface. Assumes ``param_vals`` has three columns of barycentric coordinates. See :meth:`evaluate_barycentric` for more details on how each row of parameter values is evaluated. .. image:: ../../images/surface_evaluate_barycentric_multi.png ...
4.25766
4.346268
0.979613
if s < 0.0 or t < 0.0 or s + t > 1.0: raise ValueError("Point lies outside reference triangle", s, t)
def _verify_cartesian(s, t)
Verifies that a point is in the reference triangle. I.e., checks that they sum to <= one and are each non-negative. Args: s (float): Parameter along the reference triangle. t (float): Parameter along the reference triangle. Raises: ValueError: If the point ...
5.143298
3.343241
1.538417
r if _verify: self._verify_cartesian(s, t) return _surface_helpers.evaluate_barycentric( self._nodes, self._degree, 1.0 - s - t, s, t )
def evaluate_cartesian(self, s, t, _verify=True)
r"""Compute a point on the surface. Evaluates :math:`B\left(1 - s - t, s, t\right)` by calling :meth:`evaluate_barycentric`: This method acts as a (partial) inverse to :meth:`locate`. .. testsetup:: surface-cartesian import numpy as np import bezier .. ...
7.172406
6.415056
1.118058