| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | * SymmetricMatrix basic operation | ||
| 3 | * | ||
| 4 | * Authors: | ||
| 5 | * Marco Cecchetti <mrcekets at gmail.com> | ||
| 6 | * | ||
| 7 | * Copyright 2009 authors | ||
| 8 | * | ||
| 9 | * This library is free software; you can redistribute it and/or | ||
| 10 | * modify it either under the terms of the GNU Lesser General Public | ||
| 11 | * License version 2.1 as published by the Free Software Foundation | ||
| 12 | * (the "LGPL") or, at your option, under the terms of the Mozilla | ||
| 13 | * Public License Version 1.1 (the "MPL"). If you do not alter this | ||
| 14 | * notice, a recipient may use your version of this file under either | ||
| 15 | * the MPL or the LGPL. | ||
| 16 | * | ||
| 17 | * You should have received a copy of the LGPL along with this library | ||
| 18 | * in the file COPYING-LGPL-2.1; if not, write to the Free Software | ||
| 19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
| 20 | * You should have received a copy of the MPL along with this library | ||
| 21 | * in the file COPYING-MPL-1.1 | ||
| 22 | * | ||
| 23 | * The contents of this file are subject to the Mozilla Public License | ||
| 24 | * Version 1.1 (the "License"); you may not use this file except in | ||
| 25 | * compliance with the License. You may obtain a copy of the License at | ||
| 26 | * http://www.mozilla.org/MPL/ | ||
| 27 | * | ||
| 28 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY | ||
| 29 | * OF ANY KIND, either express or implied. See the LGPL or the MPL for | ||
| 30 | * the specific language governing rights and limitations. | ||
| 31 | */ | ||
| 32 | |||
| 33 | #ifndef _NL_SYMMETRIC_MATRIX_FS_OPERATION_H_ | ||
| 34 | #define _NL_SYMMETRIC_MATRIX_FS_OPERATION_H_ | ||
| 35 | |||
| 36 | |||
| 37 | #include <2geom/numeric/symmetric-matrix-fs.h> | ||
| 38 | #include <2geom/numeric/symmetric-matrix-fs-trace.h> | ||
| 39 | |||
| 40 | |||
| 41 | |||
| 42 | |||
| 43 | namespace Geom { namespace NL { | ||
| 44 | |||
| 45 | template <size_t N> | ||
| 46 | SymmetricMatrix<N> adj(const ConstBaseSymmetricMatrix<N> & S); | ||
| 47 | |||
| 48 | template <> | ||
| 49 | inline | ||
| 50 | SymmetricMatrix<2> adj(const ConstBaseSymmetricMatrix<2> & S) | ||
| 51 | { | ||
| 52 | SymmetricMatrix<2> result; | ||
| 53 | result.get<0,0>() = S.get<1,1>(); | ||
| 54 | result.get<1,0>() = -S.get<1,0>(); | ||
| 55 | result.get<1,1>() = S.get<0,0>(); | ||
| 56 | return result; | ||
| 57 | } | ||
| 58 | |||
| 59 | template <> | ||
| 60 | inline | ||
| 61 | ✗ | SymmetricMatrix<3> adj(const ConstBaseSymmetricMatrix<3> & S) | |
| 62 | { | ||
| 63 | ✗ | SymmetricMatrix<3> result; | |
| 64 | |||
| 65 | ✗ | result.get<0,0>() = S.get<1,1>() * S.get<2,2>() - S.get<1,2>() * S.get<2,1>(); | |
| 66 | ✗ | result.get<1,0>() = S.get<0,2>() * S.get<2,1>() - S.get<0,1>() * S.get<2,2>(); | |
| 67 | ✗ | result.get<1,1>() = S.get<0,0>() * S.get<2,2>() - S.get<0,2>() * S.get<2,0>(); | |
| 68 | ✗ | result.get<2,0>() = S.get<0,1>() * S.get<1,2>() - S.get<0,2>() * S.get<1,1>(); | |
| 69 | ✗ | result.get<2,1>() = S.get<0,2>() * S.get<1,0>() - S.get<0,0>() * S.get<1,2>(); | |
| 70 | ✗ | result.get<2,2>() = S.get<0,0>() * S.get<1,1>() - S.get<0,1>() * S.get<1,0>(); | |
| 71 | ✗ | return result; | |
| 72 | ✗ | } | |
| 73 | |||
| 74 | template <size_t N> | ||
| 75 | inline | ||
| 76 | SymmetricMatrix<N> inverse(const ConstBaseSymmetricMatrix<N> & S) | ||
| 77 | { | ||
| 78 | SymmetricMatrix<N> result = adj(S); | ||
| 79 | double d = det(S); | ||
| 80 | assert (d != 0); | ||
| 81 | result.scale (1/d); | ||
| 82 | return result; | ||
| 83 | } | ||
| 84 | |||
| 85 | } /* end namespace NL*/ } /* end namespace Geom*/ | ||
| 86 | |||
| 87 | |||
| 88 | #endif // _NL_SYMMETRIC_MATRIX_FS_OPERATION_H_ | ||
| 89 | |||
| 90 | |||
| 91 | |||
| 92 | |||
| 93 | /* | ||
| 94 | Local Variables: | ||
| 95 | mode:c++ | ||
| 96 | c-file-style:"stroustrup" | ||
| 97 | c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) | ||
| 98 | indent-tabs-mode:nil | ||
| 99 | fill-column:99 | ||
| 100 | End: | ||
| 101 | */ | ||
| 102 | // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : | ||
| 103 |