Coverage Report

Created: 2026-05-16 09:25

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/basegfx/source/vector/b3dvector.cxx
Line
Count
Source
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
/*
3
 * This file is part of the LibreOffice project.
4
 *
5
 * This Source Code Form is subject to the terms of the Mozilla Public
6
 * License, v. 2.0. If a copy of the MPL was not distributed with this
7
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8
 *
9
 * This file incorporates work covered by the following license notice:
10
 *
11
 *   Licensed to the Apache Software Foundation (ASF) under one or more
12
 *   contributor license agreements. See the NOTICE file distributed
13
 *   with this work for additional information regarding copyright
14
 *   ownership. The ASF licenses this file to you under the Apache
15
 *   License, Version 2.0 (the "License"); you may not use this file
16
 *   except in compliance with the License. You may obtain a copy of
17
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
18
 */
19
20
#include <basegfx/vector/b3dvector.hxx>
21
#include <basegfx/matrix/b3dhommatrix.hxx>
22
#include <cassert>
23
24
namespace basegfx
25
{
26
    B3DVector& B3DVector::normalize()
27
182k
    {
28
182k
        double fLen(std::hypot(mnX, mnY, mnZ));
29
30
182k
        if(!::basegfx::fTools::equalZero(fLen))
31
182k
        {
32
182k
            assert(fLen != 0.0 && "help coverity see it's not zero");
33
34
182k
            const double fOne(1.0);
35
36
182k
            if(!::basegfx::fTools::equal(fOne, fLen))
37
47.0k
            {
38
47.0k
                mnX /= fLen;
39
47.0k
                mnY /= fLen;
40
47.0k
                mnZ /= fLen;
41
47.0k
            }
42
182k
        }
43
60
        else
44
60
        {
45
60
            mnX = 0.0;
46
60
            mnY = 0.0;
47
60
            mnZ = 0.0;
48
60
        }
49
50
182k
        return *this;
51
182k
    }
52
53
    B3DVector B3DVector::getPerpendicular(const B3DVector& rNormalizedVec) const
54
64.6k
    {
55
64.6k
        B3DVector aNew = cross(*this, rNormalizedVec);
56
64.6k
        aNew.normalize();
57
64.6k
        return aNew;
58
64.6k
    }
59
60
    B3DVector& B3DVector::operator*=( const ::basegfx::B3DHomMatrix& rMat )
61
20.5k
    {
62
20.5k
        const double fTempX( rMat.get(0,0)*mnX + rMat.get(0,1)*mnY + rMat.get(0,2)*mnZ );
63
20.5k
        const double fTempY( rMat.get(1,0)*mnX + rMat.get(1,1)*mnY + rMat.get(1,2)*mnZ );
64
20.5k
        const double fTempZ( rMat.get(2,0)*mnX + rMat.get(2,1)*mnY + rMat.get(2,2)*mnZ );
65
20.5k
        mnX = fTempX;
66
20.5k
        mnY = fTempY;
67
20.5k
        mnZ = fTempZ;
68
69
20.5k
        return *this;
70
20.5k
    }
71
72
    B3DVector operator*( const ::basegfx::B3DHomMatrix& rMat, const B3DVector& rVec )
73
20.4k
    {
74
20.4k
        B3DVector aRes( rVec );
75
20.4k
        aRes *= rMat;
76
20.4k
        return aRes;
77
20.4k
    }
78
79
    bool areParallel( const B3DVector& rVecA, const B3DVector& rVecB )
80
0
    {
81
        // i think fastest is to compare relations, need no square or division
82
0
        if(!fTools::equal(rVecA.getX() * rVecB.getY(), rVecA.getY() * rVecB.getX()))
83
0
            return false;
84
85
0
        if(!fTools::equal(rVecA.getX() * rVecB.getZ(), rVecA.getZ() * rVecB.getX()))
86
0
            return false;
87
88
0
        return fTools::equal(rVecA.getY() * rVecB.getZ(), rVecA.getZ() * rVecB.getY());
89
0
    }
90
91
} // end of namespace basegfx
92
93
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */