Skip to content

Commit

Permalink
Tidy up util types
Browse files Browse the repository at this point in the history
  • Loading branch information
WillB97 committed Dec 6, 2024
1 parent 604d94c commit 6ff9ec1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 21 deletions.
23 changes: 7 additions & 16 deletions april_vision/cli/marker_generator/marker_tile.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,14 @@
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

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:
Expand Down Expand Up @@ -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,
Expand All @@ -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,
)
Expand Down Expand Up @@ -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,
)
Expand Down
17 changes: 12 additions & 5 deletions april_vision/cli/marker_generator/utils.py
Original file line number Diff line number Diff line change
@@ -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]

Expand Down Expand Up @@ -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."""

Expand All @@ -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]),
)
Expand All @@ -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),
)

0 comments on commit 6ff9ec1

Please sign in to comment.