void EnvelopeCurvePopup::sliderValueChanged(Slider* sliderThatChanged) { resetCounter(); if(sliderThatChanged == slider) { EnvCurve curve = handle->getCurve(); double value = slider->getValue(); value = cubed(value); value = linlin(value, -1.0, 1.0, -50.0, 50.0); curve.setCurve(value); handle->setCurve(curve); } }
void path_preview_handle::drag_point (QPointF local_pos) { QTransform full_trans = m_item->full_transform (); QTransform full_inv = full_trans.inverted (); QPointF pos = full_inv.map (local_pos); QPointF init_pos = full_inv.map (m_prev_drag); m_prev_drag = local_pos; // Magic Bezier Drag Equations follow! // "weight" describes how the influence of the drag should be distributed // among the handles; 0 = front handle only, 1 = back handle only. double weight, t = m_drag_t; if (t <= 1.0 / 6.0) weight = 0; else if (t <= 0.5) weight = (cubed ((6 * t - 1) / 2.0)) / 2; else if (t <= 5.0 / 6.0) weight = (1 - cubed ((6 * (1-t) - 1) / 2.0)) / 2 + 0.5; else weight = 1; QPointF delta = pos - init_pos; QPointF offset0 = ((1-weight) / (3*t*(1-t)*(1-t))) * delta; QPointF offset1 = (weight/(3*t*t*(1-t))) * delta; svg_path *path = m_edit_operation->get_svg_path (); path->move_control_point (full_trans.map (m_drag_it->control_point (cp_type::RIGHT) + offset0), *m_drag_it, cp_type::RIGHT); path->move_control_point (full_trans.map (m_drag_it->right ().control_point (cp_type::LEFT) + offset1), m_drag_it->right (), cp_type::LEFT); }
int doit_cubed() { cudaFree(0); CHECK_CUDA_ERROR(); int h_val[DIM]; int h_result[DIM]; for(int i = 0; i < DIM; ++i) h_val[i] = i; // Allocate device memory unsigned int size = sizeof(int) * DIM; int* d_val; cudaMalloc((void**)&d_val, size); CHECK_CUDA_ERROR(); int* d_result; cudaMalloc((void**)&d_result, size); CHECK_CUDA_ERROR(); // Send input to device cudaMemcpy(d_val, h_val, size, cudaMemcpyHostToDevice); CHECK_CUDA_ERROR(); // Call the kernel wrapper cubed(d_val, d_result, DIM); CHECK_CUDA_ERROR(); // Get back results cudaMemcpy(h_result, d_result, size, cudaMemcpyDeviceToHost); CHECK_CUDA_ERROR(); for(int i = 0; i < DIM; ++i) printf("%d ^ 3 = %d\n", h_val[i], h_result[i]); // Free memory cudaFree((void*)d_val); CHECK_CUDA_ERROR(); cudaFree((void*)d_result); CHECK_CUDA_ERROR(); return 0; }
double calculate(int numInputTokens, char **inputString){ int i; double result = 0.0; char *s; struct DynArr *stack; double num; //set up the stack stack = createDynArr(20); // start at 1 to skip the name of the calculator calc for(i=1;i < numInputTokens;i++) { s = inputString[i]; // Hint: General algorithm: // (1) Check if the string s is in the list of operators. // (1a) If it is, perform corresponding operations. // (1b) Otherwise, check if s is a number. // (1b - I) If s is not a number, produce an error. // (1b - II) If s is a number, push it onto the stack if(strcmp(s, "+") == 0){ add(stack); printf("Adding\n"); } else if(strcmp(s,"-") == 0){ subtract(stack); printf("Subtracting\n"); } else if(strcmp(s, "/") == 0){ divide(stack); printf("Dividing\n"); } else if(strcmp(s, "x") == 0){ multiply(stack); printf("Multiplying\n"); } else if(strcmp(s,"^") == 0){ power(stack); printf("Power\n"); } else if(strcmp(s, "^2") == 0){ squared(stack); printf("Squaring\n"); } else if(strcmp(s, "^3") == 0){ cubed(stack); printf("Cubing\n"); } else if(strcmp(s, "abs") == 0){ absoluteValue(stack); printf("Absolute value\n"); } else if(strcmp(s, "sqrt") == 0){ squareRoot(stack); printf("Square root\n"); } else if(strcmp(s, "exp") == 0){ exponential(stack); printf("Exponential\n"); } else if(strcmp(s, "ln") == 0){ naturalLog(stack); printf("Natural Log\n"); } else if(strcmp(s, "log") == 0){ logBase10(stack); printf("Log\n"); } else{ // FIXME: You need to develop the code here (when s is not an operator) // Remember to deal with special values ("pi" and "e") //check if not a number if (isNumber(s, &num) == 0){ if (strcmp(s, "pi") == 0){ num = 3.14159265; } else if (strcmp(s, "e") == 0){ num = 2.7182818; } else{ //wrong printf("%s is not valid (number or operator) \n", s); break; } } pushDynArr(stack, num); } } //end for /* FIXME: You will write this part of the function (2 steps below) * (1) Check if everything looks OK and produce an error if needed. * (2) Store the final value in result and print it out. */ if (sizeDynArr(stack) != 1) { printf("Incorrect count of numbers is detected! Calculations CANNOT be preformed. "); return 0; } else { result = topDynArr(stack); } return result; }