summaryrefslogtreecommitdiff
path: root/basegfx
diff options
context:
space:
mode:
Diffstat (limited to 'basegfx')
-rw-r--r--basegfx/Library_basegfx.mk1
-rw-r--r--basegfx/source/numeric/ftools.cxx49
2 files changed, 50 insertions, 0 deletions
diff --git a/basegfx/Library_basegfx.mk b/basegfx/Library_basegfx.mk
index de2430ca8644..36666472ba56 100644
--- a/basegfx/Library_basegfx.mk
+++ b/basegfx/Library_basegfx.mk
@@ -37,6 +37,7 @@ $(eval $(call gb_Library_add_exception_objects,basegfx,\
basegfx/source/matrix/b2dhommatrix \
basegfx/source/matrix/b2dhommatrixtools \
basegfx/source/matrix/b3dhommatrix \
+ basegfx/source/numeric/ftools \
basegfx/source/pixel/bpixel \
basegfx/source/point/b2dpoint \
basegfx/source/point/b2ipoint \
diff --git a/basegfx/source/numeric/ftools.cxx b/basegfx/source/numeric/ftools.cxx
new file mode 100644
index 000000000000..a67bc56bd74e
--- /dev/null
+++ b/basegfx/source/numeric/ftools.cxx
@@ -0,0 +1,49 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#include <basegfx/numeric/ftools.hxx>
+#include <algorithm>
+
+namespace basegfx
+{
+ double snapToNearestMultiple(double v, const double fStep)
+ {
+ if(fTools::equalZero(fStep))
+ {
+ // with a zero step, all snaps to 0.0
+ return 0.0;
+ }
+ else
+ {
+ const double fHalfStep(fStep * 0.5);
+ const double fChange(fHalfStep - fmod(v + fHalfStep, fStep));
+
+ if(basegfx::fTools::equal(fabs(v), fabs(fChange)))
+ {
+ return 0.0;
+ }
+ else
+ {
+ return v + fChange;
+ }
+ }
+ }
+} // end of namespace basegfx
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */