PostGIS  3.4.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 2912 of file lwgeom_topo.c.

2914 {
2915  int i;
2916  POINT2D p1;
2917 
2918  /* Get starting ring point */
2919  getPoint2d_p(ring, from, &p1);
2920 
2921  LWDEBUGF(1, "Ring's 'from' point (%d) is %g,%g", from, p1.x, p1.y);
2922 
2923  /* find the edges defining the next portion of ring starting from
2924  * vertex "from" */
2925  for ( i=0; i<numedges; ++i )
2926  {
2927  const LWT_ISO_EDGE *isoe = &(edges[i]);
2928  LWLINE *edge = isoe->geom;
2929  POINTARRAY *epa = edge->points;
2930  POINT2D p2, pt;
2931  int match = 0;
2932  uint32_t j;
2933 
2934  /* Skip if the edge is a dangling one */
2935  if ( isoe->face_left == isoe->face_right )
2936  {
2937  LWDEBUGF(3, "_lwt_FindNextRingEdge: edge %" LWTFMT_ELEMID
2938  " has same face (%" LWTFMT_ELEMID
2939  ") on both sides, skipping",
2940  isoe->edge_id, isoe->face_left);
2941  continue;
2942  }
2943 
2944  if (epa->npoints < 2)
2945  {
2946  LWDEBUGF(3, "_lwt_FindNextRingEdge: edge %" LWTFMT_ELEMID
2947  " has only %"PRIu32" points",
2948  isoe->edge_id, epa->npoints);
2949  continue;
2950  }
2951 
2952 #if 0
2953  size_t sz;
2954  LWDEBUGF(1, "Edge %" LWTFMT_ELEMID " is %s",
2955  isoe->edge_id,
2956  lwgeom_to_wkt(lwline_as_lwgeom(edge), WKT_EXTENDED, 2, &sz));
2957 #endif
2958 
2959  /* ptarray_remove_repeated_points ? */
2960 
2961  getPoint2d_p(epa, 0, &p2);
2962  LWDEBUGF(1, "Edge %" LWTFMT_ELEMID " 'first' point is %g,%g",
2963  isoe->edge_id, p2.x, p2.y);
2964  LWDEBUGF(1, "Rings's 'from' point is still %g,%g", p1.x, p1.y);
2965  if ( P2D_SAME_STRICT(&p1, &p2) )
2966  {
2967  LWDEBUG(1, "P2D_SAME_STRICT(p1,p2) returned true");
2968  LWDEBUGF(1, "First point of edge %" LWTFMT_ELEMID
2969  " matches ring vertex %d", isoe->edge_id, from);
2970  /* first point matches, let's check next non-equal one */
2971  for ( j=1; j<epa->npoints; ++j )
2972  {
2973  getPoint2d_p(epa, j, &p2);
2974  LWDEBUGF(1, "Edge %" LWTFMT_ELEMID " 'next' point %d is %g,%g",
2975  isoe->edge_id, j, p2.x, p2.y);
2976  /* we won't check duplicated edge points */
2977  if ( P2D_SAME_STRICT(&p1, &p2) ) continue;
2978  /* we assume there are no duplicated points in ring */
2979  getPoint2d_p(ring, from+1, &pt);
2980  LWDEBUGF(1, "Ring's point %d is %g,%g",
2981  from+1, pt.x, pt.y);
2982  match = P2D_SAME_STRICT(&pt, &p2);
2983  break; /* we want to check a single non-equal next vertex */
2984  }
2985 #if POSTGIS_DEBUG_LEVEL > 0
2986  if ( match ) {
2987  LWDEBUGF(1, "Prev point of edge %" LWTFMT_ELEMID
2988  " matches ring vertex %d", isoe->edge_id, from+1);
2989  } else {
2990  LWDEBUGF(1, "Prev point of edge %" LWTFMT_ELEMID
2991  " does not match ring vertex %d", isoe->edge_id, from+1);
2992  }
2993 #endif
2994  }
2995 
2996  if ( ! match )
2997  {
2998  LWDEBUGF(1, "Edge %" LWTFMT_ELEMID " did not match as forward",
2999  isoe->edge_id);
3000  getPoint2d_p(epa, epa->npoints-1, &p2);
3001  LWDEBUGF(1, "Edge %" LWTFMT_ELEMID " 'last' point is %g,%g",
3002  isoe->edge_id, p2.x, p2.y);
3003  if ( P2D_SAME_STRICT(&p1, &p2) )
3004  {
3005  LWDEBUGF(1, "Last point of edge %" LWTFMT_ELEMID
3006  " matches ring vertex %d", isoe->edge_id, from);
3007  /* last point matches, let's check next non-equal one */
3008  for ( j=2; j<=epa->npoints; j++ )
3009  {
3010  getPoint2d_p(epa, epa->npoints - j, &p2);
3011  LWDEBUGF(1, "Edge %" LWTFMT_ELEMID " 'prev' point %d is %g,%g",
3012  isoe->edge_id, epa->npoints - j, p2.x, p2.y);
3013  /* we won't check duplicated edge points */
3014  if ( P2D_SAME_STRICT(&p1, &p2) ) continue;
3015  /* we assume there are no duplicated points in ring */
3016  getPoint2d_p(ring, from+1, &pt);
3017  LWDEBUGF(1, "Ring's point %d is %g,%g",
3018  from+1, pt.x, pt.y);
3019  match = P2D_SAME_STRICT(&pt, &p2);
3020  break; /* we want to check a single non-equal next vertex */
3021  }
3022  }
3023 #if POSTGIS_DEBUG_LEVEL > 0
3024  if ( match ) {
3025  LWDEBUGF(1, "Prev point of edge %" LWTFMT_ELEMID
3026  " matches ring vertex %d", isoe->edge_id, from+1);
3027  } else {
3028  LWDEBUGF(1, "Prev point of edge %" LWTFMT_ELEMID
3029  " does not match ring vertex %d", isoe->edge_id, from+1);
3030  }
3031 #endif
3032  }
3033 
3034  if ( match ) return i;
3035 
3036  }
3037 
3038  return -1;
3039 }
LWGEOM * lwline_as_lwgeom(const LWLINE *obj)
Definition: lwgeom.c:339
#define WKT_EXTENDED
Definition: liblwgeom.h:2186
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 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
#define P2D_SAME_STRICT(a, b)
Definition: lwgeom_topo.c:50
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: