| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | * Copyright (c) 2000-2022 Inria | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * Redistribution and use in source and binary forms, with or without | ||
| 6 | * modification, are permitted provided that the following conditions are met: | ||
| 7 | * | ||
| 8 | * * Redistributions of source code must retain the above copyright notice, | ||
| 9 | * this list of conditions and the following disclaimer. | ||
| 10 | * * Redistributions in binary form must reproduce the above copyright notice, | ||
| 11 | * this list of conditions and the following disclaimer in the documentation | ||
| 12 | * and/or other materials provided with the distribution. | ||
| 13 | * * Neither the name of the ALICE Project-Team nor the names of its | ||
| 14 | * contributors may be used to endorse or promote products derived from this | ||
| 15 | * software without specific prior written permission. | ||
| 16 | * | ||
| 17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
| 18 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | ||
| 21 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
| 22 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
| 23 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
| 24 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
| 25 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 26 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
| 27 | * POSSIBILITY OF SUCH DAMAGE. | ||
| 28 | * | ||
| 29 | * Contact: Bruno Levy | ||
| 30 | * | ||
| 31 | * https://www.inria.fr/fr/bruno-levy | ||
| 32 | * | ||
| 33 | * Inria, | ||
| 34 | * Domaine de Voluceau, | ||
| 35 | * 78150 Le Chesnay - Rocquencourt | ||
| 36 | * FRANCE | ||
| 37 | * | ||
| 38 | */ | ||
| 39 | |||
| 40 | #ifndef GEOGRAM_BASIC_DETERMINANT | ||
| 41 | #define GEOGRAM_BASIC_DETERMINANT | ||
| 42 | |||
| 43 | #include <geogram/basic/common.h> | ||
| 44 | |||
| 45 | /** | ||
| 46 | * \file geogram/basic/determinant.h | ||
| 47 | * \brief Determinants for small sizes | ||
| 48 | */ | ||
| 49 | |||
| 50 | namespace GEO { | ||
| 51 | |||
| 52 | /************************************************************************/ | ||
| 53 | |||
| 54 | /** | ||
| 55 | * \brief Computes a two-by-two determinant. | ||
| 56 | */ | ||
| 57 | template <class T> | ||
| 58 | 19958901 | inline T det2x2( | |
| 59 | const T& a11, const T& a12, | ||
| 60 | const T& a21, const T& a22 | ||
| 61 | ) { | ||
| 62 |
2/11✓ Branch 0 taken 493556 times.
✓ Branch 1 taken 809 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
|
23022521 | return a11*a22-a12*a21 ; |
| 63 | } | ||
| 64 | |||
| 65 | /** | ||
| 66 | * \brief Computes a three-by-three determinant. | ||
| 67 | */ | ||
| 68 | template <class T> | ||
| 69 | 4832096 | inline T det3x3( | |
| 70 | const T& a11, const T& a12, const T& a13, | ||
| 71 | const T& a21, const T& a22, const T& a23, | ||
| 72 | const T& a31, const T& a32, const T& a33 | ||
| 73 | ) { | ||
| 74 | return | ||
| 75 | 9727714 | a11*det2x2(a22,a23,a32,a33) | |
| 76 | 4895618 | -a21*det2x2(a12,a13,a32,a33) | |
| 77 |
0/2✗ Branch 0 not taken.
✗ Branch 1 not taken.
|
4895618 | +a31*det2x2(a12,a13,a22,a23); |
| 78 | } | ||
| 79 | |||
| 80 | |||
| 81 | /** | ||
| 82 | * \brief Computes a four-by-four determinant. | ||
| 83 | */ | ||
| 84 | template <class T> | ||
| 85 | 490109 | inline T det4x4( | |
| 86 | const T& a11, const T& a12, const T& a13, const T& a14, | ||
| 87 | const T& a21, const T& a22, const T& a23, const T& a24, | ||
| 88 | const T& a31, const T& a32, const T& a33, const T& a34, | ||
| 89 | const T& a41, const T& a42, const T& a43, const T& a44 | ||
| 90 | ) { | ||
| 91 | 490109 | T m12 = a21*a12 - a11*a22; | |
| 92 | 490109 | T m13 = a31*a12 - a11*a32; | |
| 93 | 490109 | T m14 = a41*a12 - a11*a42; | |
| 94 | 490109 | T m23 = a31*a22 - a21*a32; | |
| 95 | 490109 | T m24 = a41*a22 - a21*a42; | |
| 96 | 490109 | T m34 = a41*a32 - a31*a42; | |
| 97 | |||
| 98 | 490109 | T m123 = m23*a13 - m13*a23 + m12*a33; | |
| 99 | 490109 | T m124 = m24*a13 - m14*a23 + m12*a43; | |
| 100 | 490109 | T m134 = m34*a13 - m14*a33 + m13*a43; | |
| 101 | 490109 | T m234 = m34*a23 - m24*a33 + m23*a43; | |
| 102 | |||
| 103 | 490109 | return (m234*a14 - m134*a24 + m124*a34 - m123*a44); | |
| 104 | } | ||
| 105 | } | ||
| 106 | |||
| 107 | #endif | ||
| 108 |