PostGIS  2.5.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 2955 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().

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