]> Repositories - hackapet/Adafruit_Blinka_Displayio.git/blobdiff - displayio/_area.py
Bug fixes for SSD1306
[hackapet/Adafruit_Blinka_Displayio.git] / displayio / _area.py
index e5ab94410c0db76213c84d64792a1f6d45d4a698..f7272dd747bf25ae79ca94987ce278f0914b797a 100644 (file)
@@ -20,14 +20,14 @@ Area for Blinka Displayio
 
 from __future__ import annotations
 
-__version__ = "0.0.0-auto.0"
+__version__ = "0.0.0+auto.0"
 __repo__ = "https://github.com/adafruit/Adafruit_Blinka_Displayio.git"
 
 
 class Area:
-    # pylint: disable=invalid-name,missing-function-docstring
-    """Area Class to represent an area to be updated. Currently not used."""
+    """Area Class to represent an area to be updated."""
 
+    # pylint: disable=invalid-name
     def __init__(self, x1: int = 0, y1: int = 0, x2: int = 0, y2: int = 0):
         self.x1 = x1
         self.y1 = y1
@@ -38,25 +38,29 @@ class Area:
     def __str__(self):
         return f"Area TL({self.x1},{self.y1}) BR({self.x2},{self.y2})"
 
-    def _copy_into(self, dst) -> None:
+    def copy_into(self, dst) -> None:
+        """Copy the area into another area."""
         dst.x1 = self.x1
         dst.y1 = self.y1
         dst.x2 = self.x2
         dst.y2 = self.y2
 
-    def _scale(self, scale: int) -> None:
+    def scale(self, scale: int) -> None:
+        """Scale the area by scale."""
         self.x1 *= scale
         self.y1 *= scale
         self.x2 *= scale
         self.y2 *= scale
 
-    def _shift(self, dx: int, dy: int) -> None:
+    def shift(self, dx: int, dy: int) -> None:
+        """Shift the area by dx and dy."""
         self.x1 += dx
         self.y1 += dy
         self.x2 += dx
         self.y2 += dy
 
-    def _compute_overlap(self, other, overlap) -> bool:
+    def compute_overlap(self, other, overlap) -> bool:
+        """Compute the overlap between two areas. Returns True if there is an overlap."""
         a = self
         overlap.x1 = max(a.x1, other.x1)
         overlap.x2 = min(a.x2, other.x2)
@@ -69,22 +73,24 @@ class Area:
 
         return overlap.y1 < overlap.y2
 
-    def _empty(self):
+    def empty(self):
+        """Return True if the area is empty."""
         return (self.x1 == self.x2) or (self.y1 == self.y2)
 
-    def _canon(self):
+    def canon(self):
+        """Make sure the area is in canonical form."""
         if self.x1 > self.x2:
             self.x1, self.x2 = self.x2, self.x1
         if self.y1 > self.y2:
             self.y1, self.y2 = self.y2, self.y1
 
-    def _union(self, other, union):
-        # pylint: disable=protected-access
-        if self._empty():
-            self._copy_into(union)
+    def union(self, other, union):
+        """Combine this area along with another into union"""
+        if self.empty():
+            self.copy_into(union)
             return
-        if other._empty():
-            other._copy_into(union)
+        if other.empty():
+            other.copy_into(union)
             return
 
         union.x1 = min(self.x1, other.x1)
@@ -93,12 +99,15 @@ class Area:
         union.y2 = max(self.y2, other.y2)
 
     def width(self) -> int:
+        """Return the width of the area."""
         return self.x2 - self.x1
 
     def height(self) -> int:
+        """Return the height of the area."""
         return self.y2 - self.y1
 
     def size(self) -> int:
+        """Return the size of the area."""
         return self.width() * self.height()
 
     def __eq__(self, other):
@@ -113,7 +122,7 @@ class Area:
         )
 
     @staticmethod
-    def _transform_within(
+    def transform_within(
         mirror_x: bool,
         mirror_y: bool,
         transpose_xy: bool,
@@ -121,6 +130,7 @@ class Area:
         whole: Area,
         transformed: Area,
     ):
+        """Transform an area within a larger area."""
         # pylint: disable=too-many-arguments
         # Original and whole must be in the same coordinate space.
         if mirror_x: