1858 uint64_t numfaceedges, i, j;
1859 int newface_outside;
1860 uint64_t num_signed_edge_ids;
1864 int forward_edges_count = 0;
1866 int backward_edges_count = 0;
1869 if (!signed_edge_ids)
1876 LWDEBUGF(1,
"getRingEdges returned %d edges", num_signed_edge_ids);
1879 for (i=0; i<num_signed_edge_ids; ++i) {
1880 if ( signed_edge_ids[i] == -sedge ) {
1883 lwfree( signed_edge_ids );
1889 sedge, face, mbr_only);
1898 num_signed_edge_ids);
1900 lwfree( signed_edge_ids );
1909 lwfree( signed_edge_ids );
1911 " is geometrically not-closed", sedge);
1917 sedge, isccw ?
"counter" :
"");
1926 lwfree( signed_edge_ids );
1930 LWDEBUG(1,
"The left face of this clockwise ring is the universe, "
1931 "won't create a new face there");
1936 if ( mbr_only && face != 0 )
1942 updface.
mbr = (
GBOX *)shellbox;
1946 lwfree( signed_edge_ids );
1953 lwfree( signed_edge_ids );
1955 lwerror(
"Unexpected error: %d faces found when expecting 1", ret);
1959 lwfree( signed_edge_ids );
1967 if ( face != 0 && ! isccw)
1970 uint64_t nfaces = 1;
1972 if (nfaces == UINT64_MAX)
1974 lwfree( signed_edge_ids );
1981 lwfree( signed_edge_ids );
1983 lwerror(
"Unexpected error: %d faces found when expecting 1", nfaces);
1986 newface.
mbr = oldface->
mbr;
1990 newface.
mbr = (
GBOX *)shellbox;
1997 lwfree( signed_edge_ids );
2004 lwfree( signed_edge_ids );
2006 lwerror(
"Unexpected error: %d faces inserted when expecting 1", ret);
2017 if ( face != 0 && ! isccw ) {
2019 LWDEBUG(1,
"New face is on the outside of the ring, updating rings in former shell");
2020 newface_outside = 1;
2023 LWDEBUG(1,
"New face is on the inside of the ring, updating forward edges in new ring");
2024 newface_outside = 0;
2037 if (numfaceedges == UINT64_MAX)
2043 LWDEBUGF(1,
"_lwt_AddFaceSplit: lwt_be_getEdgeByFace(%d) returned %d edges", face, numfaceedges);
2048 forward_edges_count = 0;
2050 backward_edges_count = 0;
2053 for ( i=0; i<numfaceedges; ++i )
2061 for ( j=0; j<num_signed_edge_ids; ++j )
2063 int seid = signed_edge_ids[j];
2067 LWDEBUGF(1,
"Edge %d is a known forward edge of the new ring", e->
edge_id);
2071 if ( found == 2 )
break;
2073 else if ( -seid == e->
edge_id )
2076 LWDEBUGF(1,
"Edge %d is a known backward edge of the new ring", e->
edge_id);
2080 if ( found == 2 )
break;
2083 if ( found )
continue;
2084 LWDEBUGF(1,
"Edge %d is not a known edge of the new ring", e->
edge_id);
2103 LWDEBUGF(1,
"Edge %d first point %s new ring",
2108 if ( newface_outside )
2112 LWDEBUGF(1,
"Edge %d not outside of the new ring, not updating it",
2121 LWDEBUGF(1,
"Edge %d not inside the new ring, not updating it",
2145 if ( forward_edges_count )
2148 forward_edges_count,
2152 lwfree( signed_edge_ids );
2156 if ( ret != forward_edges_count )
2158 lwfree( signed_edge_ids );
2159 lwerror(
"Unexpected error: %d edges updated when expecting %d",
2160 ret, forward_edges_count);
2166 if ( backward_edges_count )
2169 backward_edges_count,
2173 lwfree( signed_edge_ids );
2177 if ( ret != backward_edges_count )
2179 lwfree( signed_edge_ids );
2180 lwerror(
"Unexpected error: %d edges updated when expecting %d",
2181 ret, backward_edges_count);
2194 uint64_t numisonodes = 1;
2197 &numisonodes, fields, newface.
mbr);
2198 if (numisonodes == UINT64_MAX)
2204 if ( numisonodes ) {
2206 int nodes_to_update = 0;
2207 for (i=0; i<numisonodes; ++i)
2212 LWDEBUGF(1,
"Node %d is %scontained in new ring, newface is %s",
2214 newface_outside ?
"outside" :
"inside" );
2215 if ( newface_outside )
2219 LWDEBUGF(1,
"Node %d contained in an hole of the new face",
2228 LWDEBUGF(1,
"Node %d not contained in the face shell",
2239 if ( nodes_to_update )
2245 lwfree( signed_edge_ids );
LWGEOM * lwpoly_as_lwgeom(const LWPOLY *obj)
int getPoint2d_p(const POINTARRAY *pa, uint32_t n, POINT2D *point)
const GBOX * lwgeom_get_bbox(const LWGEOM *lwgeom)
Get a non-empty geometry bounding box, computing and caching it if not already there.
void * lwalloc(size_t size)
int ptarray_is_closed_2d(const POINTARRAY *pa)
void lwpoly_free(LWPOLY *poly)
#define LW_INSIDE
Constants for point-in-polygon return values.
int ptarray_contains_point(const POINTARRAY *pa, const POINT2D *pt)
Return 1 if the point is inside the POINTARRAY, -1 if it is outside, and 0 if it is on the boundary.
int ptarray_isccw(const POINTARRAY *pa)
#define LWT_COL_EDGE_FACE_RIGHT
LWT_INT64 LWT_ELEMID
Identifier of topology element.
#define LWT_COL_EDGE_FACE_LEFT
#define LWT_COL_NODE_CONTAINING_FACE
#define LWT_COL_EDGE_EDGE_ID
Edge fields.
#define LWT_COL_NODE_GEOM
#define LWT_COL_NODE_NODE_ID
Node fields.
#define LWT_COL_EDGE_GEOM
#define LWDEBUG(level, msg)
#define LWDEBUGF(level, msg,...)
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
static LWT_ELEMID * lwt_be_getRingEdges(LWT_TOPOLOGY *topo, LWT_ELEMID edge, uint64_t *numedges, uint64_t limit)
static uint64_t lwt_be_updateFacesById(LWT_TOPOLOGY *topo, const LWT_ISO_FACE *faces, uint64_t numfaces)
const char * lwt_be_lastErrorMessage(const LWT_BE_IFACE *be)
static LWPOLY * _lwt_MakeRingShell(LWT_TOPOLOGY *topo, LWT_ELEMID *signed_edge_ids, uint64_t num_signed_edge_ids)
static int lwt_be_updateNodesById(LWT_TOPOLOGY *topo, const LWT_ISO_NODE *nodes, int numnodes, int upd_fields)
static void _lwt_release_nodes(LWT_ISO_NODE *nodes, int num_nodes)
static int lwt_be_insertFaces(LWT_TOPOLOGY *topo, LWT_ISO_FACE *face, uint64_t numelems)
static LWT_ISO_EDGE * lwt_be_getEdgeByFace(LWT_TOPOLOGY *topo, const LWT_ELEMID *ids, uint64_t *numelems, int fields, const GBOX *box)
static void _lwt_release_faces(LWT_ISO_FACE *faces, int num_faces)
static LWT_ISO_FACE * lwt_be_getFaceById(LWT_TOPOLOGY *topo, const LWT_ELEMID *ids, uint64_t *numelems, int fields)
static LWT_ISO_NODE * lwt_be_getNodeByFace(LWT_TOPOLOGY *topo, const LWT_ELEMID *ids, uint64_t *numelems, int fields, const GBOX *box)
static void _lwt_release_edges(LWT_ISO_EDGE *edges, int num_edges)
static int lwt_be_updateEdgesById(LWT_TOPOLOGY *topo, const LWT_ISO_EDGE *edges, int numedges, int upd_fields)
static const POINT2D * getPoint2d_cp(const POINTARRAY *pa, uint32_t n)
Returns a POINT2D pointer into the POINTARRAY serialized_ptlist, suitable for reading from.
Datum contains(PG_FUNCTION_ARGS)
LWT_ELEMID containing_face
const LWT_BE_IFACE * be_iface