PostGIS  3.7.0dev-r@@SVN_REVISION@@

◆ ptarray_simplify_in_place_tolerance0()

static void ptarray_simplify_in_place_tolerance0 ( POINTARRAY pa)
static

Definition at line 1675 of file ptarray.c.

1676 {
1677  uint32_t kept_it = 0;
1678  uint32_t last_it = pa->npoints - 1;
1679  const POINT2D *kept_pt = getPoint2d_cp(pa, 0);
1680  const size_t pt_size = ptarray_point_size(pa);
1681 
1682  for (uint32_t i = 1; i < last_it; i++)
1683  {
1684  const POINT2D *curr_pt = getPoint2d_cp(pa, i);
1685  const POINT2D *next_pt = getPoint2d_cp(pa, i + 1);
1686 
1687  double ba_x = next_pt->x - kept_pt->x;
1688  double ba_y = next_pt->y - kept_pt->y;
1689  double ab_length_sqr = ba_x * ba_x + ba_y * ba_y;
1690 
1691  double ca_x = curr_pt->x - kept_pt->x;
1692  double ca_y = curr_pt->y - kept_pt->y;
1693  double dot_ac_ab = ca_x * ba_x + ca_y * ba_y;
1694  double s_numerator = ca_x * ba_y - ca_y * ba_x;
1695 
1696  if (p2d_same(kept_pt, next_pt) ||
1697  dot_ac_ab < 0.0 ||
1698  dot_ac_ab > ab_length_sqr ||
1699  s_numerator != 0)
1700 
1701  {
1702  kept_it++;
1703  kept_pt = curr_pt;
1704  if (kept_it != i)
1705  memcpy(pa->serialized_pointlist + pt_size * kept_it,
1706  pa->serialized_pointlist + pt_size * i,
1707  pt_size);
1708  }
1709  }
1710 
1711  /* Append last point */
1712  kept_it++;
1713  if (kept_it != last_it)
1714  memcpy(pa->serialized_pointlist + pt_size * kept_it,
1715  pa->serialized_pointlist + pt_size * last_it,
1716  pt_size);
1717  pa->npoints = kept_it + 1;
1718 }
int p2d_same(const POINT2D *p1, const POINT2D *p2)
Definition: lwalgorithm.c:57
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:97
static size_t ptarray_point_size(const POINTARRAY *pa)
Definition: lwinline.h:56
double y
Definition: liblwgeom.h:390
double x
Definition: liblwgeom.h:390
uint32_t npoints
Definition: liblwgeom.h:427
uint8_t * serialized_pointlist
Definition: liblwgeom.h:434

References getPoint2d_cp(), POINTARRAY::npoints, p2d_same(), 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: