bluemira.geometry._private_tools ================================ .. py:module:: bluemira.geometry._private_tools .. autoapi-nested-parse:: A collection of private geometry tools for discretised geometry. Do not use these; use primitive operations in geometry/tools.py instead. Exceptions ---------- .. autoapisummary:: bluemira.geometry._private_tools.MixedFaceAreaError Classes ------- .. autoapisummary:: bluemira.geometry._private_tools.MixedFaceMaker Functions --------- .. autoapisummary:: bluemira.geometry._private_tools._segment_lengths bluemira.geometry._private_tools._side_vector bluemira.geometry._private_tools.offset bluemira.geometry._private_tools.make_circle_arc bluemira.geometry._private_tools.convert_coordinates_to_wire bluemira.geometry._private_tools.convert_coordinates_to_face bluemira.geometry._private_tools.make_mixed_wire bluemira.geometry._private_tools.make_mixed_face bluemira.geometry._private_tools.make_wire bluemira.geometry._private_tools.make_face Module Contents --------------- .. py:exception:: MixedFaceAreaError Bases: :py:obj:`bluemira.geometry.error.GeometryError` .. autoapi-inheritance-diagram:: bluemira.geometry._private_tools.MixedFaceAreaError :parts: 1 :private-bases: An error to raise when the area of a mixed face does not give a good match to the area enclosed by the original coordinates. .. py:function:: _segment_lengths(x: numpy.ndarray, y: numpy.ndarray, z: numpy.ndarray) -> numpy.ndarray Returns the length of each individual segment in a set of coordinates :param x: x coordinates [m] :param y: y coordinates [m] :param z: z coordinates [m] :rtype: The array of the length of each individual segment in the coordinates .. py:function:: _side_vector(polygon_array: numpy.ndarray) -> numpy.ndarray Calculates the side vectors of an anti-clockwise polygon :param polygon_array: The 2-D array of polygon point coordinates :returns: The 2-D array of the polygon side vectors :rtype: sides .. py:function:: offset(x: numpy.ndarray, z: numpy.ndarray, offset_value: float) -> tuple[numpy.ndarray, numpy.ndarray] Get a square-based offset of the coordinates (no splines). N-sized output :param x: The x coordinate vector :param z: The x coordinate vector :param offset_value: The offset value [m] :returns: * *xo* -- The x offset coordinates * *zo* -- The z offset coordinates .. py:function:: make_circle_arc(radius: float, x_centre: float = 0, y_centre: float = 0, angle: float = 2 * np.pi, n_points: int = 200, start_angle: float = 0) -> tuple[numpy.ndarray, numpy.ndarray] Make a circle arc of a specified radius and angle at a given location. :param radius: The radius of the circle arc :param x_centre: The x coordinate of the circle arc centre :param y_centre: The y coordinate of the circle arc centre :param angle: The angle of the circle arc [radians] :param n_points: The number of points on the circle :param start_angle: The starting angle of the circle arc :returns: * *x* -- The x coordinates of the circle arc * *y* -- The y coordinates of the circle arc .. py:function:: convert_coordinates_to_wire(x: numpy.ndarray, y: numpy.ndarray, z: numpy.ndarray, label: str = '', method: str = 'mixed', **kwargs: dict[str, Any]) -> bluemira.geometry.wire.BluemiraWire Converts the provided coordinates into a BluemiraWire using the specified method. :param x: The x coordinates of points to be converted to a BluemiraWire object :param y: The y coordinates of points to be converted to a BluemiraWire object :param z: The z coordinates of points to be converted to a BluemiraWire object :param method: The conversion method to be used: - mixed (default): results in a mix of splines and polygons - polygon: pure polygon representation - spline: pure spline representation :param label: The label for the resulting BluemiraWire object :param kwargs: Any other arguments for the conversion method, see e.g. make_mixed_face :rtype: The resulting BluemiraWire from the conversion .. py:function:: convert_coordinates_to_face(x: numpy.ndarray, y: numpy.ndarray, z: numpy.ndarray, method: str = 'mixed', label: str = '', **kwargs: dict[str, Any]) -> bluemira.geometry.face.BluemiraFace Converts the provided coordinates into a BluemiraFace using the specified method. :param x: The x coordinates of points to be converted to a BluemiraFace object :param y: The y coordinates of points to be converted to a BluemiraFace object :param z: The z coordinates of points to be converted to a BluemiraFace object :param method: The conversion method to be used: - mixed (default): results in a mix of splines and polygons - polygon: pure polygon representation - spline: pure spline representation :type method: str :param label: The label for the resulting BluemiraFace object :param kwargs: Any other arguments for the conversion method, see e.g. make_mixed_face :rtype: The resulting BluemiraFace from the conversion .. py:function:: make_mixed_wire(x: numpy.ndarray, y: numpy.ndarray, z: numpy.ndarray, label: str = '', *, median_factor: float = 2.0, n_segments: int = 4, a_acute: float = 150.0, cleaning_atol: float = 1e-06, allow_fallback: bool = True, debug: bool = False) -> bluemira.geometry.wire.BluemiraWire Construct a BluemiraWire object from the provided coordinates using a combination of polygon and spline wires. Polygons are determined by having a median length larger than the threshold or an angle that is more acute than the threshold. :param x: The x coordinates of points to be converted to a BluemiraWire object :param y: The y coordinates of points to be converted to a BluemiraWire object :param z: The z coordinates of points to be converted to a BluemiraWire object :param label: The label for the resulting BluemiraWire object :param median_factor: The factor of the median for which to filter segment lengths (below median_factor*median_length --> spline) :param n_segments: The minimum number of segments for a spline :param a_acute: The angle [degrees] between two consecutive segments deemed to be too acute to be fit with a spline. :param cleaning_atol: If a point lies within this distance [m] of the previous point then it will be treated as a duplicate and removed. This can stabilise the conversion in cases where the point density is too high for a wire to be constructed as a spline. By default this is set to 1e-6. :param allow_fallback: If True then a failed attempt to make a mixed wire will fall back to a polygon wire, else an exception will be raised. By default True. :param debug: Whether or not to print debugging information :rtype: The BluemiraWire of the mixed polygon/spline coordinates :raises RuntimeError: Cannot create mixed face .. py:function:: make_mixed_face(x: numpy.ndarray, y: numpy.ndarray, z: numpy.ndarray, label: str = '', *, median_factor: float = 2.0, n_segments: int = 4, a_acute: float = 150.0, cleaning_atol: float = 1e-06, area_rtol: float = 0.05, allow_fallback: bool = True, debug: bool = False) -> bluemira.geometry.face.BluemiraFace Construct a BluemiraFace object from the provided coordinates using a combination of polygon and spline wires. Polygons are determined by having a median length larger than the threshold or an angle that is more acute than the threshold. :param x: The x coordinates of points to be converted to a BluemiraFace object :param y: The y coordinates of points to be converted to a BluemiraFace object :param z: The z coordinates of points to be converted to a BluemiraFace object :param label: The label for the resulting BluemiraFace object :rtype: The BluemiraFace of the mixed polygon/spline coordinates :param median_factor: The factor of the median for which to filter segment lengths (below median_factor*median_length --> spline) :param n_segments: The minimum number of segments for a spline :param a_acute: The angle [degrees] between two consecutive segments deemed to be too acute to be fit with a spline. :param cleaning_atol: If a point lies within this distance [m] of the previous point then it will be treated as a duplicate and removed. This can stabilise the conversion in cases where the point density is too high for a wire to be constructed as a spline. By default this is set to 1e-6. :param area_rtol: If the area of the resulting face deviates by this relative value from the area enclosed by the provided coordinates then the conversion will fail and either fall back to a polygon-like face or raise an exception, depending on the setting of `allow_fallback`. :param allow_fallback: If True then a failed attempt to make a mixed face will fall back to a polygon wire, else an exception will be raised. By default True. :param debug: Whether or not to print debugging information :raises MixedFaceAreaError: Face and coordinates area are not close :raises RuntimeError: Can make mixed face .. py:function:: make_wire(x: numpy.ndarray, y: numpy.ndarray, z: numpy.ndarray, label: str = '', *, spline: bool = False) -> bluemira.geometry.wire.BluemiraWire Makes a wire from a set of coordinates. :param x: The x coordinates of points to be converted to a BluemiraWire object :param y: The y coordinates of points to be converted to a BluemiraWire object :param z: The z coordinates of points to be converted to a BluemiraWire object :param label: The label for the resulting BluemiraWire object :param spline: If True then creates the BluemiraWire using a Bezier spline curve, by default False :rtype: The BluemiraWire bound by the coordinates .. py:function:: make_face(x: numpy.ndarray, y: numpy.ndarray, z: numpy.ndarray, label: str = '', *, spline: bool = False) -> bluemira.geometry.face.BluemiraFace Makes a face from a set of coordinates. :param x: The x coordinates of points to be converted to a BluemiraFace object :param y: The y coordinates of points to be converted to a BluemiraFace object :param z: The z coordinates of points to be converted to a BluemiraFace object :param label: The label for the resulting BluemiraFace object :param spline: If True then creates the BluemiraFace using a Bezier spline curve, by default False :rtype: The BluemiraFace bound by the coordinates .. py:class:: MixedFaceMaker(x: numpy.ndarray, y: numpy.ndarray, z: numpy.ndarray, label: str = '', *, median_factor: float = 2.0, n_segments: int = 4, a_acute: float = 150.0, cleaning_atol: float = 1e-06, debug: bool = False) Utility class for the creation of Faces that combine splines and polygons. Polygons are detected by median length and turning angle. :param x: The x coordinates of points to be converted to a BluemiraFace object :param y: The y coordinates of points to be converted to a BluemiraFace object :param z: The z coordinates of points to be converted to a BluemiraFace object :param label: The label for the resulting BluemiraFace object :param median_factor: The factor of the median for which to filter segment lengths (below median_factor*median_length --> spline) :param n_segments: The minimum number of segments for a spline :param a_acute: The angle [degrees] between two consecutive segments deemed to be too acute to be fit with a spline. :param cleaning_atol: If a point lies within this distance [m] of the previous point then it will be treated as a duplicate and removed. This can stabilise the conversion in cases where the point density is too high for a wire to be constructed as a spline. By default this is set to 1e-6. :param debug: Whether or not to print debugging information .. py:attribute:: x .. py:attribute:: y .. py:attribute:: z .. py:attribute:: num_points .. py:attribute:: label :value: '' .. py:attribute:: median_factor :value: 2.0 .. py:attribute:: n_segments :value: 4 .. py:attribute:: a_acute :value: 150.0 .. py:attribute:: cleaning_atol :value: 1e-06 .. py:attribute:: debug :value: False .. py:attribute:: edges :value: None .. py:attribute:: wire :value: None .. py:attribute:: face :value: None .. py:attribute:: polygon_loops :value: None .. py:attribute:: spline_loops :value: None .. py:attribute:: flag_spline_first :value: None .. py:attribute:: _debugger :value: None .. py:method:: build() Carry out the MixedFaceMaker sequence to make a Face .. py:method:: _find_polygon_vertices() -> numpy.ndarray Finds all vertices in the Coordinates which belong to polygon-like edges :rtype: The vertices of the coordinates which are polygon-like (dtype=int) .. py:method:: _get_polygon_sequences(vertices: numpy.ndarray) -> list[list[float]] Gets the sequences of polygon segments :param vertices: The vertices of the lcoordinates which are polygon-like :returns: * *The list of start and end tuples of the polygon segments* * *list([start, end], [start, end])* :raises GeometryError: Not a good candidate for splining .. py:method:: _get_spline_sequences(polygon_sequences: numpy.ndarray) -> list[list[float]] Gets the sequences of spline segments :param polygon_sequences: The list of start and end tuples of the polygon segments :returns: * *The list of start and end tuples of the spline segments* * *list([start, end], [start, end])* .. py:method:: _clean_coordinates(coords: numpy.ndarray) -> numpy.ndarray Clean the provided coordinates by removing any values that are closer than the instance's cleaning_atol value. :param coords: 3D array of coordinates to be cleaned. :rtype: 3D array of cleaned coordinates. .. py:method:: _make_subcoordinates(polygon_sequences: numpy.ndarray, spline_sequences: numpy.ndarray) .. py:method:: _make_subwires() .. py:method:: _make_wire() .. py:method:: _make_face()