PostGIS  2.5.0beta2dev-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 2851 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().

2853 {
2854  int i;
2855  POINT2D p1;
2856 
2857  /* Get starting ring point */
2858  getPoint2d_p(ring, from, &p1);
2859 
2860  LWDEBUGF(1, "Ring's 'from' point (%d) is %g,%g", from, p1.x, p1.y);
2861 
2862  /* find the edges defining the next portion of ring starting from
2863  * vertex "from" */
2864  for ( i=0; i<numedges; ++i )
2865  {
2866  const LWT_ISO_EDGE *isoe = &(edges[i]);
2867  LWLINE *edge = isoe->geom;
2868  POINTARRAY *epa = edge->points;
2869  POINT2D p2, pt;
2870  int match = 0;
2871  uint32_t j;
2872 
2873  /* Skip if the edge is a dangling one */
2874  if ( isoe->face_left == isoe->face_right )
2875  {
2876  LWDEBUGF(3, "_lwt_FindNextRingEdge: edge %" LWTFMT_ELEMID
2877  " has same face (%" LWTFMT_ELEMID
2878  ") on both sides, skipping",
2879  isoe->edge_id, isoe->face_left);
2880  continue;
2881  }
2882 
2883  if (epa->npoints < 2)
2884  {
2885  LWDEBUGF(3, "_lwt_FindNextRingEdge: edge %" LWTFMT_ELEMID
2886  " has only %"PRIu32" points",
2887  isoe->edge_id, epa->npoints);
2888  continue;
2889  }
2890 
2891 #if 0
2892  size_t sz;
2893  LWDEBUGF(1, "Edge %" LWTFMT_ELEMID " is %s",
2894  isoe->edge_id,
2895  lwgeom_to_wkt(lwline_as_lwgeom(edge), WKT_EXTENDED, 2, &sz));
2896 #endif
2897 
2898  /* ptarray_remove_repeated_points ? */
2899 
2900  getPoint2d_p(epa, 0, &p2);
2901  LWDEBUGF(1, "Edge %" LWTFMT_ELEMID " 'first' point is %g,%g",
2902  isoe->edge_id, p2.x, p2.y);
2903  LWDEBUGF(1, "Rings's 'from' point is still %g,%g", p1.x, p1.y);
2904  if ( p2d_same(&p1, &p2) )
2905  {
2906  LWDEBUG(1, "p2d_same(p1,p2) returned true");
2907  LWDEBUGF(1, "First point of edge %" LWTFMT_ELEMID
2908  " matches ring vertex %d", isoe->edge_id, from);
2909  /* first point matches, let's check next non-equal one */
2910  for ( j=1; j<epa->npoints; ++j )
2911  {
2912  getPoint2d_p(epa, j, &p2);
2913  LWDEBUGF(1, "Edge %" LWTFMT_ELEMID " 'next' point %d is %g,%g",
2914  isoe->edge_id, j, p2.x, p2.y);
2915  /* we won't check duplicated edge points */
2916  if ( p2d_same(&p1, &p2) ) continue;
2917  /* we assume there are no duplicated points in ring */
2918  getPoint2d_p(ring, from+1, &pt);
2919  LWDEBUGF(1, "Ring's point %d is %g,%g",
2920  from+1, pt.x, pt.y);
2921  match = p2d_same(&pt, &p2);
2922  break; /* we want to check a single non-equal next vertex */
2923  }
2924 #if POSTGIS_DEBUG_LEVEL > 0
2925  if ( match ) {
2926  LWDEBUGF(1, "Prev point of edge %" LWTFMT_ELEMID
2927  " matches ring vertex %d", isoe->edge_id, from+1);
2928  } else {
2929  LWDEBUGF(1, "Prev point of edge %" LWTFMT_ELEMID
2930  " does not match ring vertex %d", isoe->edge_id, from+1);
2931  }
2932 #endif
2933  }
2934 
2935  if ( ! match )
2936  {
2937  LWDEBUGF(1, "Edge %" LWTFMT_ELEMID " did not match as forward",
2938  isoe->edge_id);
2939  getPoint2d_p(epa, epa->npoints-1, &p2);
2940  LWDEBUGF(1, "Edge %" LWTFMT_ELEMID " 'last' point is %g,%g",
2941  isoe->edge_id, p2.x, p2.y);
2942  if ( p2d_same(&p1, &p2) )
2943  {
2944  LWDEBUGF(1, "Last point of edge %" LWTFMT_ELEMID
2945  " matches ring vertex %d", isoe->edge_id, from);
2946  /* last point matches, let's check next non-equal one */
2947  for ( j=2; j<=epa->npoints; j++ )
2948  {
2949  getPoint2d_p(epa, epa->npoints - j, &p2);
2950  LWDEBUGF(1, "Edge %" LWTFMT_ELEMID " 'prev' point %d is %g,%g",
2951  isoe->edge_id, epa->npoints - j, p2.x, p2.y);
2952  /* we won't check duplicated edge points */
2953  if ( p2d_same(&p1, &p2) ) continue;
2954  /* we assume there are no duplicated points in ring */
2955  getPoint2d_p(ring, from+1, &pt);
2956  LWDEBUGF(1, "Ring's point %d is %g,%g",
2957  from+1, pt.x, pt.y);
2958  match = p2d_same(&pt, &p2);
2959  break; /* we want to check a single non-equal next vertex */
2960  }
2961  }
2962 #if POSTGIS_DEBUG_LEVEL > 0
2963  if ( match ) {
2964  LWDEBUGF(1, "Prev point of edge %" LWTFMT_ELEMID
2965  " matches ring vertex %d", isoe->edge_id, from+1);
2966  } else {
2967  LWDEBUGF(1, "Prev point of edge %" LWTFMT_ELEMID
2968  " does not match ring vertex %d", isoe->edge_id, from+1);
2969  }
2970 #endif
2971  }
2972 
2973  if ( match ) return i;
2974 
2975  }
2976 
2977  return -1;
2978 }
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: