Skip to content

Instantly share code, notes, and snippets.

@MichaelMure
Created May 16, 2011 15:49
Show Gist options
  • Save MichaelMure/974696 to your computer and use it in GitHub Desktop.
Save MichaelMure/974696 to your computer and use it in GitHub Desktop.
GimpCagePoint point;
GimpCagePoint *A, *B;
GimpVector2 *AB, *AD;
gdouble lAB, lAD, angle, alpha, beta;
g_return_if_fail (GIMP_IS_CAGE_CONFIG (gcc));
g_return_if_fail (point_number <= gcc->cage_points->len);
g_return_if_fail (point_number >= 0);
point.src_point.x = x + DELTA;
point.src_point.y = y + DELTA;
A = &g_array_index (gcc->cage_points, GimpCagePoint, point_number);
B = &g_array_index (gcc->cage_points, GimpCagePoint, point_number+1);
gimp_vector2_sub (AB, B, A);
gimp_vector2_sub (AD, point.src_point, A);
lAB = gimp_vector2_length (AB);
lAD = gimp_vector2_length (AD);
angle = arcsin ((B->src_point.y - A->src_point.y) / lAB) + arcsin ((y - A->src_point.y) / lAD);
alpha = lAD * cos (angle);
beta = lAB * sin (angle);
point.dest_point.x = x + DELTA;
point.dest_point.y = y + DELTA;
g_array_insert_val (gcc->cage_points, point_number, point);
gimp_cage_config_compute_scaling_factor (gcc);
gimp_cage_config_compute_edges_normal (gcc);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment