Wm4Query2TInteger.inl
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 namespace Wm4
00018 {
00019
00020 template <class Real>
00021 Query2TInteger<Real>::Query2TInteger (int iVQuantity,
00022 const Vector2<Real>* akVertex)
00023 :
00024 Query2<Real>(iVQuantity,akVertex)
00025 {
00026 }
00027
00028 template <class Real>
00029 Query::Type Query2TInteger<Real>::GetType () const
00030 {
00031 return Query::QT_INTEGER;
00032 }
00033
00034 template <class Real>
00035 int Query2TInteger<Real>::ToLine (const Vector2<Real>& rkP, int iV0, int iV1)
00036 const
00037 {
00038 const Vector2<Real>& rkV0 = m_akVertex[iV0];
00039 const Vector2<Real>& rkV1 = m_akVertex[iV1];
00040
00041 TInteger<2> kX0((int)rkP[0] - (int)rkV0[0]);
00042 TInteger<2> kY0((int)rkP[1] - (int)rkV0[1]);
00043 TInteger<2> kX1((int)rkV1[0] - (int)rkV0[0]);
00044 TInteger<2> kY1((int)rkV1[1] - (int)rkV0[1]);
00045
00046 TInteger<2> kDet2 = Det2(kX0,kY0,kX1,kY1);
00047 return (kDet2 > 0 ? +1 : (kDet2 < 0 ? -1 : 0));
00048 }
00049
00050 template <class Real>
00051 int Query2TInteger<Real>::ToCircumcircle (const Vector2<Real>& rkP, int iV0,
00052 int iV1, int iV2) const
00053 {
00054 const Vector2<Real>& rkV0 = m_akVertex[iV0];
00055 const Vector2<Real>& rkV1 = m_akVertex[iV1];
00056 const Vector2<Real>& rkV2 = m_akVertex[iV2];
00057
00058 int aiP[2] = { (int)rkP[0], (int)rkP[1] };
00059 int aiV0[2] = { (int)rkV0[0], (int)rkV0[1] };
00060 int aiV1[2] = { (int)rkV1[0], (int)rkV1[1] };
00061 int aiV2[2] = { (int)rkV2[0], (int)rkV2[1] };
00062
00063 TInteger<4> kS0x(aiV0[0] + aiP[0]);
00064 TInteger<4> kD0x(aiV0[0] - aiP[0]);
00065 TInteger<4> kS0y(aiV0[1] + aiP[1]);
00066 TInteger<4> kD0y(aiV0[1] - aiP[1]);
00067 TInteger<4> kS1x(aiV1[0] + aiP[0]);
00068 TInteger<4> kD1x(aiV1[0] - aiP[0]);
00069 TInteger<4> kS1y(aiV1[1] + aiP[1]);
00070 TInteger<4> kD1y(aiV1[1] - aiP[1]);
00071 TInteger<4> kS2x(aiV2[0] + aiP[0]);
00072 TInteger<4> kD2x(aiV2[0] - aiP[0]);
00073 TInteger<4> kS2y(aiV2[1] + aiP[1]);
00074 TInteger<4> kD2y(aiV2[1] - aiP[1]);
00075 TInteger<4> kZ0 = kS0x*kD0x + kS0y*kD0y;
00076 TInteger<4> kZ1 = kS1x*kD1x + kS1y*kD1y;
00077 TInteger<4> kZ2 = kS2x*kD2x + kS2y*kD2y;
00078 TInteger<4> kDet3 = Det3(kD0x,kD0y,kZ0,kD1x,kD1y,kZ1,kD2x,kD2y,kZ2);
00079 return (kDet3 < 0 ? 1 : (kDet3 > 0 ? -1 : 0));
00080 }
00081
00082 template <class Real>
00083 TInteger<2> Query2TInteger<Real>::Dot (TInteger<2>& rkX0, TInteger<2>& rkY0,
00084 TInteger<2>& rkX1, TInteger<2>& rkY1)
00085 {
00086 return rkX0*rkX1 + rkY0*rkY1;
00087 }
00088
00089 template <class Real>
00090 TInteger<2> Query2TInteger<Real>::Det2 (TInteger<2>& rkX0, TInteger<2>& rkY0,
00091 TInteger<2>& rkX1, TInteger<2>& rkY1)
00092 {
00093 return rkX0*rkY1 - rkX1*rkY0;
00094 }
00095
00096 template <class Real>
00097 TInteger<4> Query2TInteger<Real>::Det3 (TInteger<4>& rkX0, TInteger<4>& rkY0,
00098 TInteger<4>& rkZ0, TInteger<4>& rkX1, TInteger<4>& rkY1,
00099 TInteger<4>& rkZ1, TInteger<4>& rkX2, TInteger<4>& rkY2,
00100 TInteger<4>& rkZ2)
00101 {
00102 TInteger<4> kC00 = rkY1*rkZ2 - rkY2*rkZ1;
00103 TInteger<4> kC01 = rkY2*rkZ0 - rkY0*rkZ2;
00104 TInteger<4> kC02 = rkY0*rkZ1 - rkY1*rkZ0;
00105 return rkX0*kC00 + rkX1*kC01 + rkX2*kC02;
00106 }
00107
00108 }