def generate_code_for_Bezier(degree, printer): t = symbols('t') lines = [] n_coeffs = degree + 1 syms = utils.create_coeff_symbols(n_coeffs) func = utils.bezier(degree, t, False, syms) poly, coeffs = extract_coefficients(func, t) solver_lines = utils.generate_solver_code(coeffs, poly, printer) control_variables = ", ".join( ["Scalar cx{i}, Scalar cy{i}".format(i=i) for i in range(n_coeffs)]) control_variable_arguments = ", ".join([ "ctrl_pts({i},0), ctrl_pts({i},1)".format(i=i) for i in range(n_coeffs) ]) template_function = specialization_template.format( type="Bezier", control_variables=control_variables, body="\n".join(utils.indent(solver_lines)), degree=degree) invocation = "return compute_{}_degree_{}_singularities({}, t0, t1);".format( "Bezier", degree, control_variable_arguments) extern_declaration = specialization_extern_declaration_template.format( type="Bezier", degree=degree, control_variables=control_variables) extern_definition = specialization_extern_definition_template.format( type="Bezier", degree=degree, control_variables=control_variables) return template_function, invocation, extern_declaration, extern_definition
def _get_label_rect(self): font = QFont() metrics = QFontMetrics(font) height = metrics.height() width = metrics.width(self.label) if self.quad_center: position = bezier(self.line().p1(), self.line().p2(), self.quad_center, 0.5) return QRectF(position, QSizeF(width, height)) return QRectF(self.center, QSizeF(width, height))
def new_back_curve(self): # Make the boomerang go faster if the player is running away from it # THERE'S NO ESCAPE # IT WILL COME BACK adist = utils.dist(self.rect.center, self.source_sprite.rect.center) if adist < self.last_adist: d = self.dist / adist if d > 1: d = 1 / d d = d**(1 / 10) d = max(d, 0.2) self.length = self.base_length * d self.time = (self.time - 1) * (self.base_length / self.length) self.time = max(self.time, 1) self.last_adist = adist p = utils.break_segment(self.rect.center, self.source_sprite.rect.center, self.curve_back_spread, self.curve_back_point) self.curve_points = p return utils.bezier(*p)
def addResult(self, result: Result): self.data.results.append(result) ui_result = ResultItem(self.graph, result) self.addItem(ui_result) if isinstance(result.target, Node): ui_result.setPos(result.target.x, result.target.y) else: ui_edge = self.edges[result.target.id] start_point = QPointF(result.target.start_node.x, result.target.start_node.y) end_point = QPointF(result.target.end_node.x, result.target.end_node.y) offset = result.target.offset or 0 if result.target.length: offset /= result.target.length position = bezier(start_point, end_point, start_point + ui_edge.quad_center, offset) ui_result.setPos(position)
def new_curve(self): p = utils.break_segment(self.rect.center, self.target, self.curve_spread, self.curve_point) self.curve_points = p return utils.bezier(*p)