Back to index

texmacs  1.0.7.15
Typedefs | Functions
poly_line.hpp File Reference
#include "tree.hpp"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

typedef array< double > point
typedef array< pointpoly_line
typedef array< poly_linecontours

Functions

point operator- (point p)
point operator+ (point p1, point p2)
point operator- (point p1, point p2)
point operator* (double x, point p)
point operator/ (point p, double x)
bool operator== (point p1, point p2)
double l2_norm (point p)
double min (point p)
double max (point p)
double inner (point p, point q)
double distance (point p, point q)
point project (point p, point q1, point q2)
double distance (point p, point q1, point q2)
point inf (point p, point q)
point sup (point p, point q)
bool nearby (point p, poly_line pl)
point inf (poly_line pl)
point sup (poly_line pl)
poly_line normalize (poly_line pl)
double length (poly_line pl)
point access (poly_line pl, double t)
array< double > vertices (poly_line pl)
void invariants (contours gl, int level, array< tree > &disc, array< double > &cont)

Typedef Documentation

Definition at line 16 of file poly_line.hpp.

typedef array<double> point

Definition at line 14 of file poly_line.hpp.

typedef array<point> poly_line

Definition at line 15 of file poly_line.hpp.


Function Documentation

point access ( poly_line  pl,
double  t 
)

Definition at line 193 of file poly_line.cpp.

                                {
  if (t < 0) return pl[0];
  for (int i=1; i<N(pl); i++) {
    point dp= pl[i] - pl[i-1];
    double len= l2_norm (dp);
    if (t < len) return pl[i-1] + (t / len) * dp;
    t -= len;
  }
  return pl[N(pl)-1];
}

Here is the call graph for this function:

Here is the caller graph for this function:

double distance ( point  p,
point  q 
)

Definition at line 56 of file poly_line.cpp.

                            {
  ASSERT (N(p) == N(q), "unequal lengths");
  double s= 0.0;
  for (int i=0; i<N(p); i++)
    s += square (q[i] - p[i]);
  return sqrt (s);
}

Here is the call graph for this function:

Here is the caller graph for this function:

double distance ( point  p,
point  q1,
point  q2 
)

Definition at line 80 of file poly_line.cpp.

                                       {
  if (q1 == q2) return distance (p, q1);
  else return distance (p, project (p, q1, q2));
}

Here is the call graph for this function:

point inf ( point  p,
point  q 
)

Definition at line 86 of file poly_line.cpp.

                       {
  ASSERT (N(p) == N(q), "unequal lengths");
  point r (N(p));
  for (int i=0; i<N(p); i++)
    r[i]= min (p[i], q[i]);
  return r;
}

Here is the call graph for this function:

Here is the caller graph for this function:

point inf ( poly_line  pl)

Definition at line 130 of file poly_line.cpp.

                   {
  ASSERT (N(pl) > 0, "non zero length expected");
  point p= pl[0];
  for (int i=1; i<N(pl); i++)
    p= inf (p, pl[i]);
  return p;
}

Here is the call graph for this function:

double inner ( point  p,
point  q 
)

