Coverage for src / min_circle / utils / cloud.py: 100%
11 statements
« prev ^ index » next coverage.py v7.13.2, created at 2026-01-26 19:42 +0000
« prev ^ index » next coverage.py v7.13.2, created at 2026-01-26 19:42 +0000
1"""Point cloud utility class for representing and visualizing sets of points.
3This module provides a Cloud class for representing collections of 2D points
4and methods for visualizing them.
5"""
7from dataclasses import dataclass
9import numpy as np
10import plotly.graph_objects as go
13@dataclass(frozen=True)
14class Cloud:
15 """A 2D point cloud representation.
17 This class represents a collection of points in 2D space and provides
18 methods for visualizing them using Plotly.
20 Attributes:
21 points: A numpy array of shape (n, 2) representing n points in 2D space
22 """
24 points: np.ndarray
26 def __post_init__(self) -> None:
27 """Validate that the points array has the correct shape.
29 Raises:
30 AssertionError: If the points array doesn't have shape (n, 2)
31 """
32 assert len(self.points.shape) == 2, "Points must be a 2D array"
33 assert self.points.shape[1] == 2, "Points must have shape (n, 2)"
35 def scatter(self, size: int = 10) -> go.Scatter:
36 """Create a Plotly Scatter trace representing the point cloud.
38 Args:
39 size: Size of the marker points
41 Returns:
42 A Plotly Scatter object that can be added to a figure
43 """
44 return go.Scatter(
45 x=self.points[:, 0],
46 y=self.points[:, 1],
47 mode="markers",
48 marker={"symbol": "x", "size": size, "color": "blue"},
49 name=f"Points ({len(self.points)})",
50 )