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

Definition at line 18 of file lwlinearreferencing.c.

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

Referenced by ptarray_locate_along().

19 {
20  double m1 = p1->m;
21  double m2 = p2->m;
22  double mprop;
23 
24  /* M is out of range, no new point generated. */
25  if ( (m < FP_MIN(m1,m2)) || (m > FP_MAX(m1,m2)) )
26  {
27  return LW_FALSE;
28  }
29 
30  /* We'll just can out on this degenerate case for now.
31  Correct behavior is probably an mprop of 0.5?
32  Still would have to deal with case of true p1==p2. */
33  if( m1 == m2 )
34  {
35  lwerror("Zero measure-length line encountered!");
36  }
37 
38  /* M is in range, new point to be generated. */
39  mprop = (m - m1) / (m2 - m1);
40  pn->x = p1->x + (p2->x - p1->x) * mprop;
41  pn->y = p1->y + (p2->y - p1->y) * mprop;
42  pn->z = p1->z + (p2->z - p1->z) * mprop;
43  pn->m = m;
44 
45  /* Offset to the left or right, if necessary. */
46  if ( offset != 0.0 )
47  {
48  double theta = atan2(p2->y - p1->y, p2->x - p1->x);
49  pn->x -= sin(theta) * offset;
50  pn->y += cos(theta) * offset;
51  }
52 
53  return LW_TRUE;
54 }
double x
Definition: liblwgeom.h:308
double m
Definition: liblwgeom.h:308
#define FP_MIN(A, B)
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:67
#define LW_FALSE
Definition: liblwgeom.h:52
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:51
double z
Definition: liblwgeom.h:308
double y
Definition: liblwgeom.h:308
#define FP_MAX(A, B)

Here is the call graph for this function:

Here is the caller graph for this function: