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

Definition at line 19 of file lwlinearreferencing.c.

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

Referenced by ptarray_locate_along(), and ptarray_locate_along_linear().

20 {
21  double m1 = p1->m;
22  double m2 = p2->m;
23  double mprop;
24 
25  /* M is out of range, no new point generated. */
26  if ( (m < FP_MIN(m1,m2)) || (m > FP_MAX(m1,m2)) )
27  {
28  return LW_FALSE;
29  }
30 
31  if( m1 == m2 )
32  {
33  /* Degenerate case: same M on both points.
34  If they are the same point we just return one of them. */
35  if ( p4d_same(p1,p2) )
36  {
37  *pn = *p1;
38  return LW_TRUE;
39  }
40  /* If the points are different we can out.
41  Correct behavior is probably an mprop of 0.5? */
42  lwerror("Zero measure-length line encountered!");
43  return LW_FALSE;
44  }
45 
46  /* M is in range, new point to be generated. */
47  mprop = (m - m1) / (m2 - m1);
48  pn->x = p1->x + (p2->x - p1->x) * mprop;
49  pn->y = p1->y + (p2->y - p1->y) * mprop;
50  pn->z = p1->z + (p2->z - p1->z) * mprop;
51  pn->m = m;
52 
53  /* Offset to the left or right, if necessary. */
54  if ( offset != 0.0 )
55  {
56  double theta = atan2(p2->y - p1->y, p2->x - p1->x);
57  pn->x -= sin(theta) * offset;
58  pn->y += cos(theta) * offset;
59  }
60 
61  return LW_TRUE;
62 }
double x
Definition: liblwgeom.h:336
double m
Definition: liblwgeom.h:336
#define FP_MIN(A, B)
#define LW_FALSE
Definition: liblwgeom.h:62
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:61
double z
Definition: liblwgeom.h:336
double y
Definition: liblwgeom.h:336
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:74
int p4d_same(const POINT4D *p1, const POINT4D *p2)
Definition: lwalgorithm.c:17
#define FP_MAX(A, B)

Here is the call graph for this function:

Here is the caller graph for this function: