diff --git a/april_vision/cli/marker_generator/marker_tile.py b/april_vision/cli/marker_generator/marker_tile.py index 4cbbd96..6cb8592 100644 --- a/april_vision/cli/marker_generator/marker_tile.py +++ b/april_vision/cli/marker_generator/marker_tile.py @@ -3,8 +3,6 @@ These image tiles can be arranged on a page in the different modes. """ -from typing import NamedTuple - import numpy as np from numpy.typing import NDArray from PIL import Image, ImageDraw, ImageFont, ImageOps @@ -12,14 +10,7 @@ from april_vision.cli.utils import ApriltagFamily, get_tag_family from april_vision.marker import MarkerType -from .utils import mm_to_pixels - - -class coord(NamedTuple): - """Simple class to store coordinates.""" - - x: int - y: int +from .utils import Coord, mm_to_pixels def generate_tag_array(tag_data: ApriltagFamily, tag_id: int) -> NDArray: @@ -104,8 +95,8 @@ def __init__( self.marker_height = self.image.height # Update the coords of where the marker is in the tile - self.top_left = coord(0, 0) - self.bottom_right = coord(self.image.width, self.image.height) + self.top_left = Coord(0, 0) + self.bottom_right = Coord(self.image.width, self.image.height) def add_border_line( self, @@ -126,11 +117,11 @@ def add_border_line( self.image = bordered_image # Update the coords of where the marker is in the tile - self.top_left = coord( + self.top_left = Coord( self.top_left.x + border_width, self.top_left.y + border_width, ) - self.bottom_right = coord( + self.bottom_right = Coord( self.bottom_right.x + border_width, self.bottom_right.y + border_width, ) @@ -268,11 +259,11 @@ def add_description_border( self.image = bordered_image # Update the coords of where the marker is in the tile - self.top_left = coord( + self.top_left = Coord( self.top_left.x + marker_square_size, self.top_left.y + marker_square_size, ) - self.bottom_right = coord( + self.bottom_right = Coord( self.bottom_right.x + marker_square_size, self.bottom_right.y + marker_square_size, ) diff --git a/april_vision/cli/marker_generator/utils.py b/april_vision/cli/marker_generator/utils.py index 99c5db6..173e96b 100644 --- a/april_vision/cli/marker_generator/utils.py +++ b/april_vision/cli/marker_generator/utils.py @@ -1,7 +1,7 @@ """Utility functions for the marker generator.""" import logging from enum import Enum -from typing import List, Tuple +from typing import List, NamedTuple from font_roboto import Roboto # type: ignore[import,unused-ignore] @@ -44,6 +44,13 @@ def mm_to_pixels(mm: float) -> int: return int(inches * DPI) +class Coord(NamedTuple): + """Simple class to store coordinates.""" + + x: int + y: int + + class PageSize(Enum): """Enum to define the dimentions of different page sizes.""" @@ -53,9 +60,9 @@ class PageSize(Enum): A4L = (297, 210) @property - def pixels(self) -> Tuple[int, int]: + def pixels(self) -> Coord: """Return the page size in pixels.""" - return ( + return Coord( mm_to_pixels(self.value[0]), mm_to_pixels(self.value[1]), ) @@ -69,9 +76,9 @@ def __init__(self, width: int, height: int) -> None: self.height = height @property - def pixels(self) -> Tuple[int, int]: + def pixels(self) -> Coord: """Return the custom page size in pixels.""" - return ( + return Coord( mm_to_pixels(self.width), mm_to_pixels(self.height), )