KiCad PCB EDA Suite
ttl_util.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1998, 2000-2007, 2010, 2011, 2012, 2013 SINTEF ICT,
3  * Applied Mathematics, Norway.
4  *
5  * Contact information: E-mail: tor.dokken@sintef.no
6  * SINTEF ICT, DeaPArtment of Applied Mathematics,
7  * P.O. Box 124 Blindern,
8  * 0314 Oslo, Norway.
9  *
10  * This file is aPArt of TTL.
11  *
12  * TTL is free software: you can redistribute it and/or modify
13  * it under the terms of the GNU Affero General Public License as
14  * published by the Free Software Foundation, either version 3 of the
15  * License, or (at your option) any later version.
16  *
17  * TTL is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A aPARTICULAR PURPOSE. See the
20  * GNU Affero General Public License for more details.
21  *
22  * You should have received a copy of the GNU Affero General Public
23  * License along with TTL. If not, see
24  * <http://www.gnu.org/licenses/>.
25  *
26  * In accordance with Section 7(b) of the GNU Affero General Public
27  * License, a covered work must retain the producer line in every data
28  * file that is created or manipulated using TTL.
29  *
30  * Other Usage
31  * You can be released from the requirements of the license by purchasing
32  * a commercial license. Buying such a license is mandatory as soon as you
33  * develop commercial activities involving the TTL library without
34  * disclosing the source code of your own applications.
35  *
36  * This file may be used in accordance with the terms contained in a
37  * written agreement between you and SINTEF ICT.
38  */
39 
40 #ifndef _TTL_UTIL_H_
41 #define _TTL_UTIL_H_
42 
43 #include <vector>
44 #include <algorithm>
45 
46 #ifdef _MSC_VER
47 # if _MSC_VER < 1300
48 # include <minmax.h>
49 # endif
50 #endif
51 
77 namespace ttl_util
78 {
88 template <class REAL_TYPE>
89 REAL_TYPE ScalarProduct2D( REAL_TYPE aDX1, REAL_TYPE aDY1, REAL_TYPE aDX2, REAL_TYPE aDY2 )
90 {
91  return aDX1 * aDX2 + aDY1 * aDY2;
92 }
93 
101 template <class REAL_TYPE>
102 REAL_TYPE CrossProduct2D( REAL_TYPE aDX1, REAL_TYPE aDY1, REAL_TYPE aDX2, REAL_TYPE aDY2 )
103 {
104  return aDX1 * aDY2 - aDY1 * aDX2;
105 }
106 
116 template <class REAL_TYPE>
117 REAL_TYPE Orient2DFast( REAL_TYPE aPA[2], REAL_TYPE aPB[2], REAL_TYPE aPC[2] )
118 {
119  REAL_TYPE acx = aPA[0] - aPC[0];
120  REAL_TYPE bcx = aPB[0] - aPC[0];
121  REAL_TYPE acy = aPA[1] - aPC[1];
122  REAL_TYPE bcy = aPB[1] - aPC[1];
123 
124  return acx * bcy - acy * bcx;
125 }
126 
127 } // namespace ttl_util
128 
129 #endif // _TTL_UTIL_H_
REAL_TYPE ScalarProduct2D(REAL_TYPE aDX1, REAL_TYPE aDY1, REAL_TYPE aDX2, REAL_TYPE aDY2)
Scalar product between two 2D vectors.
Definition: ttl_util.h:89
Utilities.
Definition: ttl_util.h:77
REAL_TYPE Orient2DFast(REAL_TYPE aPA[2], REAL_TYPE aPB[2], REAL_TYPE aPC[2])
Returns a positive value if the 2D nodes/points aPA, aPB, and aPC occur in counterclockwise order; a ...
Definition: ttl_util.h:117
REAL_TYPE CrossProduct2D(REAL_TYPE aDX1, REAL_TYPE aDY1, REAL_TYPE aDX2, REAL_TYPE aDY2)
Cross product between two 2D vectors.
Definition: ttl_util.h:102