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

Linux Cross Reference
Tina6/tina-libs/tina/math/mathUtil_math.c

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

  1 /**********
  2  *
  3  * Copyright (c) 2003, Division of Imaging Science and Biomedical Engineering,
  4  * University of Manchester, UK.  All rights reserved.
  5  * 
  6  * Redistribution and use in source and binary forms, with or without modification, 
  7  * are permitted provided that the following conditions are met:
  8  * 
  9  *   . Redistributions of source code must retain the above copyright notice, 
 10  *     this list of conditions and the following disclaimer.
 11  *    
 12  *   . Redistributions in binary form must reproduce the above copyright notice,
 13  *     this list of conditions and the following disclaimer in the documentation 
 14  *     and/or other materials provided with the distribution.
 15  * 
 16  *   . Neither the name of the University of Manchester nor the names of its
 17  *     contributors may be used to endorse or promote products derived from this 
 18  *     software without specific prior written permission.
 19  * 
 20  * 
 21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
 22  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
 23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
 24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
 25  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
 26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
 27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
 29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
 30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
 31  * POSSIBILITY OF SUCH DAMAGE.
 32  *
 33  **********
 34  *
 35  * Program :    TINA
 36  * File    :  $Source: /home/tina/cvs/tina-libs/tina/math/mathUtil_math.c,v $
 37  * Date    :  $Date: 2003/09/23 11:32:20 $
 38  * Version :  $Revision: 1.5 $
 39  * CVS Id  :  $Id: mathUtil_math.c,v 1.5 2003/09/23 11:32:20 matts Exp $
 40  *
 41  * Author  :  Legacy TINA
 42  *
 43  * Notes : Maths (simple functions, eg imax3: (returns biggest of 3 ints)
 44  *
 45  *********
 46 */
 47 /** 
 48  *  @file
 49  *  @brief  Various useful simple maths functions.      
 50  *
 51  *  Functions include;
 52  *
 53  *  - wrapper around acos.
 54  *  - finding the min distance between two points.
 55  *  - finding the min/max value of a doublet/triplet of values.
 56  * 
 57 */
 58 
 59 #include "mathUtil_math.h"
 60 
 61 #if HAVE_CONFIG_H
 62 #include <config.h>
 63 #endif
 64 
 65 
 66 #include <math.h>
 67 
 68 double          tina_acos(double c)
 69 {
 70         if (c > 1.0)
 71                 c = 1.0;
 72         else if (c < -1.0)
 73                 c = -1.0;
 74         return (acos(c));
 75 }
 76 
 77 double          sqr(double x)
 78 {
 79         return (x * x);
 80 }
 81 
 82 double          dist2(double x1, double y1, double x2, double y2)
 83 {
 84         double          dx = x2 - x1;
 85         double          dy = y2 - y1;
 86 
 87         return (sqrt(dx * dx + dy * dy));
 88 }
 89 
 90 int             imin(int x, int y)
 91 {
 92         return ((x < y) ? x : y);
 93 }
 94 
 95 int             imax(int x, int y)
 96 {
 97         return ((x > y) ? x : y);
 98 }
 99 
100 double          tina_fmin(double x, double y)
101 {
102         return ((x < y) ? x : y);
103 }
104 
105 double          tina_fmax(double x, double y)
106 {
107         return ((x > y) ? x : y);
108 }
109 
110 int             imin3(int x, int y, int z)
111 {
112         return ((x < (y = imin(y, z))) ? x : y);
113 }
114 
115 int             imax3(int x, int y, int z)
116 {
117         return ((x > (y = imax(y, z))) ? x : y);
118 }
119 
120 double          fmin3(double x, double y, double z)
121 {
122         return ((x < (y = tina_fmin(y, z))) ? x : y);
123 }
124 
125 double          fmax3(double x, double y, double z)
126 {
127         return ((x > (y = tina_fmax(y, z))) ? x : y);
128 }
129 

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