PostGIS  3.7.0dev-r@@SVN_REVISION@@

◆ _lwt_FindNextRingEdge()

static int _lwt_FindNextRingEdge ( const POINTARRAY ring,
int  from,
const LWT_ISO_EDGE edges,
int  numedges 
)
static

Definition at line 2936 of file lwgeom_topo.c.

2938 {
2939  int i;
2940  POINT2D p1;
2941 
2942  /* Get starting ring point */
2943  getPoint2d_p(ring, from, &p1);
2944 
2945  LWDEBUGF(1, "Ring's 'from' point (%d) is %g,%g", from, p1.x, p1.y);
2946 
2947  /* find the edges defining the next portion of ring starting from
2948  * vertex "from" */
2949  for ( i=0; i<numedges; ++i )
2950  {
2951  const LWT_ISO_EDGE *isoe = &(edges[i]);
2952  LWLINE *edge = isoe->geom;
2953  POINTARRAY *epa = edge->points;
2954  POINT2D p2, pt;
2955  int match = 0;
2956  uint32_t j;
2957 
2958  /* Skip if the edge is a dangling one */
2959  if ( isoe->face_left == isoe->face_right )
2960  {
2961  LWDEBUGF(3, "_lwt_FindNextRingEdge: edge %" LWTFMT_ELEMID
2962  " has same face (%" LWTFMT_ELEMID
2963  ") on both sides, skipping",
2964  isoe->edge_id, isoe->face_left);
2965  continue;
2966  }
2967 
2968  if (epa->npoints < 2)
2969  {
2970  LWDEBUGF(3, "_lwt_FindNextRingEdge: edge %" LWTFMT_ELEMID
2971  " has only %"PRIu32" points",
2972  isoe->edge_id, epa->npoints);
2973  continue;
2974  }
2975 
2976 #if 0
2977  size_t sz;
2978  LWDEBUGF(1, "Edge %" LWTFMT_ELEMID " is %s",
2979  isoe->edge_id,
2980  lwgeom_to_wkt(lwline_as_lwgeom(edge), WKT_EXTENDED, 2, &sz));
2981 #endif
2982 
2983  /* ptarray_remove_repeated_points ? */
2984 
2985  getPoint2d_p(epa, 0, &p2);
2986  LWDEBUGF(1, "Edge %" LWTFMT_ELEMID " 'first' point is %g,%g",
2987  isoe->edge_id, p2.x, p2.y);
2988  LWDEBUGF(1, "Rings's 'from' point is still %g,%g", p1.x, p1.y);
2989  if ( P2D_SAME_STRICT(&p1, &p2) )
2990  {
2991  LWDEBUG(1, "P2D_SAME_STRICT(p1,p2) returned true");
2992  LWDEBUGF(1, "First point of edge %" LWTFMT_ELEMID
2993  " matches ring vertex %d", isoe->edge_id, from);
2994  /* first point matches, let's check next non-equal one */
2995  for ( j=1; j<epa->npoints; ++j )
2996  {
2997  getPoint2d_p(epa, j, &p2);
2998  LWDEBUGF(1, "Edge %" LWTFMT_ELEMID " 'next' point %d is %g,%g",
2999  isoe->edge_id, j, p2.x, p2.y);
3000  /* we won't check duplicated edge points */
3001  if ( P2D_SAME_STRICT(&p1, &p2) ) continue;
3002  /* we assume there are no duplicated points in ring */
3003  getPoint2d_p(ring, from+1, &pt);
3004  LWDEBUGF(1, "Ring's point %d is %g,%g",
3005  from+1, pt.x, pt.y);
3006  match = P2D_SAME_STRICT(&pt, &p2);
3007  break; /* we want to check a single non-equal next vertex */
3008  }
3009 #if POSTGIS_DEBUG_LEVEL > 0
3010  if ( match ) {
3011  LWDEBUGF(1, "Prev point of edge %" LWTFMT_ELEMID
3012  " matches ring vertex %d", isoe->edge_id, from+1);
3013  } else {
3014  LWDEBUGF(1, "Prev point of edge %" LWTFMT_ELEMID
3015  " does not match ring vertex %d", isoe->edge_id, from+1);
3016  }
3017 #endif
3018  }
3019 
3020  if ( ! match )
3021  {
3022  LWDEBUGF(1, "Edge %" LWTFMT_ELEMID " did not match as forward",
3023  isoe->edge_id);
3024  getPoint2d_p(epa, epa->npoints-1, &p2);
3025  LWDEBUGF(1, "Edge %" LWTFMT_ELEMID " 'last' point is %g,%g",
3026  isoe->edge_id, p2.x, p2.y);
3027  if ( P2D_SAME_STRICT(&p1, &p2) )
3028  {
3029  LWDEBUGF(1, "Last point of edge %" LWTFMT_ELEMID
3030  " matches ring vertex %d", isoe->edge_id, from);
3031  /* last point matches, let's check next non-equal one */
3032  for ( j=2; j<=epa->npoints; j++ )
3033  {
3034  getPoint2d_p(epa, epa->npoints - j, &p2);
3035  LWDEBUGF(1, "Edge %" LWTFMT_ELEMID " 'prev' point %d is %g,%g",
3036  isoe->edge_id, epa->npoints - j, p2.x, p2.y);
3037  /* we won't check duplicated edge points */
3038  if ( P2D_SAME_STRICT(&p1, &p2) ) continue;
3039  /* we assume there are no duplicated points in ring */
3040  getPoint2d_p(ring, from+1, &pt);
3041  LWDEBUGF(1, "Ring's point %d is %g,%g",
3042  from+1, pt.x, pt.y);
3043  match = P2D_SAME_STRICT(&pt, &p2);
3044  break; /* we want to check a single non-equal next vertex */
3045  }
3046  }
3047 #if POSTGIS_DEBUG_LEVEL > 0
3048  if ( match ) {
3049  LWDEBUGF(1, "Prev point of edge %" LWTFMT_ELEMID
3050  " matches ring vertex %d", isoe->edge_id, from+1);
3051  } else {
3052  LWDEBUGF(1, "Prev point of edge %" LWTFMT_ELEMID
3053  " does not match ring vertex %d", isoe->edge_id, from+1);
3054  }
3055 #endif
3056  }
3057 
3058  if ( match ) return i;
3059 
3060  }
3061 
3062  return -1;
3063 }
LWGEOM * lwline_as_lwgeom(const LWLINE *obj)
Definition: lwgeom.c:339
#define WKT_EXTENDED
Definition: liblwgeom.h:2218
int getPoint2d_p(const POINTARRAY *pa, uint32_t n, POINT2D *point)
Definition: lwgeom_api.c:342
char * lwgeom_to_wkt(const LWGEOM *geom, uint8_t variant, int precision, size_t *size_out)
WKT emitter function.
Definition: lwout_wkt.c:708
#define P2D_SAME_STRICT(a, b)
#define LWTFMT_ELEMID
#define LWDEBUG(level, msg)
Definition: lwgeom_log.h:101
#define LWDEBUGF(level, msg,...)
Definition: lwgeom_log.h:106
POINTARRAY * points
Definition: liblwgeom.h:483
LWT_ELEMID face_right
LWT_ELEMID face_left
LWLINE * geom
LWT_ELEMID edge_id
double y
Definition: liblwgeom.h:390
double x
Definition: liblwgeom.h:390
uint32_t npoints
Definition: liblwgeom.h:427

References LWT_ISO_EDGE::edge_id, LWT_ISO_EDGE::face_left, LWT_ISO_EDGE::face_right, LWT_ISO_EDGE::geom, getPoint2d_p(), LWDEBUG, LWDEBUGF, lwgeom_to_wkt(), lwline_as_lwgeom(), LWTFMT_ELEMID, POINTARRAY::npoints, P2D_SAME_STRICT, LWLINE::points, WKT_EXTENDED, POINT2D::x, and POINT2D::y.

Referenced by lwt_GetFaceEdges().

Here is the call graph for this function:
Here is the caller graph for this function: