PostGIS  2.5.0dev-r@@SVN_REVISION@@
static int segment_locate_along ( const POINT4D p1,
const POINT4D p2,
double  m,
double  offset,
POINT4D pn 
)
static

Definition at line 32 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().

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