Skip to content

Commit

Permalink
add dependabot
Browse files Browse the repository at this point in the history
  • Loading branch information
StardustDL committed Jun 26, 2020
1 parent 48c2b5a commit 7aa3d45
Show file tree
Hide file tree
Showing 6 changed files with 149 additions and 125 deletions.
7 changes: 7 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: 2
updates:
- package-ecosystem: pip
directory: "/"
schedule:
interval: daily
open-pull-requests-limit: 3
13 changes: 13 additions & 0 deletions ImagingS/_Core.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from __future__ import annotations

from math import fabs


def feq(a: float, b: float) -> bool:
return fabs(a-b) < 1e-8


def fsign(a: float) -> int:
if feq(a, 0):
return 0
return 1 if a > 0 else -1
126 changes: 2 additions & 124 deletions ImagingS/_Point.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,11 @@
from __future__ import annotations

from math import fabs
from typing import Iterable, Optional, Tuple, Union
from typing import Tuple

import numpy as np

from ImagingS.serialization import PropertySerializable


def feq(a: float, b: float) -> bool:
return fabs(a-b) < 1e-8


def fsign(a: float) -> int:
if feq(a, 0):
return 0
return 1 if a > 0 else -1
from ImagingS import feq


class Point(PropertySerializable):
Expand Down Expand Up @@ -82,115 +72,3 @@ def fromHomogeneous(arr: np.ndarray) -> Point:
w = float(arr[2][0])
assert w != 0
return Point(float(arr[0][0]) / w, float(arr[1][0]) / w)


class Size(PropertySerializable):
def __init__(self, width: float = 0.0, height: float = 0.0) -> None:
super().__init__()
self.width = width
self.height = height

def __eq__(self, obj: Size) -> bool:
return self.width == obj.width and self.height == obj.height

def __repr__(self) -> str:
return f"Size({self.width}, {self.height})"

def asTuple(self) -> Tuple[float, float]:
return self.width, self.height

@property
def width(self) -> float:
return self._width

@width.setter
def width(self, value: float) -> None:
self._width = float(value)

@property
def height(self) -> float:
return self._height

@height.setter
def height(self, value: float) -> None:
self._height = float(value)


class Rect(PropertySerializable):
_infinite: Optional[Rect] = None

def __init__(self, origin: Optional[Point] = None, size: Optional[Size] = None) -> None:
super().__init__()
self.origin = origin if origin else Point()
self.size = size if size else Size()

@classmethod
def infinite(cls) -> Rect:
if cls._infinite is None:
cls._infinite = Rect.fromPoints(Point(
float("-inf"), float("-inf")), Point(float("inf"), float("inf")))
return cls._infinite

@staticmethod
def fromPoints(p1: Point, p2: Point) -> Rect:
x1, y1 = p1.asTuple()
x2, y2 = p2.asTuple()
xmin, xmax = min(x1, x2), max(x1, x2)
ymin, ymax = min(y1, y2), max(y1, y2)
return Rect(Point(xmin, ymin), Size(xmax - xmin, ymax - ymin))

def __eq__(self, obj: Rect) -> bool:
return self.origin == obj.origin and self.size == obj.size

def __repr__(self) -> str:
return f"Rect({self.origin}, {self.size})"

def __contains__(self, point: Point) -> bool:
delta = point - self.origin
return 0 <= delta.x <= self.size.width and 0 <= delta.y <= self.size.height

@property
def origin(self) -> Point:
return self._origin

@origin.setter
def origin(self, value: Point) -> None:
assert isinstance(value, Point)
self._origin = value

@property
def size(self) -> Size:
return self._size

@size.setter
def size(self, value: Size) -> None:
assert isinstance(value, Size)
self._size = value

def vertex(self) -> Point:
return Point(self.origin.x+self.size.width, self.origin.y+self.size.height)


class RectMeasurer:
def __init__(self) -> None:
super().__init__()
self._lx = float("inf")
self._ly = float("inf")
self._rx = float("-inf")
self._ry = float("-inf")

def result(self) -> Rect:
result = Rect.fromPoints(Point(
self._lx, self._ly), Point(self._rx, self._ry))
return result

def append(self, position: Union[Point, Iterable[Point]]) -> None:
if isinstance(position, Point):
x, y = position.asTuple()
self._lx = min(self._lx, x)
self._ly = min(self._ly, y)
self._rx = max(self._rx, x)
self._ry = max(self._ry, y)
else:
for p in position:
self.append(p)
86 changes: 86 additions & 0 deletions ImagingS/_Rect.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
from __future__ import annotations

from typing import Iterable, Optional, Union

from ImagingS.serialization import PropertySerializable
from ImagingS import Point, Size


class Rect(PropertySerializable):
_infinite: Optional[Rect] = None

def __init__(self, origin: Optional[Point] = None, size: Optional[Size] = None) -> None:
super().__init__()
self.origin = origin if origin else Point()
self.size = size if size else Size()

@classmethod
def infinite(cls) -> Rect:
if cls._infinite is None:
cls._infinite = Rect.fromPoints(Point(
float("-inf"), float("-inf")), Point(float("inf"), float("inf")))
return cls._infinite

@staticmethod
def fromPoints(p1: Point, p2: Point) -> Rect:
x1, y1 = p1.asTuple()
x2, y2 = p2.asTuple()
xmin, xmax = min(x1, x2), max(x1, x2)
ymin, ymax = min(y1, y2), max(y1, y2)
return Rect(Point(xmin, ymin), Size(xmax - xmin, ymax - ymin))

def __eq__(self, obj: Rect) -> bool:
return self.origin == obj.origin and self.size == obj.size

def __repr__(self) -> str:
return f"Rect({self.origin}, {self.size})"

def __contains__(self, point: Point) -> bool:
delta = point - self.origin
return 0 <= delta.x <= self.size.width and 0 <= delta.y <= self.size.height

@property
def origin(self) -> Point:
return self._origin

@origin.setter
def origin(self, value: Point) -> None:
assert isinstance(value, Point)
self._origin = value

@property
def size(self) -> Size:
return self._size

@size.setter
def size(self, value: Size) -> None:
assert isinstance(value, Size)
self._size = value

def vertex(self) -> Point:
return Point(self.origin.x+self.size.width, self.origin.y+self.size.height)


class RectMeasurer:
def __init__(self) -> None:
super().__init__()
self._lx = float("inf")
self._ly = float("inf")
self._rx = float("-inf")
self._ry = float("-inf")

def result(self) -> Rect:
result = Rect.fromPoints(Point(
self._lx, self._ly), Point(self._rx, self._ry))
return result

def append(self, position: Union[Point, Iterable[Point]]) -> None:
if isinstance(position, Point):
x, y = position.asTuple()
self._lx = min(self._lx, x)
self._ly = min(self._ly, y)
self._rx = max(self._rx, x)
self._ry = max(self._ry, y)
else:
for p in position:
self.append(p)
37 changes: 37 additions & 0 deletions ImagingS/_Size.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from __future__ import annotations

from typing import Tuple

from ImagingS.serialization import PropertySerializable


class Size(PropertySerializable):
def __init__(self, width: float = 0.0, height: float = 0.0) -> None:
super().__init__()
self.width = width
self.height = height

def __eq__(self, obj: Size) -> bool:
return self.width == obj.width and self.height == obj.height

def __repr__(self) -> str:
return f"Size({self.width}, {self.height})"

def asTuple(self) -> Tuple[float, float]:
return self.width, self.height

@property
def width(self) -> float:
return self._width

@width.setter
def width(self, value: float) -> None:
self._width = float(value)

@property
def height(self) -> float:
return self._height

@height.setter
def height(self, value: float) -> None:
self._height = float(value)
5 changes: 4 additions & 1 deletion ImagingS/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
from ._Core import feq, fsign
from ._Color import Color, Colors
from ._Point import Point, Rect, Size, feq, fsign, RectMeasurer
from ._Point import Point
from ._Size import Size
from ._Rect import Rect, RectMeasurer
from ._IdObject import IdObject, IdObjectList
from ._Cache import Cache

Expand Down

0 comments on commit 7aa3d45

Please sign in to comment.