Create an ordering for everything
In order to make layouts more reproducible Also add pattern.sort() and file.utils.preflight_check() optionally don't sort elements elements aren't re-ordered that often, sorting them is slow, and the sort criteria are arbitrary, so we might want to only sort stuff by name
This commit is contained in:
parent
94aa853a49
commit
6db4bb96db
16 changed files with 653 additions and 24 deletions
|
|
@ -1,7 +1,8 @@
|
|||
from typing import Iterable, KeysView, ValuesView, overload, Self, Mapping, NoReturn
|
||||
from typing import Iterable, KeysView, ValuesView, overload, Self, Mapping, NoReturn, Any
|
||||
import warnings
|
||||
import traceback
|
||||
import logging
|
||||
import functools
|
||||
from collections import Counter
|
||||
from abc import ABCMeta, abstractmethod
|
||||
from itertools import chain
|
||||
|
|
@ -18,6 +19,7 @@ from .error import PortError
|
|||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@functools.total_ordering
|
||||
class Port(PositionableImpl, Rotatable, PivotableImpl, Copyable, Mirrorable):
|
||||
"""
|
||||
A point at which a `Device` can be snapped to another `Device`.
|
||||
|
|
@ -121,6 +123,27 @@ class Port(PositionableImpl, Rotatable, PivotableImpl, Copyable, Mirrorable):
|
|||
rot = str(numpy.rad2deg(self.rotation))
|
||||
return f'<{self.offset}, {rot}, [{self.ptype}]>'
|
||||
|
||||
def __lt__(self, other: 'Port') -> bool:
|
||||
if self.ptype != other.ptype:
|
||||
return self.ptype < other.ptype
|
||||
if not numpy.array_equal(self.offset, other.offset):
|
||||
return tuple(self.offset) < tuple(other.offset)
|
||||
if self.rotation != other.rotation:
|
||||
if self.rotation is None:
|
||||
return True
|
||||
if other.rotation is None:
|
||||
return False
|
||||
return self.rotation < other.rotation
|
||||
return False
|
||||
|
||||
def __eq__(self, other: Any) -> bool:
|
||||
return (
|
||||
type(self) is type(other)
|
||||
and self.ptype == other.ptype
|
||||
and numpy.array_equal(self.offset, other.offset)
|
||||
and self.rotation == other.rotation
|
||||
)
|
||||
|
||||
|
||||
class PortList(metaclass=ABCMeta):
|
||||
__slots__ = () # Allow subclasses to use __slots__
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue