PostGIS  2.2.8dev-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 2901 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().

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