PostGIS  3.1.6dev-r@@SVN_REVISION@@

◆ ptarray_simplify_in_place_tolerance0()

static void ptarray_simplify_in_place_tolerance0 ( POINTARRAY pa)
static

Definition at line 1596 of file ptarray.c.

1597 {
1598  uint32_t kept_it = 0;
1599  uint32_t last_it = pa->npoints - 1;
1600  const POINT2D *kept_pt = getPoint2d_cp(pa, 0);
1601  const size_t pt_size = ptarray_point_size(pa);
1602 
1603  for (uint32_t i = 1; i < last_it; i++)
1604  {
1605  const POINT2D *curr_pt = getPoint2d_cp(pa, i);
1606  const POINT2D *next_pt = getPoint2d_cp(pa, i + 1);
1607 
1608  double ba_x = next_pt->x - kept_pt->x;
1609  double ba_y = next_pt->y - kept_pt->y;
1610  double ab_length_sqr = ba_x * ba_x + ba_y * ba_y;
1611 
1612  double ca_x = curr_pt->x - kept_pt->x;
1613  double ca_y = curr_pt->y - kept_pt->y;
1614  double dot_ac_ab = ca_x * ba_x + ca_y * ba_y;
1615  double s_numerator = ca_x * ba_y - ca_y * ba_x;
1616 
1617  if (dot_ac_ab < 0.0 || dot_ac_ab > ab_length_sqr || s_numerator != 0)
1618  {
1619  kept_it++;
1620  kept_pt = curr_pt;
1621  if (kept_it != i)
1622  memcpy(pa->serialized_pointlist + pt_size * kept_it,
1623  pa->serialized_pointlist + pt_size * i,
1624  pt_size);
1625  }
1626  }
1627 
1628  /* Append last point */
1629  kept_it++;
1630  if (kept_it != last_it)
1631  memcpy(pa->serialized_pointlist + pt_size * kept_it,
1632  pa->serialized_pointlist + pt_size * last_it,
1633  pt_size);
1634  pa->npoints = kept_it + 1;
1635 }
static const POINT2D * getPoint2d_cp(const POINTARRAY *pa, uint32_t n)
Returns a POINT2D pointer into the POINTARRAY serialized_ptlist, suitable for reading from.
Definition: lwinline.h:101
static size_t ptarray_point_size(const POINTARRAY *pa)
Definition: lwinline.h:58
double y
Definition: liblwgeom.h:404
double x
Definition: liblwgeom.h:404
uint32_t npoints
Definition: liblwgeom.h:441
uint8_t * serialized_pointlist
Definition: liblwgeom.h:448

References getPoint2d_cp(), POINTARRAY::npoints, ptarray_point_size(), POINTARRAY::serialized_pointlist, POINT2D::x, and POINT2D::y.

Referenced by ptarray_simplify_in_place().

Here is the call graph for this function:
Here is the caller graph for this function: