PostGIS  2.4.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 2931 of file lwgeom_topo.c.

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(), LWLINE::points, WKT_EXTENDED, POINT2D::x, and POINT2D::y.

Referenced by lwt_GetFaceEdges().

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