From: Barak Itkin Date: Sat, 23 Jun 2012 20:32:46 +0000 (+0300) Subject: Add a virtual edge struct to represent an edge that may exist X-Git-Tag: p2tc-0.1.0~32 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c4d6c26508fde571ed51ec24116678c68ab5ae73;p=poly2tri-c Add a virtual edge struct to represent an edge that may exist --- diff --git a/poly2tri-c/refine/Makefile.am b/poly2tri-c/refine/Makefile.am index abc3e93..48a269d 100644 --- a/poly2tri-c/refine/Makefile.am +++ b/poly2tri-c/refine/Makefile.am @@ -1,6 +1,6 @@ noinst_LTLIBRARIES = libp2tc-refine.la -libp2tc_refine_la_SOURCES = bounded-line.c bounded-line.h cdt.c cdt.h circle.c circle.h cluster.c cluster.h delaunay-terminator.c delaunay-terminator.h edge.c edge.h line.c line.h rmath.c rmath.h mesh.c mesh.h point.c point.h pslg.c pslg.h refine.h refiner.c refiner.h triangle.c triangle.h triangulation.h utils.c utils.h vector2.c vector2.h visibility.c visibility.h +libp2tc_refine_la_SOURCES = bounded-line.c bounded-line.h cdt.c cdt.h circle.c circle.h cluster.c cluster.h delaunay-terminator.c delaunay-terminator.h edge.c edge.h line.c line.h rmath.c rmath.h mesh.c mesh.h point.c point.h pslg.c pslg.h refine.h refiner.c refiner.h triangle.c triangle.h triangulation.h utils.c utils.h vector2.c vector2.h vedge.c vedge.h visibility.c visibility.h P2TC_REFINE_publicdir = $(P2TC_publicdir)/refine -P2TC_REFINE_public_HEADERS = bounded-line.h cdt.h circle.h cluster.h edge.h line.h mesh.h point.h pslg.h refine.h refiner.h rmath.h triangle.h triangulation.h utils.h vector2.h visibility.h +P2TC_REFINE_public_HEADERS = bounded-line.h cdt.h circle.h cluster.h edge.h line.h mesh.h point.h pslg.h refine.h refiner.h rmath.h triangle.h triangulation.h utils.h vector2.h vedge.h visibility.h diff --git a/poly2tri-c/refine/refine.h b/poly2tri-c/refine/refine.h index c6b9e41..3c94553 100644 --- a/poly2tri-c/refine/refine.h +++ b/poly2tri-c/refine/refine.h @@ -47,6 +47,8 @@ #include "triangle.h" #include "mesh.h" +#include "vedge.h" + #include "cluster.h" #include "cdt.h" #include "refiner.h" diff --git a/poly2tri-c/refine/triangulation.h b/poly2tri-c/refine/triangulation.h index 3e802f8..17847ad 100644 --- a/poly2tri-c/refine/triangulation.h +++ b/poly2tri-c/refine/triangulation.h @@ -38,4 +38,5 @@ typedef struct P2trEdge_ P2trEdge; typedef struct P2trTriangle_ P2trTriangle; typedef struct P2trMesh_ P2trMesh; +typedef struct P2trVEdge_ P2trVEdge; #endif diff --git a/poly2tri-c/refine/vedge.c b/poly2tri-c/refine/vedge.c new file mode 100644 index 0000000..f37e16d --- /dev/null +++ b/poly2tri-c/refine/vedge.c @@ -0,0 +1,111 @@ +/* + * This file is a part of Poly2Tri-C + * (c) Barak Itkin + * http://code.google.com/p/poly2tri-c/ + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * * Neither the name of Poly2Tri nor the names of its contributors may be + * used to endorse or promote products derived from this software without specific + * prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include + +#include "point.h" +#include "edge.h" +#include "vedge.h" +#include "mesh.h" + +static void +p2tr_vedge_init (P2trVEdge *self, + P2trPoint *start, + P2trPoint *end) +{ + self->start = start; + self->end = end; + self->refcount = 0; +} + +P2trVEdge* +p2tr_vedge_new (P2trPoint *start, + P2trPoint *end) +{ + P2trVEdge *self = g_slice_new (P2trVEdge); + + p2tr_vedge_init (self, start, end); + + p2tr_point_ref (start); + p2tr_point_ref (end); + + ++self->refcount; + return self; +} + +P2trVEdge* +p2tr_vedge_new2 (P2trEdge *real) +{ + return p2tr_vedge_new (P2TR_EDGE_START (real), real->end); +} + +P2trVEdge* +p2tr_vedge_ref (P2trVEdge *self) +{ + ++self->refcount; + return self; +} + +void +p2tr_vedge_unref (P2trVEdge *self) +{ + g_assert (self->refcount > 0); + if (--self->refcount == 0) + p2tr_vedge_free (self); +} + +P2trEdge* +p2tr_edge_is_real (P2trVEdge *self) +{ + return p2tr_point_has_edge_to (self->start, self->end); +} + +void +p2tr_vedge_free (P2trVEdge *self) +{ + p2tr_point_unref (self->start); + p2tr_point_unref (self->end); + g_slice_free (P2trVEdge, self); +} + +P2trMesh* +p2tr_vedge_get_mesh (P2trVEdge *self) +{ + return p2tr_point_get_mesh (self->end); +} + +P2trEdge* +p2tr_vedge_get (P2trVEdge *self) +{ + return p2tr_point_get_edge_to (self->start, self->end, TRUE); +} diff --git a/poly2tri-c/refine/vedge.h b/poly2tri-c/refine/vedge.h new file mode 100644 index 0000000..1aa8f8f --- /dev/null +++ b/poly2tri-c/refine/vedge.h @@ -0,0 +1,72 @@ +/* + * This file is a part of Poly2Tri-C + * (c) Barak Itkin + * http://code.google.com/p/poly2tri-c/ + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * * Neither the name of Poly2Tri nor the names of its contributors may be + * used to endorse or promote products derived from this software without specific + * prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef __P2TC_REFINE_VEDGE_H__ +#define __P2TC_REFINE_VEDGE_H__ + +#include +#include "circle.h" +#include "triangulation.h" + +/** + * @struct P2trVEdge_ + * A struct for representing a potential ("virtual") edge in a + * triangular mesh + */ +struct P2trVEdge_ +{ + /** The start point of this virtual edge */ + P2trPoint *start; + /** The end point of this virtual edge */ + P2trPoint *end; + + /** A count of references to the virtual edge */ + guint refcount; +}; + +P2trVEdge* p2tr_vedge_new (P2trPoint *start, + P2trPoint *end); + +P2trVEdge* p2tr_vedge_new2 (P2trEdge *real); + +P2trVEdge* p2tr_vedge_ref (P2trVEdge *self); + +void p2tr_vedge_unref (P2trVEdge *self); + +void p2tr_vedge_free (P2trVEdge *self); + +P2trMesh* p2tr_vedge_get_mesh (P2trVEdge *self); + +P2trEdge* p2tr_vedge_is_real (P2trVEdge *self); + +P2trEdge* p2tr_vedge_get (P2trVEdge *self); +#endif