PostGIS  3.6.1dev-r@@SVN_REVISION@@

◆ lw_dist2d_pt_arc()

int lw_dist2d_pt_arc ( const POINT2D P,
const POINT2D A1,
const POINT2D A2,
const POINT2D A3,
DISTPTS dl 
)

Definition at line 1495 of file measures.c.

1496 {
1497  double radius_A, d;
1498  POINT2D C; /* center of circle defined by arc A */
1499  POINT2D X; /* point circle(A) where line from C to P crosses */
1500 
1501  if (dl->mode < 0)
1502  lwerror("lw_dist2d_pt_arc does not support maxdistance mode");
1503 
1504  /* What if the arc is a point? */
1505  if (lw_arc_is_pt(A1, A2, A3))
1506  return lw_dist2d_pt_pt(P, A1, dl);
1507 
1508  /* Calculate centers and radii of circles. */
1509  radius_A = lw_arc_center(A1, A2, A3, &C);
1510 
1511  /* This "arc" is actually a line (A2 is colinear with A1,A3) */
1512  if (radius_A < 0.0)
1513  return lw_dist2d_pt_seg(P, A1, A3, dl);
1514 
1515  /* Distance from point to center */
1516  d = distance2d_pt_pt(&C, P);
1517 
1518  /* P is the center of the circle */
1519  if (FP_EQUALS(d, 0.0))
1520  {
1521  lw_dist2d_distpts_set(dl, radius_A, A1, P);
1522  return LW_TRUE;
1523  }
1524 
1525  /* X is the point on the circle where the line from P to C crosses */
1526  X.x = C.x + (P->x - C.x) * radius_A / d;
1527  X.y = C.y + (P->y - C.y) * radius_A / d;
1528 
1529  /* Is crossing point inside the arc? Or arc is actually circle? */
1530  if (p2d_same(A1, A3) || lw_pt_in_arc(&X, A1, A2, A3))
1531  {
1532  lw_dist2d_pt_pt(P, &X, dl);
1533  }
1534  else
1535  {
1536  /* Distance is the minimum of the distances to the arc end points */
1537  lw_dist2d_pt_pt(A1, P, dl);
1538  lw_dist2d_pt_pt(A3, P, dl);
1539  }
1540  return LW_TRUE;
1541 }
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:93
double lw_arc_center(const POINT2D *p1, const POINT2D *p2, const POINT2D *p3, POINT2D *result)
Determines the center of the circle defined by the three given points.
Definition: lwalgorithm.c:244
#define FP_EQUALS(A, B)
int lw_arc_is_pt(const POINT2D *A1, const POINT2D *A2, const POINT2D *A3)
Returns true if arc A is actually a point (all vertices are the same) .
Definition: lwalgorithm.c:121
int lw_pt_in_arc(const POINT2D *P, const POINT2D *A1, const POINT2D *A2, const POINT2D *A3)
Returns true if P is on the same side of the plane partition defined by A1/A3 as A2 is.
Definition: lwalgorithm.c:91
int p2d_same(const POINT2D *p1, const POINT2D *p2)
Definition: lwalgorithm.c:57
void void lwerror(const char *fmt,...) __attribute__((format(printf
Write a notice out to the error handler.
double distance2d_pt_pt(const POINT2D *p1, const POINT2D *p2)
Definition: measures.c:2344
static void lw_dist2d_distpts_set(DISTPTS *dl, double distance, const POINT2D *p1, const POINT2D *p2)
Definition: measures.c:81
int lw_dist2d_pt_seg(const POINT2D *p, const POINT2D *A, const POINT2D *B, DISTPTS *dl)
lw_dist2d_comp from p to line A->B This one is now sending every occasion to lw_dist2d_pt_pt Before i...
Definition: measures.c:2217
int lw_dist2d_pt_pt(const POINT2D *thep1, const POINT2D *thep2, DISTPTS *dl)
Compares incoming points and stores the points closest to each other or most far away from each other...
Definition: measures.c:2312
int mode
Definition: measures.h:54
double y
Definition: liblwgeom.h:390
double x
Definition: liblwgeom.h:390

References distance2d_pt_pt(), FP_EQUALS, lw_arc_center(), lw_arc_is_pt(), lw_dist2d_distpts_set(), lw_dist2d_pt_pt(), lw_dist2d_pt_seg(), lw_pt_in_arc(), LW_TRUE, lwerror(), DISTPTS::mode, p2d_same(), POINT2D::x, and POINT2D::y.

Referenced by lw_dist2d_arc_arc(), lw_dist2d_pt_ptarrayarc(), lw_dist2d_seg_arc(), rect_leaf_node_distance(), rect_leaf_node_intersects(), and test_lw_dist2d_pt_arc().

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