/* See quad.h. */ /* Last edited on 2001-10-21 23:34:18 by stolfi */ /* ** Written by J. Stolfi on april 1993, based on an original ** implementation by Jim Roth (DEC CADM Advanced Group, May 1986). ** See the copyright notice at the end of this file. */ #include "quad.h" #include #include #define MARK(e) ((quad_edge_rec *)((e)&0xfffffffcu))->mark /* Make a new edge: */ quad_arc make_edge(void) { quad_arc e; e = (quad_arc) malloc(sizeof(quad_edge_rec)); ONEXT(e) = e; SYMDNEXT(e) = SYM(e); ROTRNEXT(e) = TOR(e); TORLNEXT(e) = ROT(e); MARK(e) = 0; return e; } /* Delete an edge: */ void destroy_edge(quad_arc e) { quad_arc f = SYM(e); if (ONEXT(e) != e) splice(e, OPREV(e)); if (ONEXT(f) != f) splice(f, OPREV(f)); free((char *) ((e) & 0xfffffffcu)); } /* Splice primitive: */ void splice(quad_arc a, quad_arc b) { quad_arc ta, tb; quad_arc alpha = ROT(ONEXT(a)); quad_arc beta = ROT(ONEXT(b)); ta = ONEXT(a); tb = ONEXT(b); ONEXT(a) = tb; ONEXT(b) = ta; ta = ONEXT(alpha); tb = ONEXT(beta); ONEXT(alpha) = tb; ONEXT(beta) = ta; } /* Enumerate edge quads */ void quad_do_enum ( quad_arc a, void visit_proc(quad_arc e, void *closure), void *closure, unsigned mark ); unsigned next_mark = 1; void quad_enum( quad_arc a, void visit_proc(quad_arc e, void *closure), void *closure ) { unsigned mark = next_mark; next_mark++; if (next_mark == 0) next_mark = 1; quad_do_enum(a, visit_proc, closure, mark); } void quad_do_enum ( quad_arc e, void visit_proc(quad_arc e, void *closure), void *closure, unsigned mark ) { while (MARK(e) != mark) { visit_proc(e, closure); MARK(e) = mark; quad_do_enum (ONEXT(SYM(e)), visit_proc, closure, mark); e = ONEXT(e); } } /* ** Copyright notice: ** ** Copyright 1996 Institute of Computing, Unicamp. ** ** Permission to use this software for any purpose is hereby granted, ** provided that any substantial copy or mechanically derived version ** of this file that is made available to other parties is accompanied ** by this copyright notice in full, and is distributed under these same ** terms. ** ** NOTE: this copyright notice does not claim to supersede any copyrights ** that may apply to the original DEC implementation of the quad-edge ** data structure. ** ** DISCLAIMER: This software is provided "as is" with no explicit or ** implicit warranty of any kind. Neither the authors nor their ** employers can be held responsible for any losses or damages ** that might be attributed to its use. ** ** End of copyright notice. */