This commit introduces the core functionality of the project, including the implementation of key classes and methods for drawing shapes. It also adds initial unit tests to ensure the correctness of the implemented features. Changes include: - Implementation of the `ZcDrawShapeFactory` class for managing and drawing shapes. - Implementation of the `ZcCircle` class for drawing circle shapes. - Implementation of the `ZcColor` class for handling colors and conversions between RGB and hex. - Utility functions added to `helpers.py` for common operations. - Abstract base class `BaseShape` defined for future shape extensions. - Unit tests for `ZcDrawShapeFactory`, `ZcCircle`, `ZcColor`, and utility functions in `tests` directory. All modules are documented with docstrings, and initial test coverage has been verified.
32 lines
711 B
Python
32 lines
711 B
Python
import numpy as np
|
|
import torch
|
|
|
|
def pil2tensor(image):
|
|
"""
|
|
Converts a PIL image to a normalized PyTorch tensor.
|
|
|
|
Args:
|
|
image (PIL.Image.Image): The PIL image to convert.
|
|
|
|
Returns:
|
|
torch.Tensor: The normalized PyTorch tensor.
|
|
"""
|
|
return torch.from_numpy(np.array(image).astype(np.float32) / 255.0)
|
|
|
|
def check_index_exists(array, index):
|
|
"""
|
|
Checks if an index exists in an array.
|
|
|
|
Args:
|
|
array (iterable): The array or sequence to check.
|
|
index (int): The index to check.
|
|
|
|
Returns:
|
|
bool: True if the index exists, False otherwise.
|
|
"""
|
|
try:
|
|
array[index]
|
|
return True
|
|
except IndexError:
|
|
return False
|