PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ is_clockwise()

static int is_clockwise ( int  num_points,
double *  x,
double *  y,
double *  z 
)
static

Definition at line 490 of file pgsql2shp-core.c.

References area(), free(), and malloc().

Referenced by create_multipolygon(), create_polygon(), and ST_IsPolygonCW().

491 {
492  int i;
493  double x_change,y_change,area;
494  double *x_new, *y_new; /* the points, translated to the origin
495  * for safer accuracy */
496 
497  x_new = (double *)malloc(sizeof(double) * num_points);
498  y_new = (double *)malloc(sizeof(double) * num_points);
499  area=0.0;
500  x_change = x[0];
501  y_change = y[0];
502 
503  for (i=0; i < num_points ; i++)
504  {
505  x_new[i] = x[i] - x_change;
506  y_new[i] = y[i] - y_change;
507  }
508 
509  for (i=0; i < num_points - 1; i++)
510  {
511  /* calculate the area */
512  area += (x[i] * y[i+1]) - (y[i] * x[i+1]);
513  }
514  if (area > 0 )
515  {
516  free(x_new);
517  free(y_new);
518  return 0; /*counter-clockwise */
519  }
520  else
521  {
522  free(x_new);
523  free(y_new);
524  return 1; /*clockwise */
525  }
526 }
Datum area(PG_FUNCTION_ARGS)
void free(void *)
void * malloc(YYSIZE_T)
Here is the call graph for this function:
Here is the caller graph for this function: