def length(self) -> float: if self._length is None: length = 0 for v1, v2 in pairwise(self.points): length += v1.distance(v2) self._length = length return self._length
def flat_length(self) -> float: if self._flat_length is None: flat_length = 0 for v1, v2 in pairwise(self.points): flat_length += v1.vec2.distance(v2.vec2) self._flat_length = flat_length return self._flat_length
def centroid(self) -> Vector: try: return self._centroid except AttributeError: centroid = NULLVEC for p1, p2 in pairwise(self.points): centroid += p1.lerp(p2) self._centroid = centroid return centroid
def centroid(self): try: return self._centroid except AttributeError: points = [Vector(point) for point in self.entity.points()] centroid = NULLVEC for p1, p2 in pairwise(points): centroid += p1.lerp(p2) self._centroid = centroid return centroid
def inside_polygon(p, poly: List[List[float]]) -> bool: # проверка точка p внутри полигона или нет # TODO: use cv.polygonTest p = [round(coord, 2) for coord in p] boundary_area = round(polygon_area(poly)) partial_area = 0 for v1, v2 in pairwise(closed(poly)): partial_area += triangle_area(p, v1, v2) if boundary_area - round(partial_area) > boundary_area * 0.01: return False return True
def slice(self, step=1): points = [Vector(self.entity.dxf.start), Vector(self.entity.dxf.end)] sliced = [points[0]] for start, end in pairwise(points): dist = start.distance(end) n_steps = int(dist / step) try: param_step = step / dist except ZeroDivisionError: continue v = Vector() for i in range(n_steps): v = start.lerp(end, param_step * (i + 1)) sliced.append(v) if not v.isclose(end): sliced.append(end) self.points = sliced self.sliced = True self._length = None
def slice(self, step=1): """ Нарезать элемент на более менее линии с заданным шагом :param float step: шаг нарезки :return: """ sliced = [self.points[0]] for start, end in pairwise(self.points): dist = start.distance(end) n_steps = int(dist / step) try: param_step = step / dist except ZeroDivisionError: continue v = Vector() for i in range(n_steps): v = start.lerp(end, param_step * (i + 1)) sliced.append(v) if not v.isclose(end): sliced.append(end) self.points = sliced self.sliced = True self._length = None