Commit 2693402
new is_clockwise implementation
Changed files (3)
Diff
@@ -31,14 +31,6 @@ enum PointType { FLOATING } -enum PointDirection {- NONE,- UP_RIGHT,- DOWN_RIGHT,- UP_LEFT,- DOWN_LEFT-}- class EditPoint { public double x; public double y;@@ -52,8 +44,6 @@ class EditPoint { public unowned List<EditPoint>? prev = null; public unowned List<EditPoint>? next = null; - public PointDirection direction = PointDirection.NONE;- public bool active = false; bool active_handle = false; @@ -95,8 +85,6 @@ class EditPoint { new_point.y = y; new_point.type = type;- new_point.direction = direction;- new_point.set_color (r, g, b, a); new_point.tie_handles = tie_handles;@@ -231,34 +219,6 @@ class EditPoint { return update; } - // Fixa: ta bort färgmarkeringarna- public void set_direction () {- EditPoint pep = this.get_next ().data;- EditPoint ep = this;-- if (pep.x < ep.x) {- - if (pep.y < ep.y) { - ep.direction = PointDirection.DOWN_LEFT;- ep.set_color (1,1,0,1); // gul - } else {- ep.direction = PointDirection.UP_LEFT;- ep.set_color (1,0,0,1); // röd- }- - } else {-- if (pep.y < ep.y) {- ep.direction = PointDirection.DOWN_RIGHT;- ep.set_color (0,1,0,1); // grön- } else {- ep.direction = PointDirection.UP_RIGHT;- ep.set_color (0,1,1,1); // ljusblå- }- - } - }- public int get_index () { int i = -1; @@ -817,135 +817,32 @@ class IntersectionList : GLib.Object { stdout.printf (@"Point $i at ($(p.x), $(p.y)) $t \n"); } }-- // Fixa- private int next_point_is_clockwise (EditPoint p) {- if (p.direction == PointDirection.DOWN_RIGHT) {- if (p.get_next ().data.direction == PointDirection.DOWN_LEFT)- return -1;- else- return +1;- }- - if (p.direction == PointDirection.UP_RIGHT) {- if (p.get_next ().data.direction == PointDirection.DOWN_RIGHT)- return -2;- else- return +2;- }- - if (p.direction == PointDirection.UP_LEFT) {- if (p.get_next ().data.direction == PointDirection.UP_RIGHT)- return -3;- else- return +3;- }- - if (p.direction == PointDirection.DOWN_LEFT) {- if (p.get_next ().data.direction == PointDirection.UP_LEFT)- return -4;- else- return +4;- }-- warn_if_reached ();- return 0;- } - public bool is_clockwise () {- int i, r;+ private bool is_clockwise_top () {+ EditPoint top_point = new EditPoint (1000, 1000);+ + return_if_fail (points.length () >= 3); - if (unlikely (points.length () <= 2)) {- no_derived_direction = true;- return clockwise_direction;- }-- reverse_points ();- create_list ();- set_directions (); - r = points_direction ();-- reverse_points (); create_list ();- set_directions ();- i = points_direction ();- - /*- if (i < r) print (@"Ja den är medsols \n");- else print (@"Nä den är inte medsols\n");- print (@" i > r; $i > $r \n\n");- */- - if (unlikely (i == r)) {- warning (@"Can not determine directions since i == r ($i == $r)\n");- } - return i < r;- }- - private int points_direction () {- int dir = 0;- foreach (var p in points) {- dir += next_point_is_clockwise (p);+ foreach (EditPoint ep in points) {+ if (ep.y < top_point.y) {+ top_point = ep;+ } }- return dir; - }- - public static bool next_triangle_is_clockwise (EditPoint a) {- unowned List<EditPoint>? p = a.get_next ();- unowned List<EditPoint>? q = ((!)p).next;- - return_if_fail (p != null);- - if (q == null) q = ((!)p).first ();- - return_if_fail (q != null); - return triangle_is_clockwise (a, ((!)p).data, ((!)q).data);+ return (top_point.get_prev ().data.x < top_point.get_next ().data.x); } - public static bool triangle_is_clockwise (EditPoint a, EditPoint b, EditPoint c) {- - if (a.x <= b.x <= c.x) return (a.y < c.y);- if (a.x < b.x <= c.x) return (a.y < c.y);- if (a.x >= b.x && c.x >= b.x) return (a.y > c.y);- if (a.x < b.x && c.x < b.x) return (a.y > c.y); - if (a.x >= b.x && c.x <= b.x) return (c.y > a.y);- if (a.x <= b.x && c.x <= b.x) return (c.y < a.y);- if (a.x <= b.x && c.x >= b.x) return (c.y > a.y);- - warning ("Reached.");- return false;- }-- private bool is_clockwise_extrema (int ul, int ur, int lr, int ll) {- int t;- int i;-- for (i = 0; i < 4; i++) {-- if (ul <= ur <= lr <= ll) {- return false;- }- - if (ul >= ur >= lr <= ll) {- return true;- }- - // shift- t = lr;- lr = ll;- ll = ul;- ul = ur;- ur = t;+ public bool is_clockwise () {+ if (unlikely (points.length () <= 2)) {+ no_derived_direction = true;+ return clockwise_direction; }-- warning (@"($ul <= $ur <= $lr <= $ll) \n");- warn_if_reached (); - return false;+ return is_clockwise_top (); }-+ private static uint num_positions (uint i_xmax, uint i_ymax, uint i_xmin, uint i_ymin) { List<uint> i = new List<uint> (); @@ -1618,16 +1515,6 @@ class IntersectionList : GLib.Object { ep.data.prev = ep.prev; } - public void set_directions () {- create_list ();- - if (points.length () <= 1) return;- - foreach (var ep in points) {- ep.set_direction ();- }- }- public void set_new_start (EditPoint ep) { List<EditPoint> list = new List<EditPoint> (); uint len = points.length ();@@ -74,8 +74,7 @@ class ShrinkTool : Tool { EditPoint ep; p.create_list ();- p.set_directions ();- + foreach (EditPoint pep in p.points) { unowned List<EditPoint>? lep = pep.get_next ();