Skip to main content

MiniFw Base

Project description

Documentation for Geometry and Color Models

This document provides an overview of the Point, Rect, RGB, and Size classes implemented using Pydantic for validation and type enforcement.

Point Class

The Point class represents a point in a 2D space with non-negative coordinates.

Attributes

  • x: The x-coordinate (non-negative integer).
  • y: The y-coordinate (non-negative integer).

Methods

  • is_in_rect(rect: 'Rect') -> bool: Checks if the point is inside the given rectangle.
  • offset(dx: int = 0, dy: int = 0) -> 'Point': Returns a new Point offset by specified amounts.

Rect Class

The Rect class represents a rectangle defined by its position and dimensions.

Attributes

  • x: The x-coordinate of the rectangle's top-left corner (non-negative integer).
  • y: The y-coordinate of the rectangle's top-left corner (non-negative integer).
  • w: The width of the rectangle (greater than zero).
  • h: The height of the rectangle (greater than zero).

Methods

  • __contains__(item: 'Rect'): Checks if another rectangle is contained within this rectangle.
  • size() -> 'Size': Returns the size of the rectangle.
  • center() -> 'Point': Returns the center point of the rectangle.
  • left_top() -> 'Point': Returns the top-left corner point.
  • right_top() -> 'Point': Returns the top-right corner point.
  • right_bottom() -> 'Point': Returns the bottom-right corner point.
  • left_bottom() -> 'Point': Returns the bottom-left corner point.

RGB Class

The RGB class represents a color in the RGB color model.

Attributes

  • r: Red component (integer between 0 and 255).
  • g: Green component (integer between 0 and 255).
  • b: Blue component (integer between 0 and 255).

Methods

  • is_similar(other: 'RGB', threshold: int = 4) -> bool: Checks if two RGB colors are similar within a threshold.
  • __hex__() -> str: Converts the RGB color to a hexadecimal string.
  • from_hex(hex_str: str) -> 'RGB': Creates an RGB object from a hexadecimal string.
  • hex() -> str: Returns the hexadecimal representation of the color.
  • __int__() -> int: Converts the RGB object to an integer representation.
  • from_int(color: int) -> 'RGB': Creates an RGB object from an integer value.
  • int() -> int: Returns the integer representation of the color.

Size Class

The Size class represents the dimensions of an object.

Attributes

  • width: The width of the object (greater than zero).
  • height: The height of the object (greater than zero).

Methods

  • area() -> int: Calculates the area of the size.

Usage Example

point = Point(x=5, y=10)
rectangle = Rect(x=0, y=0, w=10, h=20)
color = RGB(r=255, g=0, b=0)
size = Size(width=10, height=20)

# Check if point is in rectangle
is_inside = point.is_in_rect(rectangle)

# Calculate area of size
area = size.area()

This documentation should serve as a comprehensive guide to understanding and using the defined classes.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mcore-0.0.2.tar.gz (3.6 kB view details)

Uploaded Source

Built Distribution

mcore-0.0.2-py3-none-any.whl (3.7 kB view details)

Uploaded Python 3

File details

Details for the file mcore-0.0.2.tar.gz.

File metadata

  • Download URL: mcore-0.0.2.tar.gz
  • Upload date:
  • Size: 3.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.9

File hashes

Hashes for mcore-0.0.2.tar.gz
Algorithm Hash digest
SHA256 1a2fbe3adfddb651446953179261d11026e8810a17c4b939f37e85686e67d209
MD5 cddda0c2c333597bfc2fa95943637836
BLAKE2b-256 323c7dce7617f75395c24d6914a4d6fa5a18cb952e6fb2670dcd00b234db56dd

See more details on using hashes here.

File details

Details for the file mcore-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: mcore-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 3.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.9

File hashes

Hashes for mcore-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 5b6ff8716ea4a4b3d7079de232be213cd001b76773d59e4a0d54f9f8ba316596
MD5 ad196be3d0091bf17439828ae3ed3ea9
BLAKE2b-256 0d343f90617f731166aadd2c934aca0d51fd7b4d6c8fb9ab6764348fed2d16e8

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page