Definition at line 47 of file poly_line.cpp.

                         {
  ASSERT (N(p) == N(q), "unequal lengths");
  double s= 0.0;
  for (int i=0; i<N(p); i++)
    s += p[i] * q[i];
  return s;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void invariants ( contours  gl,
int  level,
array< tree > &  disc,
array< double > &  cont 
)

Definition at line 338 of file poly_line.cpp.

{
  gl= normalize (gl);
  disc << tree (as_string (N(gl)));
  for (int i=0; i<N(gl); i++)
    invariants (gl[i], level, disc, cont);
}

Here is the call graph for this function:

double l2_norm ( point  p)

Definition at line 39 of file poly_line.cpp.

                  {
  double s= 0.0;
  for (int i=0; i<N(p); i++)
    s += square (p[i]);
  return sqrt (s);
}

Here is the call graph for this function:

Here is the caller graph for this function:

double length ( poly_line  pl)

Definition at line 185 of file poly_line.cpp.

                      {
  double len= 0.0;
  for (int i=1; i<N(pl); i++)
    len += distance (pl[i], pl[i-1]);
  return len;
}

Here is the call graph for this function:

double max ( point  p)

Definition at line 30 of file poly_line.cpp.

              {
  ASSERT (N(p) > 0, "non zero length expected");
  double r= p[0];
  for (int i=1; i<N(p); i++)
    r= max (r, p[i]);
  return r;
}

Here is the call graph for this function:

double min ( point  p)

Definition at line 21 of file poly_line.cpp.

              {
  ASSERT (N(p) > 0, "non zero length expected");
  double r= p[0];
  for (int i=1; i<N(p); i++)
    r= min (r, p[i]);
  return r;
}

Here is the call graph for this function:

bool nearby ( point  p,
poly_line  pl 
)

Definition at line 125 of file poly_line.cpp.

                               {
  return distance (p, pl) <= 5.0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 175 of file poly_line.cpp.

                         {
  if (N(pl) == 0) return pl;
  pl= pl - inf (pl);
  if (N(pl) == 1) return pl;
  double sc= max (sup (pl));
  if (sc == 0.0) return pl;
  return (1.0 / sc) * pl;
}

Here is the call graph for this function:

Here is the caller graph for this function:

point operator* ( double  x,
point  p 
)

Definition at line 43 of file point.cpp.

                               {
  int i, n= N(p);
  point r (n);
  for (i=0; i<n; i++)
    r[i]= x * p[i];
  return r;
}
point operator+ ( point  p1,
point  p2 
)

Definition at line 25 of file point.cpp.

                                {
  int i, n= min (N(p1), N(p2));
  point r (n);
  for (i=0; i<n; i++)
    r[i]= p1[i] + p2[i];
  return r;
}
point operator- ( point  p)

Definition at line 16 of file point.cpp.

                     {
  int i, n= N(p);
  point r (n);
  for (i=0; i<n; i++)
    r[i]= - p[i];
  return r;
}
point operator- ( point  p1,
point  p2 
)

Definition at line 34 of file point.cpp.

                                {
  int i, n= min (N(p1), N(p2));
  point r (n);
  for (i=0; i<n; i++)
    r[i]= p1[i] - p2[i];
  return r;
}
point operator/ ( point  p,
double  x 
)

Definition at line 52 of file point.cpp.

                               {
  int i, n= N(p);
  point r (n);
  for (i=0; i<n; i++)
    r[i]= p[i] / x;
  return r;
}
bool operator== ( point  p1,
point  p2 
)

Definition at line 61 of file point.cpp.

                                 {
  if (N(p1) != N(p2)) return false;
  int i, n= N(p1);
  for (i=0; i<n; i++)
    if (!fnull (p1[i]-p2[i], 1e-6)) return false;
  return true;
}
point project ( point  p,
point  q1,
point  q2 
)

Definition at line 65 of file poly_line.cpp.

                                      {
  ASSERT (N(p) == N(q1) && N(p) == N(q2), "unequal lengths");
  int i, n= N(p);
  double s= 0.0, t= 0.0;
  for (i=0; i<n; i++) {
    s += (q2[i] - q1[i]) * (p[i] - q1[i]);
    t += square (q2[i] - q1[i]);
  }
  double a= s / t;
  if (a < 0.0) return q1;
  if (a > 1.0) return q2;
  return q1 + a * (q2 - q1);
}

Here is the call graph for this function:

Here is the caller graph for this function:

point sup ( point  p,
point  q 
)

Definition at line 95 of file poly_line.cpp.

                       {
  ASSERT (N(p) == N(q), "unequal lengths");
  point r (N(p));
  for (int i=0; i<N(p); i++)
    r[i]= max (p[i], q[i]);
  return r;
}

Here is the call graph for this function:

Here is the caller graph for this function:

point sup ( poly_line  pl)

Definition at line 139 of file poly_line.cpp.

                   {
  ASSERT (N(pl) > 0, "non zero length expected");
  point p= pl[0];
  for (int i=1; i<N(pl); i++)
    p= sup (p, pl[i]);
  return p;
}

Here is the call graph for this function:

array<double> vertices ( poly_line  pl)

Definition at line 281 of file poly_line.cpp.

                        {
  pl= (1.0 / length (pl)) * pl;
  array<double> r;
  double t = 0.0;
  double dt= 0.025;
  r << 0.0;
  int    todo_i= -1;
  double todo_t= 0.0;
  double todo_p= 0.0;
  for (int i=0; i+1<N(pl); i++) {
    if (t >= r[N(r)-1] + dt && t <= 1.0 - dt) {
      double t1= max (t - dt, 0.000000001);
      double t2= min (t + dt, 0.999999999);
      point  p = pl[i];
      point  p1= access (pl, t1);
      point  p2= access (pl, t2);
      double pr= inner (p1 - p, p2 - p);
      if (pr >= 0 && (todo_i < 0 || pr > todo_p)) {
        todo_i= i;
        todo_t= t;
        todo_p= pr;
      }
    }
    t += distance (pl[i+1], pl[i]);
    if (todo_i >= 0 && t >= todo_t + dt) {
      r << todo_t;
      todo_i= -1;
    }
  }
  r << 1.0;
  return r;
}

Here is the call graph for this function:

Here is the caller graph for this function: