Skip to content

Commit

Permalink
'Refactored by Sourcery' (#414)
Browse files Browse the repository at this point in the history
Co-authored-by: Sourcery AI <>
  • Loading branch information
sourcery-ai[bot] authored Mar 17, 2022
1 parent 091705b commit c72f0d4
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 11 deletions.
2 changes: 1 addition & 1 deletion gaphas/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ def distance_rectangle_point(rect: Rect | Rectangle, point: Point) -> float:
"""Return the distance (fast) from a rectangle ``(x, y, width,height)`` to
a ``point``."""
d = distance_rectangle_border_point(rect, point)
return 0 if d < 0 else d
return max(d, 0)


def point_on_rectangle(
Expand Down
9 changes: 2 additions & 7 deletions gaphas/handlemove.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ def start_move(self, pos: Pos) -> None:
self.last_x, self.last_y = pos
model = self.view.model
assert model
cinfo = model.connections.get_connection(self.handle)
if cinfo:
if cinfo := model.connections.get_connection(self.handle):
self.handle.glued = True
model.connections.solver.remove_constraint(cinfo.constraint)

Expand Down Expand Up @@ -102,11 +101,7 @@ def connect(self, pos: Pos) -> None:
connections = model.connections
connector = Connector(self.item, handle, connections)

# find connectable item and its port
sink = self.glue(pos)

# no new connectable item, then diconnect and exit
if sink:
if sink := self.glue(pos):
connector.connect(sink)
else:
cinfo = connections.get_connection(handle)
Expand Down
6 changes: 3 additions & 3 deletions gaphas/item.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,10 +363,10 @@ def _update_ports(self) -> None:
used when initializing the line.
"""
assert len(self._handles) >= 2, "Not enough segments"
self._ports = []
handles = self._handles
for h1, h2 in zip(handles[:-1], handles[1:]):
self._ports.append(LinePort(h1.pos, h2.pos))
self._ports = [
LinePort(h1.pos, h2.pos) for h1, h2 in zip(handles[:-1], handles[1:])
]

def opposite(self, handle: Handle) -> Handle:
"""Given the handle of one end of the line, return the other end."""
Expand Down

0 comments on commit c72f0d4

Please sign in to comment.