removed remove_last parameter

This commit is contained in:
Pilar 2021-03-08 12:56:19 -05:00
parent dbd32e4d20
commit a9abb59835
3 changed files with 45 additions and 53 deletions

View File

@ -16,17 +16,17 @@ class Surface:
""" """
Surface class Surface class
""" """
def __init__(self, coordinates, holes_coordinates=None, surface_type=None, name=None, swr='0.2', remove_last=True): def __init__(self, coordinates, holes_coordinates=None, surface_type=None, name=None, swr='0.2'):
self._coordinates = coordinates self._coordinates = coordinates
self._holes_coordinates = holes_coordinates self._holes_coordinates = holes_coordinates
self._type = surface_type self._type = surface_type
self._name = name self._name = name
self._swr = swr self._swr = swr
self._remove_last = remove_last
self._points = None self._points = None
self._points_list = None self._points_list = None
self._holes_points = None self._holes_points = None
self._holes_points_list = None self._holes_points_list = None
self._perimeter_points = None
self._azimuth = None self._azimuth = None
self._inclination = None self._inclination = None
self._area_above_ground = None self._area_above_ground = None
@ -40,7 +40,6 @@ class Surface:
self._perimeter_surface = None self._perimeter_surface = None
self._hole_surfaces = None self._hole_surfaces = None
self._solid_surface = None self._solid_surface = None
self._perimeter_vertices = None
def parent(self, parent, surface_id): def parent(self, parent, surface_id):
""" """
@ -82,32 +81,32 @@ class Surface:
@property @property
def points(self) -> np.ndarray: def points(self) -> np.ndarray:
""" """
Surface point coordinates list [x, y, z, x, y, z,...] Solid surface point matrix [[x, y, z],[x, y, z],...]
:return: np.ndarray :return: np.ndarray
""" """
if self._points is None: if self._points is None:
self._points = np.fromstring(self._coordinates, dtype=float, sep=' ') self._points = np.fromstring(self._coordinates, dtype=float, sep=' ')
self._points = gh.to_points_matrix(self._points, self._remove_last) self._points = gh.to_points_matrix(self._points)
return self._points return self._points
@property @property
def holes_points(self) -> [np.ndarray]: def holes_points(self) -> [np.ndarray]:
""" """
Surface point coordinates list [x, y, z, x, y, z,...] Holes surfaces point matrices [[[x, y, z],[x, y, z],...]]
:return: np.ndarray :return: np.ndarray
""" """
if self._holes_coordinates is not None: if self._holes_coordinates is not None:
self._holes_points = [] self._holes_points = []
for hole_coordinates in self._holes_coordinates: for hole_coordinates in self._holes_coordinates:
hole_points = np.fromstring(hole_coordinates, dtype=float, sep=' ') hole_points = np.fromstring(hole_coordinates, dtype=float, sep=' ')
hole_points = gh.to_points_matrix(hole_points, self._remove_last) hole_points = gh.to_points_matrix(hole_points)
self._holes_points.append(hole_points) self._holes_points.append(hole_points)
return self._holes_points return self._holes_points
@property @property
def points_list(self) -> np.ndarray: def points_list(self) -> np.ndarray:
""" """
Surface point matrix [[x, y, z],[x, y, z],...] Solid surface point coordinates list [x, y, z, x, y, z,...]
:return: np.ndarray :return: np.ndarray
""" """
if self._points_list is None: if self._points_list is None:
@ -118,7 +117,7 @@ class Surface:
@property @property
def holes_points_list(self) -> np.ndarray: def holes_points_list(self) -> np.ndarray:
""" """
Surface point matrix [[x, y, z],[x, y, z],...] Holes surfaces point coordinates list [x, y, z, x, y, z,...]
:return: np.ndarray :return: np.ndarray
""" """
if self._holes_coordinates is not None: if self._holes_coordinates is not None:
@ -274,7 +273,7 @@ class Surface:
:return: Polygon :return: Polygon
""" """
if self._perimeter_surface is None: if self._perimeter_surface is None:
self._perimeter_surface = Polygon(self.perimeter_vertices) self._perimeter_surface = Polygon(self.perimeter_points)
return self._perimeter_surface return self._perimeter_surface
@property @property
@ -301,43 +300,37 @@ class Surface:
self._hole_surfaces = None self._hole_surfaces = None
else: else:
self._hole_surfaces = [] self._hole_surfaces = []
for hole_vertices in self.holes_points: for hole_points in self.holes_points:
self._hole_surfaces.append(Polygon(hole_vertices)) self._hole_surfaces.append(Polygon(hole_points))
return self._hole_surfaces return self._hole_surfaces
@property @property
def perimeter_vertices(self) -> np.ndarray: def perimeter_points(self) -> np.ndarray:
""" """
vertices of the perimeter organized in the same order as in coordinates Matrix of points of the perimeter in the same order as in coordinates [[x, y, z],[x, y, z],...]
:return: :return: np.ndarray
""" """
if self._perimeter_vertices is None: if self._perimeter_points is None:
if self.holes_points is None: if self.holes_points is None:
self._perimeter_vertices = self.points self._perimeter_points = self.points
else: else:
first_point = True _perimeter_coordinates = self._coordinates
for point in self.points:
point_of_hole = False
for hole_points in self.holes_points: for hole_points in self.holes_points:
for hole_point in hole_points: _hole = np.append(hole_points, hole_points[0])
if gh().almost_equal(0.0, point, hole_point): _closed_hole = ' '.join(str(e) for e in [*_hole[:]])
point_of_hole = True # add a mark 'M' to ensure that the recombination of points does not provoke errors in finding holes
if not point_of_hole: _perimeter_coordinates = _perimeter_coordinates.replace(_closed_hole, 'M')
if first_point: _perimeter_coordinates = _perimeter_coordinates.replace('M', '')
self._perimeter_vertices = np.array([point]) self._perimeter_points = np.fromstring(_perimeter_coordinates, dtype=float, sep=' ')
first_point = False self._perimeter_points = gh.to_points_matrix(self._perimeter_points)
else:
self._perimeter_vertices = np.append(self._perimeter_vertices, [point], axis=0)
# remove duplicated points # remove duplicated points
pv = np.array([self._perimeter_vertices[0]]) pv = np.array([self._perimeter_points[0]])
for point in self._perimeter_vertices: for point in self._perimeter_points:
duplicated_point = False duplicated_point = False
for p in pv: for p in pv:
if gh().almost_equal(0.0, p, point): if gh().almost_equal(0.0, p, point):
duplicated_point = True duplicated_point = True
if not duplicated_point: if not duplicated_point:
pv = np.append(pv, [point], axis=0) pv = np.append(pv, [point], axis=0)
self._perimeter_vertices = pv self._perimeter_points = pv
if not self._remove_last: return self._perimeter_points
self._perimeter_vertices = np.append(self._perimeter_vertices, [self._perimeter_vertices[0]], axis=0)
return self._perimeter_vertices

