~ubuntu-branches/ubuntu/maverick/freecad/maverick

« back to all changes in this revision

Viewing changes to src/Mod/Mesh/App/WildMagic4/Wm4Query2Filtered.inl

  • Committer: Bazaar Package Importer
  • Author(s): Teemu Ikonen
  • Date: 2009-07-16 18:37:41 UTC
  • Revision ID: james.westby@ubuntu.com-20090716183741-oww9kcxqrk991i1n
Tags: upstream-0.8.2237
ImportĀ upstreamĀ versionĀ 0.8.2237

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Wild Magic Source Code
 
2
// David Eberly
 
3
// http://www.geometrictools.com
 
4
// Copyright (c) 1998-2007
 
5
//
 
6
// This library is free software; you can redistribute it and/or modify it
 
7
// under the terms of the GNU Lesser General Public License as published by
 
8
// the Free Software Foundation; either version 2.1 of the License, or (at
 
9
// your option) any later version.  The license is available for reading at
 
10
// either of the locations:
 
11
//     http://www.gnu.org/copyleft/lgpl.html
 
12
//     http://www.geometrictools.com/License/WildMagicLicense.pdf
 
13
// The license applies to versions 0 through 4 of Wild Magic.
 
14
//
 
15
// Version: 4.0.0 (2006/06/28)
 
16
 
 
17
//----------------------------------------------------------------------------
 
18
template <class Real>
 
19
Query2Filtered<Real>::Query2Filtered (int iVQuantity,
 
20
    const Vector2<Real>* akVertex, Real fUncertainty)
 
21
    :
 
22
    Query2<Real>(iVQuantity,akVertex),
 
23
    m_kRQuery(iVQuantity,akVertex)
 
24
{
 
25
    assert((Real)0.0 <= fUncertainty && fUncertainty <= (Real)1.0);
 
26
    m_fUncertainty = fUncertainty;
 
27
}
 
28
//----------------------------------------------------------------------------
 
29
template <class Real>
 
30
Query2Filtered<Real>::~Query2Filtered ()
 
31
{
 
32
}
 
33
//----------------------------------------------------------------------------
 
34
template <class Real>
 
35
Query::Type Query2Filtered<Real>::GetType () const
 
36
{
 
37
    return Query::QT_FILTERED;
 
38
}
 
39
//----------------------------------------------------------------------------
 
40
template <class Real>
 
41
int Query2Filtered<Real>::ToLine (const Vector2<Real>& rkP, int iV0, int iV1)
 
42
    const
 
43
{
 
44
    const Vector2<Real>& rkV0 = m_akVertex[iV0];
 
45
    const Vector2<Real>& rkV1 = m_akVertex[iV1];
 
46
 
 
47
    Real fX0 = rkP[0] - rkV0[0];
 
48
    Real fY0 = rkP[1] - rkV0[1];
 
49
    Real fX1 = rkV1[0] - rkV0[0];
 
50
    Real fY1 = rkV1[1] - rkV0[1];
 
51
 
 
52
    Real fLen0 = Math<Real>::Sqrt(fX0*fX0 + fY0*fY0);
 
53
    Real fLen1 = Math<Real>::Sqrt(fX1*fX1 + fY1*fY1);
 
54
    Real fScaledUncertainty = m_fUncertainty*fLen0*fLen1;
 
55
 
 
56
    Real fDet2 = Det2(fX0,fY0,fX1,fY1);
 
57
    if (Math<Real>::FAbs(fDet2) >= fScaledUncertainty)
 
58
    {
 
59
        return (fDet2 > (Real)0.0 ? +1 : (fDet2 < (Real)0.0 ? -1 : 0));
 
60
    }
 
61
 
 
62
    return m_kRQuery.ToLine(rkP,iV0,iV1);
 
63
}
 
64
//----------------------------------------------------------------------------
 
65
template <class Real>
 
66
int Query2Filtered<Real>::ToCircumcircle (const Vector2<Real>& rkP, int iV0,
 
67
    int iV1, int iV2) const
 
68
{
 
69
    const Vector2<Real>& rkV0 = m_akVertex[iV0];
 
70
    const Vector2<Real>& rkV1 = m_akVertex[iV1];
 
71
    const Vector2<Real>& rkV2 = m_akVertex[iV2];
 
72
 
 
73
    Real fS0x = rkV0[0] + rkP[0];
 
74
    Real fD0x = rkV0[0] - rkP[0];
 
75
    Real fS0y = rkV0[1] + rkP[1];
 
76
    Real fD0y = rkV0[1] - rkP[1];
 
77
    Real fS1x = rkV1[0] + rkP[0];
 
78
    Real fD1x = rkV1[0] - rkP[0];
 
79
    Real fS1y = rkV1[1] + rkP[1];
 
80
    Real fD1y = rkV1[1] - rkP[1];
 
81
    Real fS2x = rkV2[0] + rkP[0];
 
82
    Real fD2x = rkV2[0] - rkP[0];
 
83
    Real fS2y = rkV2[1] + rkP[1];
 
84
    Real fD2y = rkV2[1] - rkP[1];
 
85
    Real fZ0 = fS0x*fD0x + fS0y*fD0y;
 
86
    Real fZ1 = fS1x*fD1x + fS1y*fD1y;
 
87
    Real fZ2 = fS2x*fD2x + fS2y*fD2y;
 
88
 
 
89
    Real fLen0 = Math<Real>::Sqrt(fD0x*fD0x + fD0y*fD0y + fZ0*fZ0);
 
90
    Real fLen1 = Math<Real>::Sqrt(fD1x*fD1x + fD1y*fD1y + fZ1*fZ1);
 
91
    Real fLen2 = Math<Real>::Sqrt(fD2x*fD2x + fD2y*fD2y + fZ2*fZ2);
 
92
    Real fScaledUncertainty = m_fUncertainty*fLen0*fLen1*fLen2;
 
93
 
 
94
    Real fDet3 = Det3(fD0x,fD0y,fZ0,fD1x,fD1y,fZ1,fD2x,fD2y,fZ2);
 
95
    if (Math<Real>::FAbs(fDet3) >= fScaledUncertainty)
 
96
    {
 
97
        return (fDet3 < (Real)0.0 ? 1 : (fDet3 > (Real)0.0 ? -1 : 0));
 
98
    }
 
99
 
 
100
    return m_kRQuery.ToCircumcircle(rkP,iV0,iV1,iV2);
 
101
}
 
102
//----------------------------------------------------------------------------