PostGIS  3.3.9dev-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 2942 of file lwgeom_topo.c.

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

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: