Update draw function ConvexHull
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
83
algorithm.py
83
algorithm.py
@@ -47,6 +47,9 @@ class Algorithm():
|
||||
def is_running(self):
|
||||
"""Return if the algorithm is running."""
|
||||
return self._running
|
||||
def get_section(self):
|
||||
"""Return the current section name of the algorithm."""
|
||||
return self._section
|
||||
def get_result(self):
|
||||
"""Return the result of the algorithm."""
|
||||
return self._result
|
||||
@@ -275,6 +278,7 @@ class ConvexHullIncremental(Algorithm):
|
||||
super().step()
|
||||
if len(self._es) == 0:
|
||||
self._es = copy.deepcopy(self._result["lt"])
|
||||
# self._result["lt"] = []
|
||||
self._section = "sweep-left-to-top"
|
||||
|
||||
elif self._section == "sweep-left-to-top":
|
||||
@@ -296,6 +300,7 @@ class ConvexHullIncremental(Algorithm):
|
||||
if len(self._es) == 0:
|
||||
self._result["lt"] = copy.deepcopy(self._sss["lt"])
|
||||
self._es = copy.deepcopy(self._result["lb"])
|
||||
# self._result["lb"] = []
|
||||
self._section = "sweep-left-to-bottom"
|
||||
|
||||
elif self._section == "sweep-left-to-bottom":
|
||||
@@ -317,6 +322,7 @@ class ConvexHullIncremental(Algorithm):
|
||||
if len(self._es) == 0:
|
||||
self._result["lb"] = copy.deepcopy(self._sss["lb"])
|
||||
self._es = copy.deepcopy(self._result["rt"])
|
||||
# self._result["rt"] = []
|
||||
self._section = "sweep-right-to-top"
|
||||
|
||||
elif self._section == "sweep-right-to-top":
|
||||
@@ -338,6 +344,7 @@ class ConvexHullIncremental(Algorithm):
|
||||
if len(self._es) == 0:
|
||||
self._result["rt"] = copy.deepcopy(self._sss["rt"])
|
||||
self._es = copy.deepcopy(self._result["rb"])
|
||||
# self._result["rb"] = []
|
||||
self._section = "sweep-right-to-bottom"
|
||||
|
||||
elif self._section == "sweep-right-to-bottom":
|
||||
@@ -372,16 +379,86 @@ class ConvexHullIncremental(Algorithm):
|
||||
self._result["success"] = True
|
||||
self._running = False
|
||||
def draw(self, canvas, width, height, max_x, max_y):
|
||||
"""Draw the algorithms state on the canvas."""
|
||||
canvas.delete("all")
|
||||
if self._running:
|
||||
pass
|
||||
for i in range(len(self._result["lt"]) - 1):
|
||||
linesegment.LineSegment(self._result["lt"][i], self._result["lt"][i+1])\
|
||||
.draw(canvas, width, height, max_x, max_y, "#000000")
|
||||
for i in range(len(self._result["lb"]) - 1):
|
||||
linesegment.LineSegment(self._result["lb"][i], self._result["lb"][i+1])\
|
||||
.draw(canvas, width, height, max_x, max_y, "#000000")
|
||||
for i in range(len(self._result["rt"]) - 1):
|
||||
linesegment.LineSegment(self._result["rt"][i], self._result["rt"][i+1])\
|
||||
.draw(canvas, width, height, max_x, max_y, "#000000")
|
||||
for i in range(len(self._result["rb"]) - 1):
|
||||
linesegment.LineSegment(self._result["rb"][i], self._result["rb"][i+1])\
|
||||
.draw(canvas, width, height, max_x, max_y, "#000000")
|
||||
if self._section == "sweep-left-to-right" or \
|
||||
self._section == "sweep-right-to-left":
|
||||
if len(self._es) > 0:
|
||||
if self._section == "sweep-left-to-right":
|
||||
canvas.create_line(self._es[0].get_x() * width / max_x, 0, \
|
||||
self._es[0].get_x() * width / max_x, height, fill="#0000FF")
|
||||
else:
|
||||
canvas.create_line(self._es[-1].get_x() * width / max_x, 0, \
|
||||
self._es[-1].get_x() * width / max_x, height, fill="#0000FF")
|
||||
for pnt in self._input:
|
||||
if pnt in self._result["lt"] or \
|
||||
pnt in self._result["lb"] or \
|
||||
pnt in self._result["rt"] or \
|
||||
pnt in self._result["rb"]:
|
||||
pnt.draw(canvas, width, height, max_x, max_y, "#FF0000")
|
||||
elif pnt in self._es:
|
||||
pnt.draw(canvas, width, height, max_x, max_y, "#000000")
|
||||
else:
|
||||
pnt.draw(canvas, width, height, max_x, max_y, "#777777")
|
||||
elif self._section == "sweep-left-to-top" or \
|
||||
self._section == "sweep-left-to-bottom" or \
|
||||
self._section == "sweep-right-to-top" or \
|
||||
self._section == "sweep-right-to-bottom":
|
||||
if len(self._es) > 0:
|
||||
canvas.create_line(self._es[0].get_x() * width / max_x, 0, \
|
||||
self._es[0].get_x() * width / max_x, height, fill="#0000FF")
|
||||
for pnt in self._input:
|
||||
if pnt in self._es:
|
||||
pnt.draw(canvas, width, height, max_x, max_y, "#FF0000")
|
||||
elif self._section == "sweep-left-to-top" and pnt in self._sss["lt"] or \
|
||||
self._section == "sweep-left-to-bottom" and pnt in self._sss["lb"] or \
|
||||
self._section == "sweep-right-to-top" and pnt in self._sss["rt"] or \
|
||||
self._section == "sweep-right-to-bottom" and pnt in self._sss["rb"]:
|
||||
pnt.draw(canvas, width, height, max_x, max_y, "#000000")
|
||||
# elif pnt in self._result["lt"] or \
|
||||
# pnt in self._result["lb"] or \
|
||||
# pnt in self._result["rt"] or \
|
||||
# pnt in self._result["rb"]:
|
||||
# pnt.draw(canvas, width, height, max_x, max_y, "#000000")
|
||||
else:
|
||||
pnt.draw(canvas, width, height, max_x, max_y, "#777777")
|
||||
if self._section == "sweep-left-to-top":
|
||||
for i in range(len(self._sss["lt"]) - 1):
|
||||
linesegment.LineSegment(self._sss["lt"][i], self._sss["lt"][i+1])\
|
||||
.draw(canvas, width, height, max_x, max_y, "#FF0000")
|
||||
elif self._section == "sweep-left-to-bottom":
|
||||
for i in range(len(self._sss["lb"]) - 1):
|
||||
linesegment.LineSegment(self._sss["lb"][i], self._sss["lb"][i+1])\
|
||||
.draw(canvas, width, height, max_x, max_y, "#FF0000")
|
||||
elif self._section == "sweep-right-to-top":
|
||||
for i in range(len(self._sss["rt"]) - 1):
|
||||
linesegment.LineSegment(self._sss["rt"][i], self._sss["rt"][i+1])\
|
||||
.draw(canvas, width, height, max_x, max_y, "#FF0000")
|
||||
elif self._section == "sweep-right-to-bottom":
|
||||
for i in range(len(self._sss["rb"]) - 1):
|
||||
linesegment.LineSegment(self._sss["rb"][i], self._sss["rb"][i+1])\
|
||||
.draw(canvas, width, height, max_x, max_y, "#FF0000")
|
||||
else:
|
||||
for i in range(len(self._result["hull"]) - 1):
|
||||
linesegment.LineSegment( \
|
||||
self._result["hull"][i], self._result["hull"][i+1]) \
|
||||
.draw(canvas, width, height, max_x, max_y, "#FF0000")
|
||||
.draw(canvas, width, height, max_x, max_y, "#000000")
|
||||
linesegment.LineSegment( \
|
||||
self._result["hull"][-1], self._result["hull"][0]) \
|
||||
.draw(canvas, width, height, max_x, max_y, "#FF0000")
|
||||
.draw(canvas, width, height, max_x, max_y, "#000000")
|
||||
for pnt in self._input:
|
||||
if pnt in self._result["hull"]:
|
||||
pnt.draw(canvas, width, height, max_x, max_y, "#000000")
|
||||
|
||||
Reference in New Issue
Block a user