2
* Inkscape::Util::... some mathmatical functions
5
* Johan Engelen <goejendaagh@zonnet.nl>
7
* Copyright (C) 2007 Johan Engelen
9
* Released under GNU GPL, read the file 'COPYING' for more information
12
#ifndef SEEN_INKSCAPE_UTIL_MATHFNS_H
13
#define SEEN_INKSCAPE_UTIL_MATHFNS_H
15
#include <2geom/point.h>
22
* Returns area in triangle given by points; may be negative.
25
triangle_area (Geom::Point p1, Geom::Point p2, Geom::Point p3)
29
return (p1[X]*p2[Y] + p1[Y]*p3[X] + p2[X]*p3[Y] - p2[Y]*p3[X] - p1[Y]*p2[X] - p1[X]*p3[Y]);
33
* \return x rounded to the nearest multiple of c1 plus c0.
36
* If c1==0 (and c0 is finite), then returns +/-inf. This makes grid spacing of zero
37
* mean "ignore the grid in this dimension".
39
inline double round_to_nearest_multiple_plus(double x, double const c1, double const c0)
41
return floor((x - c0) / c1 + .5) * c1 + c0;
45
* \return x rounded to the lower multiple of c1 plus c0.
48
* If c1==0 (and c0 is finite), then returns +/-inf. This makes grid spacing of zero
49
* mean "ignore the grid in this dimension".
51
inline double round_to_lower_multiple_plus(double x, double const c1, double const c0)
53
return floor((x - c0) / c1) * c1 + c0;
57
* \return x rounded to the upper multiple of c1 plus c0.
60
* If c1==0 (and c0 is finite), then returns +/-inf. This makes grid spacing of zero
61
* mean "ignore the grid in this dimension".
63
inline double round_to_upper_multiple_plus(double x, double const c1, double const c0)
65
return ceil((x - c0) / c1) * c1 + c0;
77
c-file-style:"stroustrup"
78
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
83
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :