]> granicus.if.org Git - poly2tri-c/commitdiff
Add a virtual edge struct to represent an edge that may exist
authorBarak Itkin <lightningismyname@gmail.com>
Sat, 23 Jun 2012 20:32:46 +0000 (23:32 +0300)
committerBarak Itkin <lightningismyname@gmail.com>
Sat, 23 Jun 2012 20:32:46 +0000 (23:32 +0300)
poly2tri-c/refine/Makefile.am
poly2tri-c/refine/refine.h
poly2tri-c/refine/triangulation.h
poly2tri-c/refine/vedge.c [new file with mode: 0644]
poly2tri-c/refine/vedge.h [new file with mode: 0644]

index abc3e936fff089d5a18ba9b94580560ac160673d..48a269d17839f83d64a7801307ba8fed72be74d1 100644 (file)
@@ -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
index c6b9e41edbade83d07df1297a9e89371e169c36c..3c94553f13d1ab01c80c64b8e5c022371341b4d4 100644 (file)
@@ -47,6 +47,8 @@
 #include "triangle.h"
 #include "mesh.h"
 
+#include "vedge.h"
+
 #include "cluster.h"
 #include "cdt.h"
 #include "refiner.h"
index 3e802f8b172f45aa28325dcd12e0fe938e02c655..17847ad874714b5787bf795bc99d8c219ff93d66 100644 (file)
@@ -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 (file)
index 0000000..f37e16d
--- /dev/null
@@ -0,0 +1,111 @@
+/*
+ * This file is a part of Poly2Tri-C
+ * (c) Barak Itkin <lightningismyname@gmail.com>
+ * 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 <math.h>
+#include <glib.h>
+
+#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 (file)
index 0000000..1aa8f8f
--- /dev/null
@@ -0,0 +1,72 @@
+/*
+ * This file is a part of Poly2Tri-C
+ * (c) Barak Itkin <lightningismyname@gmail.com>
+ * 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 <glib.h>
+#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