~valavanisalex/ubuntu/precise/inkscape/fix-943984

« back to all changes in this revision

Viewing changes to inkscape-0.47pre1/src/util/mathfns.h

  • Committer: Bazaar Package Importer
  • Author(s): Bryce Harrington
  • Date: 2009-07-02 17:09:45 UTC
  • mfrom: (1.1.9 upstream)
  • Revision ID: james.westby@ubuntu.com-20090702170945-nn6d6zswovbwju1t
Tags: 0.47~pre1-0ubuntu1
* New upstream release.
  - Don't constrain maximization on small resolution devices (pre0)
    (LP: #348842)
  - Fixes segfault on startup (pre0)
    (LP: #391149)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Inkscape::Util::... some mathmatical functions 
 
3
 *
 
4
 * Authors:
 
5
 *   Johan Engelen <goejendaagh@zonnet.nl>
 
6
 *
 
7
 * Copyright (C) 2007 Johan Engelen
 
8
 *
 
9
 * Released under GNU GPL, read the file 'COPYING' for more information
 
10
 */
 
11
 
 
12
#ifndef SEEN_INKSCAPE_UTIL_MATHFNS_H
 
13
#define SEEN_INKSCAPE_UTIL_MATHFNS_H
 
14
 
 
15
#include <2geom/point.h>
 
16
 
 
17
namespace Inkscape {
 
18
 
 
19
namespace Util {
 
20
 
 
21
/**
 
22
 * Returns area in triangle given by points; may be negative.
 
23
 */
 
24
inline double
 
25
triangle_area (Geom::Point p1, Geom::Point p2, Geom::Point p3)
 
26
{
 
27
    using Geom::X;
 
28
    using Geom::Y;
 
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]);
 
30
}
 
31
 
 
32
/**
 
33
 * \return x rounded to the nearest multiple of c1 plus c0.
 
34
 *
 
35
 * \note
 
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".
 
38
 */
 
39
inline double round_to_nearest_multiple_plus(double x, double const c1, double const c0)
 
40
{
 
41
    return floor((x - c0) / c1 + .5) * c1 + c0;
 
42
}
 
43
 
 
44
/**
 
45
 * \return x rounded to the lower multiple of c1 plus c0.
 
46
 *
 
47
 * \note
 
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".
 
50
 */
 
51
inline double round_to_lower_multiple_plus(double x, double const c1, double const c0)
 
52
{
 
53
    return floor((x - c0) / c1) * c1 + c0;
 
54
}
 
55
 
 
56
/**
 
57
 * \return x rounded to the upper multiple of c1 plus c0.
 
58
 *
 
59
 * \note
 
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".
 
62
 */
 
63
inline double round_to_upper_multiple_plus(double x, double const c1, double const c0)
 
64
{
 
65
    return ceil((x - c0) / c1) * c1 + c0;
 
66
}
 
67
 
 
68
 
 
69
}
 
70
 
 
71
}
 
72
 
 
73
#endif
 
74
/*
 
75
  Local Variables:
 
76
  mode:c++
 
77
  c-file-style:"stroustrup"
 
78
  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
 
79
  indent-tabs-mode:nil
 
80
  fill-column:99
 
81
  End:
 
82
*/
 
83
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :