PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ segment_locate_along()

static int segment_locate_along ( const POINT4D p1,
const POINT4D p2,
double  m,
double  offset,
POINT4D pn 
)
static

Definition at line 31 of file lwlinearreferencing.c.

References FP_MAX, FP_MIN, LW_FALSE, LW_TRUE, POINT4D::m, p4d_same(), POINT4D::x, POINT4D::y, and POINT4D::z.

Referenced by ptarray_locate_along(), and ptarray_locate_along_linear().

32 {
33  double m1 = p1->m;
34  double m2 = p2->m;
35  double mprop;
36 
37  /* M is out of range, no new point generated. */
38  if ( (m < FP_MIN(m1,m2)) || (m > FP_MAX(m1,m2)) )
39  {
40  return LW_FALSE;
41  }
42 
43  if( m1 == m2 )
44  {
45  /* Degenerate case: same M on both points.
46  If they are the same point we just return one of them. */
47  if ( p4d_same(p1,p2) )
48  {
49  *pn = *p1;
50  return LW_TRUE;
51  }
52  /* If the points are different we split the difference */
53  mprop = 0.5;
54  }
55  else
56  {
57  mprop = (m - m1) / (m2 - m1);
58  }
59 
60  /* M is in range, new point to be generated. */
61  pn->x = p1->x + (p2->x - p1->x) * mprop;
62  pn->y = p1->y + (p2->y - p1->y) * mprop;
63  pn->z = p1->z + (p2->z - p1->z) * mprop;
64  pn->m = m;
65 
66  /* Offset to the left or right, if necessary. */
67  if ( offset != 0.0 )
68  {
69  double theta = atan2(p2->y - p1->y, p2->x - p1->x);
70  pn->x -= sin(theta) * offset;
71  pn->y += cos(theta) * offset;
72  }
73 
74  return LW_TRUE;
75 }
double x
Definition: liblwgeom.h:352
double m
Definition: liblwgeom.h:352
#define FP_MIN(A, B)
#define LW_FALSE
Definition: liblwgeom.h:77
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:76
double z
Definition: liblwgeom.h:352
double y
Definition: liblwgeom.h:352
int p4d_same(const POINT4D *p1, const POINT4D *p2)
Definition: lwalgorithm.c:31
#define FP_MAX(A, B)
Here is the call graph for this function:
Here is the caller graph for this function: