simetri.graphics.dots

Dot and Dots classes for creating dots.

  1"""Dot and Dots classes for creating dots.
  2"""
  3
  4__all__ = ["Dot", "Dots"]
  5
  6import numpy as np
  7
  8from .shapes import Shape
  9from .batch import Batch
 10from ..helpers.validation import validate_args
 11from ..canvas.style_map import shape_args
 12from ..settings.settings import defaults
 13from .common import Point
 14from .all_enums import Types
 15from ..colors.colors import Color
 16from ..geometry.geometry import close_points2
 17from ..canvas.style_map import batch_args
 18
 19
 20class Dot(Shape):
 21    """A dot defined by a single point.
 22    The radius is for drawing. The only style property is the color."""
 23
 24    def __init__(
 25        self, pos: Point = (0, 0), radius: float = 1, color: Color = None, **kwargs
 26    ) -> None:
 27        """Initialize a Dot object.
 28
 29        Args:
 30            pos (Point, optional): The position of the dot. Defaults to (0, 0).
 31            radius (float, optional): The radius of the dot. Defaults to 1.
 32            color (Color, optional): The color of the dot. Defaults to None.
 33            **kwargs: Additional keyword arguments.
 34        """
 35        valid_args = shape_args
 36        validate_args(kwargs, valid_args)
 37        super().__init__([(0, 0)], **kwargs)
 38        self.move_to(pos)
 39        self.subtype = Types.DOT
 40        self.radius = radius  # for drawing
 41        if color is not None:
 42            self.color = color
 43        else:
 44            self.color = defaults["dot_color"]
 45
 46    @property
 47    def pos(self) -> Point:
 48        """Return the point of the dot.
 49
 50        Returns:
 51            Point: The point of the dot.
 52        """
 53        return self.vertices[0]
 54
 55    @pos.setter
 56    def pos(self, new_pos: Point):
 57        """Set the position of the dot.
 58
 59        Args:
 60            new_pos (Point): The new position of the dot.
 61
 62        Raises:
 63            TypeError: If the new position is not a list, tuple, or ndarray.
 64        """
 65        if not isinstance(new_pos, (list, tuple, np.ndarray)):
 66            raise TypeError("Name must be a string")
 67        self.move_to(new_pos)
 68
 69    def copy(self) -> Shape:
 70        """Return a copy of the dot.
 71
 72        Returns:
 73            Shape: A copy of the dot.
 74        """
 75        color = self.color.copy()
 76        return Dot(self.pos, self.radius, color)
 77
 78    def __str__(self):
 79        """Return a string representation of the dot.
 80
 81        Returns:
 82            str: The string representation of the dot.
 83        """
 84        return f"Dot({self.pos}, {self.radius}, {self.color})"
 85
 86    def __repr__(self):
 87        """Return a string representation of the dot.
 88
 89        Returns:
 90            str: The string representation of the dot.
 91        """
 92        return f"Dot({self.pos}, {self.radius}, {self.color})"
 93
 94    def __eq__(self, other):
 95        """Check if the dot is equal to another dot.
 96
 97        Args:
 98            other (Dot): The other dot to compare to.
 99
100        Returns:
101            bool: True if the dots are equal, False otherwise.
102        """
103        return other.type == Types.DOT and close_points2(
104            self.pos, other.pos, self.dtol2
105        )
106
107
108class Dots(Batch):
109    """For creating multiple dots. Initially there is only one dot."""
110
111    def __init__(
112        self, pos: Point = (0, 0), radius: float = 1, color: Color = None, **kwargs
113    ) -> None:
114        """Initialize a Dots object.
115
116        Args:
117            pos (Point, optional): The position of the dots. Defaults to (0, 0).
118            radius (float, optional): The radius of the dots. Defaults to 1.
119            color (Color, optional): The color of the dots. Defaults to None.
120            **kwargs: Additional keyword arguments.
121        """
122        valid_args = batch_args + shape_args + ["radius", "color", "pos"]
123        dot = Dot(pos=pos, radius=radius, color=color, **kwargs)
124        super().__init__([dot], subtype=Types.DOTS, **kwargs)
class Dot(simetri.graphics.shape.Shape):
 21class Dot(Shape):
 22    """A dot defined by a single point.
 23    The radius is for drawing. The only style property is the color."""
 24
 25    def __init__(
 26        self, pos: Point = (0, 0), radius: float = 1, color: Color = None, **kwargs
 27    ) -> None:
 28        """Initialize a Dot object.
 29
 30        Args:
 31            pos (Point, optional): The position of the dot. Defaults to (0, 0).
 32            radius (float, optional): The radius of the dot. Defaults to 1.
 33            color (Color, optional): The color of the dot. Defaults to None.
 34            **kwargs: Additional keyword arguments.
 35        """
 36        valid_args = shape_args
 37        validate_args(kwargs, valid_args)
 38        super().__init__([(0, 0)], **kwargs)
 39        self.move_to(pos)
 40        self.subtype = Types.DOT
 41        self.radius = radius  # for drawing
 42        if color is not None:
 43            self.color = color
 44        else:
 45            self.color = defaults["dot_color"]
 46
 47    @property
 48    def pos(self) -> Point:
 49        """Return the point of the dot.
 50
 51        Returns:
 52            Point: The point of the dot.
 53        """
 54        return self.vertices[0]
 55
 56    @pos.setter
 57    def pos(self, new_pos: Point):
 58        """Set the position of the dot.
 59
 60        Args:
 61            new_pos (Point): The new position of the dot.
 62
 63        Raises:
 64            TypeError: If the new position is not a list, tuple, or ndarray.
 65        """
 66        if not isinstance(new_pos, (list, tuple, np.ndarray)):
 67            raise TypeError("Name must be a string")
 68        self.move_to(new_pos)
 69
 70    def copy(self) -> Shape:
 71        """Return a copy of the dot.
 72
 73        Returns:
 74            Shape: A copy of the dot.
 75        """
 76        color = self.color.copy()
 77        return Dot(self.pos, self.radius, color)
 78
 79    def __str__(self):
 80        """Return a string representation of the dot.
 81
 82        Returns:
 83            str: The string representation of the dot.
 84        """
 85        return f"Dot({self.pos}, {self.radius}, {self.color})"
 86
 87    def __repr__(self):
 88        """Return a string representation of the dot.
 89
 90        Returns:
 91            str: The string representation of the dot.
 92        """
 93        return f"Dot({self.pos}, {self.radius}, {self.color})"
 94
 95    def __eq__(self, other):
 96        """Check if the dot is equal to another dot.
 97
 98        Args:
 99            other (Dot): The other dot to compare to.
100
101        Returns:
102            bool: True if the dots are equal, False otherwise.
103        """
104        return other.type == Types.DOT and close_points2(
105            self.pos, other.pos, self.dtol2
106        )

A dot defined by a single point. The radius is for drawing. The only style property is the color.

Dot( pos: Sequence[float] = (0, 0), radius: float = 1, color: simetri.colors.colors.Color = None, **kwargs)
25    def __init__(
26        self, pos: Point = (0, 0), radius: float = 1, color: Color = None, **kwargs
27    ) -> None:
28        """Initialize a Dot object.
29
30        Args:
31            pos (Point, optional): The position of the dot. Defaults to (0, 0).
32            radius (float, optional): The radius of the dot. Defaults to 1.
33            color (Color, optional): The color of the dot. Defaults to None.
34            **kwargs: Additional keyword arguments.
35        """
36        valid_args = shape_args
37        validate_args(kwargs, valid_args)
38        super().__init__([(0, 0)], **kwargs)
39        self.move_to(pos)
40        self.subtype = Types.DOT
41        self.radius = radius  # for drawing
42        if color is not None:
43            self.color = color
44        else:
45            self.color = defaults["dot_color"]

Initialize a Dot object.

Arguments:
  • pos (Point, optional): The position of the dot. Defaults to (0, 0).
  • radius (float, optional): The radius of the dot. Defaults to 1.
  • color (Color, optional): The color of the dot. Defaults to None.
  • **kwargs: Additional keyword arguments.
subtype
radius
pos: Sequence[float]
47    @property
48    def pos(self) -> Point:
49        """Return the point of the dot.
50
51        Returns:
52            Point: The point of the dot.
53        """
54        return self.vertices[0]

Return the point of the dot.

Returns:

Point: The point of the dot.

def copy(self) -> simetri.graphics.shape.Shape:
70    def copy(self) -> Shape:
71        """Return a copy of the dot.
72
73        Returns:
74            Shape: A copy of the dot.
75        """
76        color = self.color.copy()
77        return Dot(self.pos, self.radius, color)

Return a copy of the dot.

Returns:

Shape: A copy of the dot.

class Dots(simetri.graphics.batch.Batch):
109class Dots(Batch):
110    """For creating multiple dots. Initially there is only one dot."""
111
112    def __init__(
113        self, pos: Point = (0, 0), radius: float = 1, color: Color = None, **kwargs
114    ) -> None:
115        """Initialize a Dots object.
116
117        Args:
118            pos (Point, optional): The position of the dots. Defaults to (0, 0).
119            radius (float, optional): The radius of the dots. Defaults to 1.
120            color (Color, optional): The color of the dots. Defaults to None.
121            **kwargs: Additional keyword arguments.
122        """
123        valid_args = batch_args + shape_args + ["radius", "color", "pos"]
124        dot = Dot(pos=pos, radius=radius, color=color, **kwargs)
125        super().__init__([dot], subtype=Types.DOTS, **kwargs)

For creating multiple dots. Initially there is only one dot.

Dots( pos: Sequence[float] = (0, 0), radius: float = 1, color: simetri.colors.colors.Color = None, **kwargs)
112    def __init__(
113        self, pos: Point = (0, 0), radius: float = 1, color: Color = None, **kwargs
114    ) -> None:
115        """Initialize a Dots object.
116
117        Args:
118            pos (Point, optional): The position of the dots. Defaults to (0, 0).
119            radius (float, optional): The radius of the dots. Defaults to 1.
120            color (Color, optional): The color of the dots. Defaults to None.
121            **kwargs: Additional keyword arguments.
122        """
123        valid_args = batch_args + shape_args + ["radius", "color", "pos"]
124        dot = Dot(pos=pos, radius=radius, color=color, **kwargs)
125        super().__init__([dot], subtype=Types.DOTS, **kwargs)

Initialize a Dots object.

Arguments:
  • pos (Point, optional): The position of the dots. Defaults to (0, 0).
  • radius (float, optional): The radius of the dots. Defaults to 1.
  • color (Color, optional): The color of the dots. Defaults to None.
  • **kwargs: Additional keyword arguments.