~ubuntu-branches/ubuntu/oneiric/kig/oneiric

« back to all changes in this revision

Viewing changes to misc/cubic-common.h

  • Committer: Bazaar Package Importer
  • Author(s): Harald Sitter
  • Date: 2011-07-10 11:57:38 UTC
  • Revision ID: james.westby@ubuntu.com-20110710115738-gdjnn1kctr49lmy9
Tags: upstream-4.6.90+repack
ImportĀ upstreamĀ versionĀ 4.6.90+repack

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright (C)  2003  Dominique Devriese <devriese@kde.org>
 
2
 
 
3
// This program is free software; you can redistribute it and/or
 
4
// modify it under the terms of the GNU General Public License
 
5
// as published by the Free Software Foundation; either version 2
 
6
// of the License, or (at your option) any later version.
 
7
 
 
8
// This program is distributed in the hope that it will be useful,
 
9
// but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
// GNU General Public License for more details.
 
12
 
 
13
// You should have received a copy of the GNU General Public License
 
14
// along with this program; if not, write to the Free Software
 
15
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 
16
// 02110-1301, USA.
 
17
 
 
18
#ifndef KIG_MISC_CUBIC_COMMON_H
 
19
#define KIG_MISC_CUBIC_COMMON_H
 
20
 
 
21
#include "common.h"
 
22
 
 
23
class Transformation;
 
24
 
 
25
/**
 
26
 * This class represents an equation of a cubic in the form
 
27
 * \f$ a_{ijk} x_i x_j x_k = 0 \f$ (in homogeneous coordinates,
 
28
 * \f$ i,j,k = 0,1,2 \f$), \f$ i <= j <= k \f$.
 
29
 * The coefficients are stored in lessicografic order.
 
30
 */
 
31
class CubicCartesianData
 
32
{
 
33
public:
 
34
  double coeffs[10];
 
35
  /**
 
36
   * \ifnot creating-python-scripting-doc
 
37
   * \brief Default Constructor
 
38
   *
 
39
   * Constructs a new CubicCartesianData, with all the coeffs
 
40
   * initialized to 0.
 
41
   * \endif
 
42
   */
 
43
  explicit CubicCartesianData();
 
44
  /**
 
45
   * Constructor. Construct a new CubicCartesianData, with the given
 
46
   * values as coeffs.
 
47
   */
 
48
  CubicCartesianData( double a000, double a001, double a002,
 
49
                      double a011, double a012, double a022,
 
50
                      double a111, double a112, double a122,
 
51
                      double a222 )
 
52
    {
 
53
      coeffs[0] = a000;
 
54
      coeffs[1] = a001;
 
55
      coeffs[2] = a002;
 
56
      coeffs[3] = a011;
 
57
      coeffs[4] = a012;
 
58
      coeffs[5] = a022;
 
59
      coeffs[6] = a111;
 
60
      coeffs[7] = a112;
 
61
      coeffs[8] = a122;
 
62
      coeffs[9] = a222;
 
63
    }
 
64
  CubicCartesianData( const double incoeffs[10] );
 
65
 
 
66
  /**
 
67
   * Create an invalid CubicCartesianData. This is a special state of a
 
68
   * CubicCartesianData that signals that something went wrong..
 
69
   *
 
70
   * \see CubicCartesianData::valid
 
71
   *
 
72
   * \internal We represent an invalid CubicCartesianData by setting all
 
73
   * the coeffs to positive or negative infinity. This is handy, since
 
74
   * it doesn't require us to adapt most of the functions, it doesn't
 
75
   * need extra space, and most of the times that we should get an
 
76
   * invalid CubicCartesianData, we get one automatically..
 
77
   */
 
78
  static CubicCartesianData invalidData();
 
79
  /**
 
80
   * Return whether this is a valid CubicCartesianData.
 
81
   *
 
82
   * \see CubicCartesianData::invalidData
 
83
   */
 
84
  bool valid() const;
 
85
  /*
 
86
   * normalize mdata with infinity norm of the coefficients = 1
 
87
   */
 
88
  void normalize();
 
89
};
 
90
 
 
91
bool operator==( const CubicCartesianData& lhs, const CubicCartesianData& rhs );
 
92
 
 
93
/**
 
94
 * This function calcs a cartesian cubic equation such that the
 
95
 * given points are on the cubic.  There can be at most 9 and at
 
96
 * least 2 point.  If there are less than 9, than the coefficients
 
97
 * will be chosen to 1.0 if possible
 
98
 */
 
99
const CubicCartesianData calcCubicThroughPoints (
 
100
    const std::vector<Coordinate>& points );
 
101
 
 
102
const CubicCartesianData calcCubicCuspThroughPoints (
 
103
    const std::vector<Coordinate>& points );
 
104
 
 
105
const CubicCartesianData calcCubicNodeThroughPoints (
 
106
    const std::vector<Coordinate>& points );
 
107
 
 
108
double calcCubicYvalue ( double x, double ymin, double ymax,
 
109
                         int root, CubicCartesianData data,
 
110
                         bool& valid, int& numroots );
 
111
 
 
112
const Coordinate calcCubicLineIntersect( const CubicCartesianData& c,
 
113
                                         const LineData& l,
 
114
                                         int root, bool& valid );
 
115
 
 
116
void calcCubicLineRestriction ( CubicCartesianData data,
 
117
         Coordinate p1, Coordinate dir,
 
118
         double& a, double& b, double& c, double& d );
 
119
 
 
120
const CubicCartesianData calcCubicTransformation (
 
121
  const CubicCartesianData& data,
 
122
  const Transformation& t, bool& valid );
 
123
 
 
124
#endif