1
// Wild Magic Source Code
3
// http://www.geometrictools.com
4
// Copyright (c) 1998-2007
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.
15
// Version: 4.0.0 (2006/06/28)
17
//----------------------------------------------------------------------------
19
Query2Filtered<Real>::Query2Filtered (int iVQuantity,
20
const Vector2<Real>* akVertex, Real fUncertainty)
22
Query2<Real>(iVQuantity,akVertex),
23
m_kRQuery(iVQuantity,akVertex)
25
assert((Real)0.0 <= fUncertainty && fUncertainty <= (Real)1.0);
26
m_fUncertainty = fUncertainty;
28
//----------------------------------------------------------------------------
30
Query2Filtered<Real>::~Query2Filtered ()
33
//----------------------------------------------------------------------------
35
Query::Type Query2Filtered<Real>::GetType () const
37
return Query::QT_FILTERED;
39
//----------------------------------------------------------------------------
41
int Query2Filtered<Real>::ToLine (const Vector2<Real>& rkP, int iV0, int iV1)
44
const Vector2<Real>& rkV0 = m_akVertex[iV0];
45
const Vector2<Real>& rkV1 = m_akVertex[iV1];
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];
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;
56
Real fDet2 = Det2(fX0,fY0,fX1,fY1);
57
if (Math<Real>::FAbs(fDet2) >= fScaledUncertainty)
59
return (fDet2 > (Real)0.0 ? +1 : (fDet2 < (Real)0.0 ? -1 : 0));
62
return m_kRQuery.ToLine(rkP,iV0,iV1);
64
//----------------------------------------------------------------------------
66
int Query2Filtered<Real>::ToCircumcircle (const Vector2<Real>& rkP, int iV0,
67
int iV1, int iV2) const
69
const Vector2<Real>& rkV0 = m_akVertex[iV0];
70
const Vector2<Real>& rkV1 = m_akVertex[iV1];
71
const Vector2<Real>& rkV2 = m_akVertex[iV2];
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;
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;
94
Real fDet3 = Det3(fD0x,fD0y,fZ0,fD1x,fD1y,fZ1,fD2x,fD2y,fZ2);
95
if (Math<Real>::FAbs(fDet3) >= fScaledUncertainty)
97
return (fDet3 < (Real)0.0 ? 1 : (fDet3 > (Real)0.0 ? -1 : 0));
100
return m_kRQuery.ToCircumcircle(rkP,iV0,iV1,iV2);
102
//----------------------------------------------------------------------------