~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Linux Cross Reference
Tina4/src/vision/line2/line2.c

Version: ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /** @(#)Functions for manipulating 2D lines
  2  *
  3  * typedef struct line2
  4  * {
  5  * int     type;
  6  * struct vec2 p1, p2;
  7  * struct vec2 v;
  8  * float   length;
  9  * struct list *props;
 10  * }       Line2;
 11  */
 12 
 13 #include <stdio.h>
 14 #include <math.h>
 15 #include <tina/sys.h>
 16 #include <tina/sysfuncs.h>
 17 #include <tina/math.h>
 18 #include <tina/mathfuncs.h>
 19 #include <tina/vision.h>
 20 #include <tina/visionfuncs.h>
 21 #ifdef _PCC
 22 #include <memory.h>
 23 #endif
 24 
 25 Line2  *line2_alloc(unsigned int type)
 26 {
 27     Line2  *line = ts_ralloc(Line2);
 28 
 29     line->type = type;
 30     line->label = new_label();
 31     return (line);
 32 }
 33 
 34 Line2  *line2_make(Vec2 p1, Vec2 p2, unsigned int type)
 35 {
 36     Line2  *line = ts_ralloc(Line2);
 37 
 38     line->type = type;
 39     line->label = new_label();
 40     line->p1 = p1;
 41     line->p2 = p2;
 42     line->p = vec2_times(0.5, vec2_sum(p1, p2));
 43     line->v = vec2_diff(p2, p1);
 44     line->length = (float)vec2_mod(line->v);
 45     line->v = vec2_times(1.0 / line->length, line->v);
 46     line->props = NULL;
 47     return (line);
 48 }
 49 
 50 void    line2_free(Line2 * line)
 51 {
 52     if (line == NULL)
 53         return;
 54     proplist_freelist(line->props);
 55     rfree((void *) line);
 56 }
 57 
 58 Line2  *line2_copy(Line2 * line)
 59 {
 60     Line2  *copy;
 61     List   *proplist_copy();
 62 
 63     if (line == NULL)
 64         return (NULL);
 65 
 66     copy = ts_ralloc(Line2);
 67     (void) memcpy((char *) copy, (char *) line, sizeof(Line2));
 68     copy->props = proplist_copy(line->props);
 69     return (copy);
 70 }
 71 
 72 Line2  *line2_negative(Line2 * line)
 73 {
 74     if (line == NULL)
 75         return (NULL);
 76 
 77     line = line2_copy(line);
 78     SWAP(Vec2, line->p1, line->p2);
 79     line->v = vec2_minus(line->v);
 80     return (line);
 81 }
 82 
 83 void    line2_negate(Line2 * line)
 84 {
 85     if (line == NULL)
 86         return;
 87 
 88     SWAP(Vec2, line->p1, line->p2);
 89     line->v = vec2_minus(line->v);
 90 }
 91 
 92 Bool    line2_point_on_line(Line2 * line, Vec2 p, double thres)
 93 {
 94     Vec2    d = {Vec2_id};
 95     double  dp;
 96 
 97     d = vec2_diff(p, line->p1);
 98     dp = vec2_dot(line->v, d);
 99     d = vec2_diff(d, vec2_times(dp, line->v));
100     return ((vec2_sqrmod(d) < SQR(thres)) ? true : false);
101 }
102 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.