_code_components:

Components Module#

class Point(position: Tuple[float, float] | None = None, instance: Point | None = None, index: float | None = None)[source]#

Bases: Alteration

The Point class manages individual points in the coordinate system. It is used as a building block for defining fiber positions and manipulating coordinates.

position: Tuple[float, float] | None = None#
instance: Point | None = None#
index: float | None = None#
property x: float#

Returns the x-coordinate of the point.

property y: float#

Returns the y-coordinate of the point.

shift_position(shift: Tuple[float, float]) Point[source]#

Shifts the point by a given offset and returns a new Point instance.

distance(other: Point) float[source]#

Computes the Euclidean distance between this point and another point.

plot(ax: Axes = None, show: bool = True, **kwargs)#
copy() Alteration#

Create a deep copy of the object.

Returns:

A new instance that is a deep copy of the current object.

Return type:

Alteration

in_place_copy() Callable#

Decorator to manage in-place operations.

Parameters:

function (Callable) – The function to wrap.

Returns:

Wrapped function that optionally modifies the object in-place.

Return type:

Callable

intersection(*args, in_place=False, **kwargs)#
property is_empty: bool#

Check if the shapely object is empty.

Returns:

True if the object is empty, False otherwise.

Return type:

bool

rotate(*args, in_place=False, **kwargs)#
scale(*args, in_place=False, **kwargs)#
translate(*args, in_place=False, **kwargs)#
union(*args, in_place=False, **kwargs)#
class LineString(coordinates: Tuple | None = None, instance: LineString | None = None, index: float | None = None)[source]#

Bases: Alteration

The LineString class represents linear structures connecting points, useful for defining fiber alignments and connections. It includes methods for creating and manipulating these linear structures.

coordinates: Tuple | None = None#
instance: LineString | None = None#
index: float | None = None#
property boundary: Tuple[Point, Point]#

Returns the boundary points of the line string as a tuple of Shapely Point objects.

property center: Point#

Returns the centroid of the line as a Shapely Point object.

property mid_point: Point#

Returns the midpoint of the line string as a Shapely Point object.

property length: float#

Returns the length of the line string.

intersect(other: LineString) None[source]#

Intersects this line string with another, updating the shapely object in place.

get_perpendicular() LineString[source]#

Returns a new LineString object that is perpendicular to this one.

get_position_parametrization(t: float) Point[source]#

Returns the point at parameter t along the line. 0 <= t <= 1.

render_on_axis(ax, **kwargs) None[source]#

Renders the line string on a given matplotlib axis.

make_length(length: float) LineString[source]#

Returns a new LineString scaled to the specified length.

centering(center: Point) LineString[source]#

Centers the line string at a given point.

get_vector() ndarray[source]#

Returns a unit vector representing the direction of the line string.

extend(factor: float = 1) LineString[source]#

Returns a new LineString scaled by the specified factor.

copy() Alteration#

Create a deep copy of the object.

Returns:

A new instance that is a deep copy of the current object.

Return type:

Alteration

in_place_copy() Callable#

Decorator to manage in-place operations.

Parameters:

function (Callable) – The function to wrap.

Returns:

Wrapped function that optionally modifies the object in-place.

Return type:

Callable

intersection(*args, in_place=False, **kwargs)#
property is_empty: bool#

Check if the shapely object is empty.

Returns:

True if the object is empty, False otherwise.

Return type:

bool

rotate(*args, in_place=False, **kwargs)#
scale(*args, in_place=False, **kwargs)#
translate(*args, in_place=False, **kwargs)#
union(*args, in_place=False, **kwargs)#
class Polygon(coordinates: List[Tuple[float, float]] | None = None, instance: Polygon | MultiPolygon | None = None, index: float | None = None)[source]#

Bases: BaseArea

Represents a polygon using either a set of coordinates or a Shapely Polygon instance.

Parameters:
  • coordinates (list of tuple of float, optional) – A list of (x, y) tuples representing the coordinates of the polygon.

  • instance (geo.Polygon or geo.MultiPolygon, optional) – An existing Shapely Polygon or MultiPolygon instance.

  • index (float, optional) – An optional numerical index associated with the polygon.

Raises:

ValueError – If neither coordinates nor instance is provided or if both are provided.

The Polygon class manages polygonal shapes, which are essential for modeling complex geometries like fiber intersections and combined areas. This class supports operations such as intersection, union, and transformation.

property interiors#

Retrieves the interior coordinates of the polygon.

Returns:

An iterable of coordinates that define the interior boundaries of the polygon.

Return type:

Iterable

get_hole() Polygon[source]#

Retrieves the holes within the polygon as a new Polygon object.

Returns:

A polygon representing the holes, or an empty polygon if no holes exist.

Return type:

geo.Polygon

contains_points(coordinates: ndarray) ndarray[source]#

Checks which of the provided coordinates lie within the polygon or multipolygon, excluding any holes.

Parameters:

coordinates (np.ndarray) – An array of coordinates to check against the polygon or multipolygon.

Returns:

A boolean array where True indicates that the coordinate is inside the polygon or multipolygon (excluding any holes) and False indicates that it is outside or within a hole.

Return type:

np.ndarray

plot(ax: Axes = None, show: bool = True, **kwargs)#
rasterize(coordinate_system: CoordinateSystem) ndarray[source]#

Rasterizes the polygon to a grid based on a coordinate system.

Parameters:

coordinate_system (CoordinateSystem) – The coordinate system used for rasterization.

Returns:

A 2D array where 1 indicates the presence of the polygon and 0 indicates its absence.

Return type:

np.ndarray

remove_non_polygon_elements() Polygon[source]#

Removes non-polygon elements from the geometry.

Filters out elements that are not Polygon or MultiPolygon from the current geometry.

Returns:

The instance of this class with only polygon elements retained.

Return type:

Polygon

keep_largest_polygon() Polygon[source]#

Retains only the largest polygon in the geometry.

If the geometry is a MultiPolygon, it keeps the one with the largest area.

Returns:

The instance of this class with the largest polygon retained.

Return type:

Polygon

property area: float#

Calculate the area of the shape.

Returns:

The area of the shape.

Return type:

float

property bounds: Tuple[float, float, float, float]#

Get the bounds of the shape.

Returns:

The (minx, miny, maxx, maxy) bounds of the shape.

Return type:

tuple of float

property center: Point#

Get the center (centroid) of the shape.

Returns:

The centroid of the shape as a Point.

Return type:

Point

property convex_hull: Polygon#

Get the convex hull of the shape.

Returns:

The convex hull as a Polygon.

Return type:

Polygon

copy() Alteration#

Create a deep copy of the object.

Returns:

A new instance that is a deep copy of the current object.

Return type:

Alteration

property exterior#

Get the exterior boundary of the polygon.

Returns:

The exterior boundary of the polygon.

Return type:

LinearRing

get_rasterized_mesh(coordinate_system: CoordinateSystem) ndarray#

Rasterize the shape based on the given coordinate system.

Parameters:

coordinate_system (CoordinateSystem) – The coordinate system used for rasterization.

Returns:

The rasterized shape as a mesh.

Return type:

numpy.ndarray

in_place_copy() Callable#

Decorator to manage in-place operations.

Parameters:

function (Callable) – The function to wrap.

Returns:

Wrapped function that optionally modifies the object in-place.

Return type:

Callable

intersection(*args, in_place=False, **kwargs)#
property is_empty: bool#

Check if the shapely object is empty.

Returns:

True if the object is empty, False otherwise.

Return type:

bool

property is_iterable: bool#

Check if the shapely object is iterable.

Returns:

True if the object is iterable, False otherwise.

Return type:

bool

property is_multi: bool#

Check if the shapely object is a MultiPolygon.

Returns:

True if the object is a MultiPolygon, False otherwise.

Return type:

bool

property is_pure_polygon: bool#

Check if the shapely object is a pure Polygon.

Returns:

True if the object is a pure Polygon, False otherwise.

Return type:

bool

rotate(*args, in_place=False, **kwargs)#
scale(*args, in_place=False, **kwargs)#
scale_position(factor: float) BaseArea#

Scale the position of the shape.

Parameters:

factor (float) – The scaling factor for the shape’s position.

Returns:

The scaled shape.

Return type:

BaseArea

shift_position(shift: Tuple[float, float], inplace: bool = True) BaseArea#

Shift the position of the shape.

Parameters:

shift (tuple of float) – The (x, y) shift values.

Returns:

The shifted shape.

Return type:

BaseArea

split_with_line(line, return_largest: bool = True) Polygon#

Split the shape using a line.

Parameters:
  • line (LineString) – The line used for splitting the shape.

  • return_largest (bool, optional) – If True, returns the largest resulting polygon. Otherwise, returns the smallest. Default is True.

Returns:

The resulting polygon based on the split.

Return type:

ff.Polygon

Raises:

ValueError – If the shape is not a pure polygon.

translate(*args, in_place=False, **kwargs)#
union(*args, in_place=False, **kwargs)#
class EmptyPolygon(*args, **kwargs)[source]#

Bases: Polygon

A representation of an empty polygon.

The EmptyPolygon class represents an empty polygon structure, used as a placeholder for initializing and managing polygonal geometries that may be populated later in the modeling process.

property area: float#

Calculate the area of the shape.

Returns:

The area of the shape.

Return type:

float

property bounds: Tuple[float, float, float, float]#

Get the bounds of the shape.

Returns:

The (minx, miny, maxx, maxy) bounds of the shape.

Return type:

tuple of float

property center: Point#

Get the center (centroid) of the shape.

Returns:

The centroid of the shape as a Point.

Return type:

Point

contains_points(coordinates: ndarray) ndarray#

Checks which of the provided coordinates lie within the polygon or multipolygon, excluding any holes.

Parameters:

coordinates (np.ndarray) – An array of coordinates to check against the polygon or multipolygon.

Returns:

A boolean array where True indicates that the coordinate is inside the polygon or multipolygon (excluding any holes) and False indicates that it is outside or within a hole.

Return type:

np.ndarray

property convex_hull: Polygon#

Get the convex hull of the shape.

Returns:

The convex hull as a Polygon.

Return type:

Polygon

copy() Alteration#

Create a deep copy of the object.

Returns:

A new instance that is a deep copy of the current object.

Return type:

Alteration

property exterior#

Get the exterior boundary of the polygon.

Returns:

The exterior boundary of the polygon.

Return type:

LinearRing

get_hole() Polygon#

Retrieves the holes within the polygon as a new Polygon object.

Returns:

A polygon representing the holes, or an empty polygon if no holes exist.

Return type:

geo.Polygon

get_rasterized_mesh(coordinate_system: CoordinateSystem) ndarray#

Rasterize the shape based on the given coordinate system.

Parameters:

coordinate_system (CoordinateSystem) – The coordinate system used for rasterization.

Returns:

The rasterized shape as a mesh.

Return type:

numpy.ndarray

in_place_copy() Callable#

Decorator to manage in-place operations.

Parameters:

function (Callable) – The function to wrap.

Returns:

Wrapped function that optionally modifies the object in-place.

Return type:

Callable

property interiors#

Retrieves the interior coordinates of the polygon.

Returns:

An iterable of coordinates that define the interior boundaries of the polygon.

Return type:

Iterable

intersection(*args, in_place=False, **kwargs)#
property is_empty: bool#

Check if the shapely object is empty.

Returns:

True if the object is empty, False otherwise.

Return type:

bool

property is_iterable: bool#

Check if the shapely object is iterable.

Returns:

True if the object is iterable, False otherwise.

Return type:

bool

property is_multi: bool#

Check if the shapely object is a MultiPolygon.

Returns:

True if the object is a MultiPolygon, False otherwise.

Return type:

bool

property is_pure_polygon: bool#

Check if the shapely object is a pure Polygon.

Returns:

True if the object is a pure Polygon, False otherwise.

Return type:

bool

keep_largest_polygon() Polygon#

Retains only the largest polygon in the geometry.

If the geometry is a MultiPolygon, it keeps the one with the largest area.

Returns:

The instance of this class with the largest polygon retained.

Return type:

Polygon

plot(ax: Axes = None, show: bool = True, **kwargs)#
rasterize(coordinate_system: CoordinateSystem) ndarray#

Rasterizes the polygon to a grid based on a coordinate system.

Parameters:

coordinate_system (CoordinateSystem) – The coordinate system used for rasterization.

Returns:

A 2D array where 1 indicates the presence of the polygon and 0 indicates its absence.

Return type:

np.ndarray

remove_non_polygon_elements() Polygon#

Removes non-polygon elements from the geometry.

Filters out elements that are not Polygon or MultiPolygon from the current geometry.

Returns:

The instance of this class with only polygon elements retained.

Return type:

Polygon

rotate(*args, in_place=False, **kwargs)#
scale(*args, in_place=False, **kwargs)#
scale_position(factor: float) BaseArea#

Scale the position of the shape.

Parameters:

factor (float) – The scaling factor for the shape’s position.

Returns:

The scaled shape.

Return type:

BaseArea

shift_position(shift: Tuple[float, float], inplace: bool = True) BaseArea#

Shift the position of the shape.

Parameters:

shift (tuple of float) – The (x, y) shift values.

Returns:

The shifted shape.

Return type:

BaseArea

split_with_line(line, return_largest: bool = True) Polygon#

Split the shape using a line.

Parameters:
  • line (LineString) – The line used for splitting the shape.

  • return_largest (bool, optional) – If True, returns the largest resulting polygon. Otherwise, returns the smallest. Default is True.

Returns:

The resulting polygon based on the split.

Return type:

ff.Polygon

Raises:

ValueError – If the shape is not a pure polygon.

translate(*args, in_place=False, **kwargs)#
union(*args, in_place=False, **kwargs)#