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

Linux Cross Reference
Tina6/tina-libs/tina/geometry/geomLine_2line.c

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

  1 /**********
  2  * 
  3  * This file is part of the TINA Open Source Image Analysis Environment
  4  * henceforth known as TINA
  5  *
  6  * TINA is free software; you can redistribute it and/or modify
  7  * it under the terms of the GNU General Public License as 
  8  * published by the Free Software Foundation.
  9  *
 10  * TINA is distributed in the hope that it will be useful,
 11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 13  * GNU General Public License for more details.
 14  *
 15  * You should have received a copy of the GNU General Public License
 16  * along with TINA; if not, write to the Free Software Foundation, Inc., 
 17  * 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 18  *
 19  * ANY users of TINA who require exemption from the existing licence must
 20  * negotiate a new licence with Dr. Neil.A.Thacker, the sole agent for
 21  * the University of Manchester.
 22  *
 23  **********
 24  * 
 25  * Program :    TINA
 26  * File    :  $Source: /home/tina/cvs/tina-libs/tina/geometry/geomLine_2line.c,v $
 27  * Date    :  $Date: 2005/01/09 17:49:25 $
 28  * Version :  $Revision: 1.2 $
 29  * CVS Id  :  $Id: geomLine_2line.c,v 1.2 2005/01/09 17:49:25 paul Exp $
 30  *
 31  * Notes : Functions for manipulating 2D lines
 32  *
 33  *********
 34 */
 35 
 36 
 37 #include "geomLine_2line.h"
 38 
 39 #if HAVE_CONFIG_H
 40   #include <config.h>
 41 #endif
 42 
 43 #include <stdio.h>
 44 #include <math.h>
 45 #include <string.h>
 46 #include <tina/sys/sysDef.h>
 47 #include <tina/sys/sysPro.h>
 48 #include <tina/math/mathDef.h>
 49 #include <tina/math/mathPro.h>
 50 #include <tina/geometry/geom_LineDef.h>
 51 #ifdef _PCC
 52 #include <memory.h>
 53 #endif
 54 
 55 Line2  *line2_alloc(unsigned int type)
 56 {
 57     Line2  *line = ts_ralloc(Line2);
 58 
 59     line->type = type;
 60     line->label = new_label();
 61     return (line);
 62 }
 63 
 64 Line2  *line2_make(Vec2 p1, Vec2 p2, unsigned int type)
 65 {
 66     Line2  *line = ts_ralloc(Line2);
 67 
 68     line->type = type;
 69     line->label = new_label();
 70     line->p1 = p1;
 71     line->p2 = p2;
 72     line->p = vec2_times(0.5, vec2_sum(p1, p2));
 73     line->v = vec2_diff(p2, p1);
 74     line->length = (float)vec2_mod(line->v);
 75     line->v = vec2_times(1.0 / line->length, line->v);
 76     line->props = NULL;
 77     return (line);
 78 }
 79 
 80 void    line2_free(Line2 * line)
 81 {
 82     if (line == NULL)
 83         return;
 84     proplist_freelist(line->props);
 85     rfree((void *) line);
 86 }
 87 
 88 Line2  *line2_copy(Line2 * line)
 89 {
 90     Line2  *copy;
 91     List   *proplist_copy();
 92 
 93     if (line == NULL)
 94         return (NULL);
 95 
 96     copy = ts_ralloc(Line2);
 97     (void) memcpy((char *) copy, (char *) line, sizeof(Line2));
 98     copy->props = proplist_copy(line->props);
 99     return (copy);
100 }
101 
102 Line2  *line2_negative(Line2 * line)
103 {
104     if (line == NULL)
105         return (NULL);
106 
107     line = line2_copy(line);
108     SWAP(Vec2, line->p1, line->p2);
109     line->v = vec2_minus(line->v);
110     return (line);
111 }
112 
113 void    line2_negate(Line2 * line)
114 {
115     if (line == NULL)
116         return;
117 
118     SWAP(Vec2, line->p1, line->p2);
119     line->v = vec2_minus(line->v);
120 }
121 
122 Bool    line2_point_on_line(Line2 * line, Vec2 p, double thres)
123 {
124     Vec2    d = {Vec2_id};
125     double  dp;
126 
127     d = vec2_diff(p, line->p1);
128     dp = vec2_dot(line->v, d);
129     d = vec2_diff(d, vec2_times(dp, line->v));
130     return ((vec2_sqrmod(d) < SQR(thres)) ? true : false);
131 }
132 

~ [ 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.