View File

@ -2,7 +2,7 @@
Geometry helper Geometry helper
SPDX - License - Identifier: LGPL - 3.0 - or -later SPDX - License - Identifier: LGPL - 3.0 - or -later
Copyright © 2020 Project Author Guille Gutierrez guillermo.gutierrezmorote@concordia.ca Copyright © 2020 Project Author Guille Gutierrez guillermo.gutierrezmorote@concordia.ca
Contributors Pilar Monsalvete pilar_monsalvete@yahoo.es Contributors Pilar Monsalvete Álvarez de Uribarri pilar.monsalvete@concordia.ca
""" """
import sys import sys
import math import math
@ -99,17 +99,14 @@ class GeometryHelper:
return True return True
@staticmethod @staticmethod
def to_points_matrix(points, remove_last=False): def to_points_matrix(points):
""" """
Transform a point vector into a point matrix Transform a point vector into a point matrix
:param points: [x, y, z, x, y, z ...] :param points: [x, y, z, x, y, z ...]
:param remove_last: Boolean
:return: [[x,y,z],[x,y,z]...] :return: [[x,y,z],[x,y,z]...]
""" """
rows = points.size // 3 rows = points.size // 3
points = points.reshape(rows, 3) points = points.reshape(rows, 3)
if remove_last:
points = np.delete(points, rows - 1, 0)
return points return points
@staticmethod @staticmethod

View File

@ -249,16 +249,18 @@ class TestGeometryFactory(TestCase):
def test_surface(self): def test_surface(self):
coordinates = '0.0 0.0 0.0 0.0 4.0 0.0 4.0 4.0 0.0 4.0 0.0 0.0 0.0 0.0 0.0 ' \ coordinates = '0.0 0.0 0.0 0.0 4.0 0.0 4.0 4.0 0.0 4.0 0.0 0.0 0.0 0.0 0.0 ' \
'1.0 1.0 0.0 2.0 1.0 0.0 2.0 2.0 0.0 1.0 2.0 0.0 1.0 1.0 0.0 0.0 0.0 0.0 ' \ '1.0 1.0 0.0 2.0 1.0 0.0 2.0 2.0 0.0 1.0 2.0 0.0 1.0 1.0 0.0 0.0 0.0 0.0 ' \
'2.0 2.0 0.0 3.0 2.0 0.0 3.0 3.0 0.0 2.0 3.0 0.0 2.0 2.0 0.0 0.0 0.0 0.0' '2.0 2.0 0.0 3.0 2.0 0.0 3.0 3.0 0.0 2.0 3.0 0.0 2.0 2.0 0.0'
holes_coordinates = ['1.0 1.0 0.0 2.0 1.0 0.0 2.0 2.0 0.0 1.0 2.0 0.0 1.0 1.0 0.0', holes_coordinates = ['1.0 1.0 0.0 2.0 1.0 0.0 2.0 2.0 0.0 1.0 2.0 0.0',
'2.0 2.0 0.0 3.0 2.0 0.0 3.0 3.0 0.0 2.0 3.0 0.0 2.0 2.0 0.0'] '2.0 2.0 0.0 3.0 2.0 0.0 3.0 3.0 0.0 2.0 3.0 0.0']
surface = Surface(coordinates, holes_coordinates=holes_coordinates, remove_last=True) surface = Surface(coordinates, holes_coordinates=holes_coordinates)
print(surface.points) print('solid:', surface.points)
print(surface.holes_points) print(surface.holes_points)
print(surface.perimeter_vertices) print('perimeter:', surface.perimeter_points)
print(surface.hole_surfaces[1].area) for i in range(0, len(holes_coordinates)):
print(surface.perimeter_surface.area) print(surface.hole_surfaces[i].area)
print(surface.solid_surface.area) print('perimeter:', surface.perimeter_surface.area)
print(surface.hole_surfaces[1].normal) print('solid:', surface.solid_surface.area)
print(surface.perimeter_surface.normal) for i in range(0, len(holes_coordinates)):
print(surface.solid_surface.normal) print(surface.hole_surfaces[i].normal)
print('perimeter:', surface.perimeter_surface.normal)
print('solid:', surface.solid_surface.normal)