Formatted filles

This commit is contained in:
Peter Yefi 2021-10-19 13:58:46 +00:00
parent ba72bd9043
commit 9c2b4ca7ef
3 changed files with 743 additions and 735 deletions

View File

@ -4,7 +4,6 @@ SPDX - License - Identifier: LGPL - 3.0 - or -later
Copyright © 2020 Project Author Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca
"""
from __future__ import annotations
import math
import sys
@ -72,11 +71,11 @@ class Polygon:
"""
if self._edges is None:
self._edges = []
for i in range(0, len(self.points)-1):
for i in range(0, len(self.points) - 1):
point_1 = self.points[i]
point_2 = self.points[i+1]
point_2 = self.points[i + 1]
self._edges.append([point_1, point_2])
self._edges.append([self.points[len(self.points)-1], self.points[0]])
self._edges.append([self.points[len(self.points) - 1], self.points[0]])
return self._edges
@property
@ -100,12 +99,12 @@ class Polygon:
return 0
horizontal_points = self._points_rotated_to_horizontal
area = 0
for i in range(0, len(horizontal_points)-1):
for i in range(0, len(horizontal_points) - 1):
point = horizontal_points[i]
next_point = horizontal_points[i+1]
next_point = horizontal_points[i + 1]
area += (next_point[1] + point[1]) / 2 * (next_point[0] - point[0])
next_point = horizontal_points[0]
point = horizontal_points[len(horizontal_points)-1]
point = horizontal_points[len(horizontal_points) - 1]
area += (next_point[1] + point[1]) / 2 * (next_point[0] - point[0])
self._area = abs(area)
return self._area
@ -157,8 +156,8 @@ class Polygon:
if self._normal is None:
points = self.coordinates
# todo: IF THE FIRST ONE IS 0, START WITH THE NEXT
point_origin = points[len(points)-2]
vector_1 = points[len(points)-1] - point_origin
point_origin = points[len(points) - 2]
vector_1 = points[len(points) - 1] - point_origin
vector_2 = points[0] - point_origin
vector_3 = points[1] - point_origin
cross_product = np.cross(vector_1, vector_2)
@ -173,9 +172,9 @@ class Polygon:
if np.linalg.norm(cross_product) == 0:
return cross_product
alpha += self._angle(vector_2, vector_3, cross_product)
for i in range(0, len(points)-4):
vector_1 = points[i+1] - point_origin
vector_2 = points[i+2] - point_origin
for i in range(0, len(points) - 4):
vector_1 = points[i + 1] - point_origin
vector_2 = points[i + 2] - point_origin
alpha += self._angle(vector_1, vector_2, cross_product)
vector_1 = points[len(points) - 1] - point_origin
vector_2 = points[0] - point_origin
@ -242,25 +241,30 @@ class Polygon:
if self._is_ear(ear, rest_points):
ears.append(ear)
point_to_remove = concave_points[i]
previous_point_in_list, next_point_in_list = self._enveloping_points(point_to_remove, total_points_list)
previous_point_in_list, next_point_in_list = self._enveloping_points(point_to_remove,
total_points_list)
total_points_list.remove(point_to_remove)
concave_points.remove(point_to_remove)
# Was any of the adjacent points convex? -> check if changed status to concave
for convex_point in convex_points:
if convex_point == previous_point_in_list:
concave_points, convex_points, end_loop = self._if_concave_change_status(normal, points_list,
concave_points, convex_points, end_loop = self._if_concave_change_status(normal,
points_list,
convex_point,
total_points_list,
concave_points, convex_points,
concave_points,
convex_points,
previous_point_in_list)
if end_loop:
break
continue
if convex_point == next_point_in_list:
concave_points, convex_points, end_loop = self._if_concave_change_status(normal, points_list,
concave_points, convex_points, end_loop = self._if_concave_change_status(normal,
points_list,
convex_point,
total_points_list,
concave_points, convex_points,
concave_points,
convex_points,
next_point_in_list)
if end_loop:
break
@ -300,11 +304,11 @@ class Polygon:
else:
convex_points.append(index)
# case 2: all points except first and last
for i in range(0, int((len(points_list)-6)/3)):
point = points_list[(i+1)*3:(i+2)*3]
previous_point = points_list[i*3:(i+1)*3]
next_point = points_list[(i+2)*3:(i+3)*3]
index = i+1
for i in range(0, int((len(points_list) - 6) / 3)):
point = points_list[(i + 1) * 3:(i + 2) * 3]
previous_point = points_list[i * 3:(i + 1) * 3]
next_point = points_list[(i + 2) * 3:(i + 3) * 3]
index = i + 1
total_points_list.append(index)
if Polygon._point_is_concave(normal, point, previous_point, next_point):
concave_points.append(index)
@ -314,7 +318,7 @@ class Polygon:
point = points_list[len(points_list) - 3:]
previous_point = points_list[len(points_list) - 6:len(points_list) - 3]
next_point = points_list[0:3]
index = int(len(points_list)/3) - 1
index = int(len(points_list) / 3) - 1
total_points_list.append(index)
if Polygon._point_is_concave(normal, point, previous_point, next_point):
concave_points.append(index)
@ -358,7 +362,7 @@ class Polygon:
if point_position == total_points_list[len(total_points_list) - 1]:
previous_point_index = total_points_list[len(total_points_list) - 2] * 3
next_point_index = total_points_list[0] * 3
for i in range(1, len(total_points_list)-1):
for i in range(1, len(total_points_list) - 1):
if point_position == total_points_list[i]:
previous_point_index = total_points_list[i - 1] * 3
next_point_index = total_points_list[i + 1] * 3
@ -495,9 +499,9 @@ class Polygon:
sys.stderr.write("Warning: impossible to calculate angle between planes' normal. Return 0\n")
return 0
cosine = np.dot(vec_1, vec_2) / np.linalg.norm(vec_1) / np.linalg.norm(vec_2)
if cosine > 1 and cosine-1 < 1e-5:
if cosine > 1 and cosine - 1 < 1e-5:
cosine = 1
elif cosine < -1 and cosine+1 > -1e-5:
elif cosine < -1 and cosine + 1 > -1e-5:
cosine = -1
alpha = math.acos(cosine)
return alpha
@ -546,8 +550,9 @@ class Polygon:
@staticmethod
def _edge_in_edges_list(edge, edges_list):
for edge_element in edges_list:
if (edge_element[0].distance_to_point(edge[0]) == 0 and edge_element[1].distance_to_point(edge[1]) == 0) or\
(edge_element[1].distance_to_point(edge[0]) == 0 and edge_element[0].distance_to_point(edge[1]) == 0):
if (edge_element[0].distance_to_point(edge[0]) == 0 and edge_element[1].distance_to_point(edge[1]) == 0) or \
(edge_element[1].distance_to_point(edge[0]) == 0 and edge_element[0].distance_to_point(
edge[1]) == 0):
return True
return False
@ -558,10 +563,10 @@ class Polygon:
for _ in range(0, len(points)):
for i in range(1, len(edges_list)):
point_1 = edges_list[i][0]
point_2 = points[len(points)-1]
point_2 = points[len(points) - 1]
if point_1.distance_to_point(point_2) == 0:
points.append(edges_list[i][1])
points.remove(points[len(points)-1])
points.remove(points[len(points) - 1])
array_points = []
for point in points:
array_points.append(point.coordinates)
@ -571,8 +576,10 @@ class Polygon:
def _remove_from_list(edge, edges_list):
new_list = []
for edge_element in edges_list:
if not((edge_element[0].distance_to_point(edge[0]) == 0 and edge_element[1].distance_to_point(edge[1]) == 0) or
(edge_element[1].distance_to_point(edge[0]) == 0 and edge_element[0].distance_to_point(edge[1]) == 0)):
if not ((edge_element[0].distance_to_point(edge[0]) == 0 and edge_element[1].distance_to_point(
edge[1]) == 0) or
(edge_element[1].distance_to_point(edge[0]) == 0 and edge_element[0].distance_to_point(
edge[1]) == 0)):
new_list.append(edge_element)
return new_list

View File

@ -12,6 +12,7 @@ class Schedule:
"""
Schedule class
"""
def __init__(self):
self._id = None
self._type = None