def interpret(self, interpreter, variables): interpreter.assert_not_closed() interpreter.start_new_segment() v0 = interpreter.position if interpreter.has_last_vertex: v0_index = interpreter.get_last_vertex() else: v0_index = interpreter.new_vertex(*v0) start = complex(*v0) rad_x_expr, rad_y_expr = self.radii rad_x = interpreter.eval_(rad_x_expr, variables) rad_y = interpreter.eval_(rad_y_expr, variables) radius = complex(rad_x, rad_y) xaxis_rot = interpreter.eval_(self.rot, variables) flag1 = interpreter.eval_(self.flag1, variables) flag2 = interpreter.eval_(self.flag2, variables) # numverts, requires -1 else it means segments (21 verts is 20 segments). if self.num_verts is not None: num_verts = interpreter.eval_(self.num_verts, variables) else: num_verts = interpreter.dflt_num_verts num_verts -= 1 end = interpreter.calc_vertex(self.is_abs, self.end[0], self.end[1], variables) end = complex(*end) arc = Arc(start, radius, xaxis_rot, flag1, flag2, end) theta = 1 / num_verts for i in range(1, num_verts + 1): v1 = x, y = arc.point(theta * i) v1_index = interpreter.new_vertex(x, y) interpreter.new_edge(v0_index, v1_index) v0_index = v1_index curve = SvCircle.from_arc(arc) interpreter.curves.append(curve) interpreter.position = v1 interpreter.new_knot("A.#", *v1) if self.close: interpreter.close_segment(v1_index) interpreter.has_last_vertex = True
def perform_ArcTo(self): ''' expects 6 parameters: A rx,ry rot flag1 flag2 x,y num_verts [z] example: A <2v xr,yr> <rot> <int-bool> <int-bool> <2v xend,yend> <int num_verts> [z] ''' tempstr = self.stripped_line.split(' ') if not len(tempstr) == 6: print(tempstr) print('error on ArcTo line: ', self.stripped_line) return points = [] start = complex(*self.posxy) radius = complex(*self.get_2vec(tempstr[0])) xaxis_rot = self.get_typed(tempstr[1], float) flag1 = self.get_typed(tempstr[2], int) flag2 = self.get_typed(tempstr[3], int) # numverts, requires -1 else it means segments (21 verts is 20 segments). num_verts = self.get_typed(tempstr[5], int) - 1 if self.section_type == 'arc_to_absolute': end = complex(*self.get_2vec(tempstr[4])) else: xy_end_pre = self.get_2vec(tempstr[4]) xy_end_final = self.relative(self.posxy, xy_end_pre) end = complex(*xy_end_final) arc = Arc(start, radius, xaxis_rot, flag1, flag2, end) theta = 1/num_verts for i in range(num_verts+1): point = arc.point(theta * i) points.append(point) return self.find_right_index_and_make_edges(points)
def perform_ArcTo(self): ''' expects 6 parameters: A rx,ry rot flag1 flag2 x,y num_verts [z] example: A <2v xr,yr> <rot> <int-bool> <int-bool> <2v xend,yend> <int num_verts> [z] ''' tempstr = self.stripped_line.split(' ') if not len(tempstr) == 6: print(tempstr) print('error on ArcTo line: ', self.stripped_line) return points = [] start = complex(*self.posxy) radius = complex(*self.get_2vec(tempstr[0])) xaxis_rot = self.get_typed(tempstr[1], float) flag1 = self.get_typed(tempstr[2], int) flag2 = self.get_typed(tempstr[3], int) # numverts, requires -1 else it means segments (21 verts is 20 segments). num_verts = self.get_typed(tempstr[5], int) - 1 if self.section_type == 'arc_to_absolute': end = complex(*self.get_2vec(tempstr[4])) else: xy_end_pre = self.get_2vec(tempstr[4]) xy_end_final = self.relative(self.posxy, xy_end_pre) end = complex(*xy_end_final) arc = Arc(start, radius, xaxis_rot, flag1, flag2, end) theta = 1/num_verts for i in range(num_verts+1): point = arc.point(theta * i) points.append(point) return self.find_right_index_and_make_edges(points)