From: SiegeLord <sie...@us...> - 2013-01-26 21:46:21
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "Allegro". The branch, 5.1 has been updated via d4e8a8434bb5f9bc33b46af1874118071fb5f200 (commit) from b0a38785ed2daac6727e388c4f3c178ae4759a72 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit d4e8a8434bb5f9bc33b46af1874118071fb5f200 Author: SiegeLord <sie...@us...> Date: Sat Jan 26 16:42:36 2013 -0500 Replace the explict angle calculation with a cross product in the triangulation code. Results in 30% speedup of al_triangulate_polygon_with_holes. ----------------------------------------------------------------------- Summary of changes: addons/primitives/allegro5/internal/aintern_prim.h | 3 -- addons/primitives/prim_util.c | 27 -------------------- addons/primitives/triangulator.c | 10 +++--- 3 files changed, 5 insertions(+), 35 deletions(-) diff --git a/addons/primitives/allegro5/internal/aintern_prim.h b/addons/primitives/allegro5/internal/aintern_prim.h index 5188eec..f3e1ba2 100644 --- a/addons/primitives/allegro5/internal/aintern_prim.h +++ b/addons/primitives/allegro5/internal/aintern_prim.h @@ -51,9 +51,6 @@ void _al_prim_cache_push_triangle(ALLEGRO_PRIM_VERTEX_CACHE* cache, const float* /* Internal functions. */ float _al_prim_get_scale(void); float _al_prim_normalize(float* vector); -float _al_prim_wrap_two_pi(float angle); -float _al_prim_wrap_pi_to_pi(float angle); -float _al_prim_get_angle(const float* p0, const float* origin, const float* p1); int _al_prim_test_line_side(const float* origin, const float* normal, const float* point); bool _al_prim_is_point_in_triangle(const float* point, const float* v0, const float* v1, const float* v2); bool _al_prim_intersect_segment(const float* v0, const float* v1, const float* p0, const float* p1, float* point, float* t0, float* t1); diff --git a/addons/primitives/prim_util.c b/addons/primitives/prim_util.c index 425bc22..bf74c66 100644 --- a/addons/primitives/prim_util.c +++ b/addons/primitives/prim_util.c @@ -71,33 +71,6 @@ float _al_prim_wrap_two_pi(float angle) /* - * Wraps angle to the range [-pi, pi). - */ -float _al_prim_wrap_pi_to_pi(float angle) -{ - angle = _al_prim_wrap_two_pi(angle); - if (angle >= ALLEGRO_PI) - angle = -2.0f * ALLEGRO_PI + angle; - return angle; -} - - -/* - * Returns angle between two edges. - * - * Angle is in range [-2 pi, 2 pi], so it is good idea to - * use _al_prim_wrap_two_pi() for normalization. - */ -float _al_prim_get_angle(const float* p0, const float* origin, const float* p1) -{ - float angle1 = atan2f(origin[1] - p0[1], origin[0] - p0[0]); - float angle2 = atan2f(origin[1] - p1[1], origin[0] - p1[0]); - - return angle2 - angle1; -} - - -/* * Tests on which side of the line point is placed. * Positive value will be returned if point is on half plane * determined by normal vector. Negative value will be returned diff --git a/addons/primitives/triangulator.c b/addons/primitives/triangulator.c index d4f2501..605aa24 100644 --- a/addons/primitives/triangulator.c +++ b/addons/primitives/triangulator.c @@ -499,7 +499,7 @@ static int poly_compute_vertex_attributes(_AL_LIST* vertices, _AL_LIST_ITEM* ite float* v0; float* v1; float* v2; - float angle; + float cross; // Oops, degenerate triangle in store. if (_al_list_size(vertices) < 3) @@ -510,8 +510,8 @@ static int poly_compute_vertex_attributes(_AL_LIST* vertices, _AL_LIST_ITEM* ite v1 = (float*)_al_list_item_data(item); v2 = (float*)_al_list_item_data(next); - // Get angle between edges of current vertex. - angle = _al_prim_wrap_two_pi(_al_prim_get_angle(v0, v1, v2)); + // Compute the cross product between the two edges + cross = (v0[0] - v1[0]) * (v2[1] - v1[1]) - (v0[1] - v1[1]) * (v2[0] - v1[0]); # if POLY_DEBUG if (g_poly_debug_step == g_poly_debug_step_current) { @@ -521,7 +521,7 @@ static int poly_compute_vertex_attributes(_AL_LIST* vertices, _AL_LIST_ITEM* ite float dir0[2] = { v0[0] - v1[0], v0[1] - v1[1] }; float dir2[2] = { v2[0] - v1[0], v2[1] - v1[1] }; - POLY_DEBUG_TEXT(v1[0], v1[1], "%.1f", angle * 180.0f / 3.1415f); + POLY_DEBUG_TEXT(v1[0], v1[1], "%d", cross > 0); al_draw_line(v1[0], v1[1], v1[0] + dir0[0] * step, v1[1] + dir0[1] * step, al_map_rgb(255, 0, 0), 4.0f * g_poly_debug_scale); al_draw_line(v1[0], v1[1], v1[0] + dir2[0] * step, v1[1] + dir2[1] * step, al_map_rgb(255, 0, 0), 4.0f * g_poly_debug_scale); @@ -530,7 +530,7 @@ static int poly_compute_vertex_attributes(_AL_LIST* vertices, _AL_LIST_ITEM* ite // If internal angle is less than 180 degrees then we may // have an ear clip vertex, otherwise we have reflex. - if (angle <= ALLEGRO_PI) + if (cross >= 0) { if (flags & POLY_VERTEX_ATTR_EAR_CLIP) { hooks/post-receive -- Allegro |