Coverage for src/min_circle/utils/cloud.py: 100%
10 statements
« prev ^ index » next coverage.py v7.10.4, created at 2025-08-19 00:41 +0000
« prev ^ index » next coverage.py v7.10.4, created at 2025-08-19 00:41 +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 and self.points.shape[1] == 2, "Points must be a 2D array with shape (n, 2)"
34 def scatter(self, size: int = 10) -> go.Scatter:
35 """Create a Plotly Scatter trace representing the point cloud.
37 Args:
38 size: Size of the marker points
40 Returns:
41 A Plotly Scatter object that can be added to a figure
42 """
43 return go.Scatter(
44 x=self.points[:, 0],
45 y=self.points[:, 1],
46 mode="markers",
47 marker=dict(symbol="x", size=size, color="blue"),
48 name=f"Points ({len(self.points)})",
49 )