Skip to content

Commit

Permalink
big fix and optimizations!
Browse files Browse the repository at this point in the history
  • Loading branch information
PycraftDeveloper committed Nov 4, 2024
1 parent cfee5a7 commit b870222
Show file tree
Hide file tree
Showing 2 changed files with 165 additions and 11 deletions.
173 changes: 164 additions & 9 deletions python_src/draw.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,30 @@ def get_end(self, format=_Constants.CONVENTIONAL_COORDINATES):
return self._end.get_coordinates(format=format)

def set_color(self, color, format=_Constants.RGB):
color_input_type = type(color)
if self._color.get_color_set():
if format == _Constants.RGB:
original_color = self._color.get_color(format=_Constants.RGB)
if color_input_type == _ColorConverter:
new_color = color.get_color(format=_Constants.RGB)
else:
new_color = [int(color[0]), int(color[1]), int(color[2])]

if new_color[0] == original_color[0] and new_color[1] == original_color[1] and new_color[2] == original_color[2]:
return

elif format == _Constants.RGBA:
original_color = self._color.get_color(format=_Constants.RGBA)
if color_input_type == _ColorConverter:
new_color = color.get_color(format=_Constants.RGBA)
else:
new_color = [int(color[0]), int(color[1]), int(color[2]), int(color[3])]

if new_color[0] == original_color[0] and new_color[1] == original_color[1] and new_color[2] == original_color[2] and new_color[3] == original_color[3]:
return

self._color_changed = True
if type(color) != _ColorConverter:
if color_input_type != _ColorConverter:
self._color.set_color(color, format=format)
else:
self._color = color
Expand Down Expand Up @@ -413,8 +435,30 @@ def get_radius(self, format=_Constants.CONVENTIONAL_COORDINATES):
return self._radius.get_point(format=format)

def set_color(self, color, format=_Constants.RGB):
color_input_type = type(color)
if self._color.get_color_set():
if format == _Constants.RGB:
original_color = self._color.get_color(format=_Constants.RGB)
if color_input_type == _ColorConverter:
new_color = color.get_color(format=_Constants.RGB)
else:
new_color = [int(color[0]), int(color[1]), int(color[2])]

if new_color[0] == original_color[0] and new_color[1] == original_color[1] and new_color[2] == original_color[2]:
return

elif format == _Constants.RGBA:
original_color = self._color.get_color(format=_Constants.RGBA)
if color_input_type == _ColorConverter:
new_color = color.get_color(format=_Constants.RGBA)
else:
new_color = [int(color[0]), int(color[1]), int(color[2]), int(color[3])]

if new_color[0] == original_color[0] and new_color[1] == original_color[1] and new_color[2] == original_color[2] and new_color[3] == original_color[3]:
return

self._color_changed = True
if type(color) != _ColorConverter:
if color_input_type != _ColorConverter:
self._color.set_color(color, format=format)
else:
self._color = color
Expand Down Expand Up @@ -610,8 +654,30 @@ def get_size(self, format=_Constants.CONVENTIONAL_COORDINATES):
return [self._x_size.get_point(format=format), self._y_size.get_point(format=format)]

def set_color(self, color, format=_Constants.RGB):
color_input_type = type(color)
if self._color.get_color_set():
if format == _Constants.RGB:
original_color = self._color.get_color(format=_Constants.RGB)
if color_input_type == _ColorConverter:
new_color = color.get_color(format=_Constants.RGB)
else:
new_color = [int(color[0]), int(color[1]), int(color[2])]

if new_color[0] == original_color[0] and new_color[1] == original_color[1] and new_color[2] == original_color[2]:
return

elif format == _Constants.RGBA:
original_color = self._color.get_color(format=_Constants.RGBA)
if color_input_type == _ColorConverter:
new_color = color.get_color(format=_Constants.RGBA)
else:
new_color = [int(color[0]), int(color[1]), int(color[2]), int(color[3])]

if new_color[0] == original_color[0] and new_color[1] == original_color[1] and new_color[2] == original_color[2] and new_color[3] == original_color[3]:
return

self._color_changed = True
if type(color) != _ColorConverter:
if color_input_type != _ColorConverter:
self._color.set_color(color, format=format)
else:
self._color = color
Expand Down Expand Up @@ -880,8 +946,30 @@ def get_radius(self, format=_Constants.CONVENTIONAL_COORDINATES):
return self._radius.get_point(format=format)

def set_color(self, color, format=_Constants.RGB):
color_input_type = type(color)
if self._color.get_color_set():
if format == _Constants.RGB:
original_color = self._color.get_color(format=_Constants.RGB)
if color_input_type == _ColorConverter:
new_color = color.get_color(format=_Constants.RGB)
else:
new_color = [int(color[0]), int(color[1]), int(color[2])]

if new_color[0] == original_color[0] and new_color[1] == original_color[1] and new_color[2] == original_color[2]:
return

elif format == _Constants.RGBA:
original_color = self._color.get_color(format=_Constants.RGBA)
if color_input_type == _ColorConverter:
new_color = color.get_color(format=_Constants.RGBA)
else:
new_color = [int(color[0]), int(color[1]), int(color[2]), int(color[3])]

if new_color[0] == original_color[0] and new_color[1] == original_color[1] and new_color[2] == original_color[2] and new_color[3] == original_color[3]:
return

self._color_changed = True
if type(color) != _ColorConverter:
if color_input_type != _ColorConverter:
self._color.set_color(color, format=format)
else:
self._color = color
Expand Down Expand Up @@ -1115,8 +1203,30 @@ def get_size(self, format=_Constants.CONVENTIONAL_COORDINATES):
return [self._outer_x_size.get_coordinates(format=format), self._outer_y_size.get_coordinates(format=format)]

def set_color(self, color, format=_Constants.RGB):
color_input_type = type(color)
if self._color.get_color_set():
if format == _Constants.RGB:
original_color = self._color.get_color(format=_Constants.RGB)
if color_input_type == _ColorConverter:
new_color = color.get_color(format=_Constants.RGB)
else:
new_color = [int(color[0]), int(color[1]), int(color[2])]

if new_color[0] == original_color[0] and new_color[1] == original_color[1] and new_color[2] == original_color[2]:
return

elif format == _Constants.RGBA:
original_color = self._color.get_color(format=_Constants.RGBA)
if color_input_type == _ColorConverter:
new_color = color.get_color(format=_Constants.RGBA)
else:
new_color = [int(color[0]), int(color[1]), int(color[2]), int(color[3])]

if new_color[0] == original_color[0] and new_color[1] == original_color[1] and new_color[2] == original_color[2] and new_color[3] == original_color[3]:
return

self._color_changed = True
if type(color) != _ColorConverter:
if color_input_type != _ColorConverter:
self._color.set_color(color, format=format)
else:
self._color = color
Expand Down Expand Up @@ -1320,8 +1430,30 @@ def get_points(self, format=_Constants.CONVENTIONAL_COORDINATES):
return points

def set_color(self, color, format=_Constants.RGB):
color_input_type = type(color)
if self._color.get_color_set():
if format == _Constants.RGB:
original_color = self._color.get_color(format=_Constants.RGB)
if color_input_type == _ColorConverter:
new_color = color.get_color(format=_Constants.RGB)
else:
new_color = [int(color[0]), int(color[1]), int(color[2])]

if new_color[0] == original_color[0] and new_color[1] == original_color[1] and new_color[2] == original_color[2]:
return

elif format == _Constants.RGBA:
original_color = self._color.get_color(format=_Constants.RGBA)
if color_input_type == _ColorConverter:
new_color = color.get_color(format=_Constants.RGBA)
else:
new_color = [int(color[0]), int(color[1]), int(color[2]), int(color[3])]

if new_color[0] == original_color[0] and new_color[1] == original_color[1] and new_color[2] == original_color[2] and new_color[3] == original_color[3]:
return

self._color_changed = True
if type(color) != _ColorConverter:
if color_input_type != _ColorConverter:
self._color.set_color(color, format=format)
else:
self._color = color
Expand Down Expand Up @@ -1509,10 +1641,33 @@ def get_position(self, format=_Constants.CONVENTIONAL_COORDINATES):
return self._position.get_coordinates(format=format)

def set_color(self, color, format=_Constants.RGB):
if type(color) != _ColorConverter:
self._color_changed = self._color.set_color(color, format=format)
color_input_type = type(color)
if self._color.get_color_set():
if format == _Constants.RGB:
original_color = self._color.get_color(format=_Constants.RGB)
if color_input_type == _ColorConverter:
new_color = color.get_color(format=_Constants.RGB)
else:
new_color = [int(color[0]), int(color[1]), int(color[2])]

if new_color[0] == original_color[0] and new_color[1] == original_color[1] and new_color[2] == original_color[2]:
return

elif format == _Constants.RGBA:
original_color = self._color.get_color(format=_Constants.RGBA)
if color_input_type == _ColorConverter:
new_color = color.get_color(format=_Constants.RGBA)
else:
new_color = [int(color[0]), int(color[1]), int(color[2]), int(color[3])]

if new_color[0] == original_color[0] and new_color[1] == original_color[1] and new_color[2] == original_color[2] and new_color[3] == original_color[3]:
return

self._color_changed = True
if color_input_type != _ColorConverter:
self._color.set_color(color, format=format)
else:
self._color_changed = self._color.set_color(color.get_color(format=format))
self._color = color

def get_color(self, format=_Constants.RGB):
if self._color is not None:
Expand Down
3 changes: 1 addition & 2 deletions python_src/utility/general_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,7 @@ def quit(show_statistics=None, terminate_application=True):
for locations in path:
_Registry.profiler.dump_stats(locations)
else:
with open(path, "w") as file:
_Registry.profiler.dump_stats(file)
_Registry.profiler.dump_stats(path)

if _PassportIntermediary.passport_file_location is not None:
passport = {"components used": _PassportIntermediary.components_used}
Expand Down

0 comments on commit b870222

Please sign in to comment.