1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <basegfx/numeric/ftools.hxx>
25 // init static member of class fTools
26 double ::basegfx::fTools::mfSmallValue
= 0.000000001;
28 double snapToNearestMultiple(double v
, const double fStep
)
30 if(fTools::equalZero(fStep
))
32 // with a zero step, all snaps to 0.0
37 const double fHalfStep(fStep
* 0.5);
38 const double fChange(fHalfStep
- fmod(v
+ fHalfStep
, fStep
));
40 if(basegfx::fTools::equal(fabs(v
), fabs(fChange
)))
51 double snapToZeroRange(double v
, double fWidth
)
53 if(fTools::equalZero(fWidth
))
55 // with no range all snaps to range bound
60 if(v
< 0.0 || v
> fWidth
)
62 double fRetval(fmod(v
, fWidth
));
78 double snapToRange(double v
, double fLow
, double fHigh
)
80 if(fTools::equal(fLow
, fHigh
))
82 // with no range all snaps to range bound
89 // correct range order. Evtl. assert this (?)
90 std::swap(fLow
, fHigh
);
93 if(v
< fLow
|| v
> fHigh
)
95 return snapToZeroRange(v
- fLow
, fHigh
- fLow
) + fLow
;
103 } // end of namespace basegfx
105 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */