// File gp_Dir.lxx , JCV 01/10/90 #include #include #include #include inline gp_Dir::gp_Dir () : coord(1.,0.,0.) { } inline gp_Dir::gp_Dir (const gp_Vec& V) { const gp_XYZ& XYZ = V.XYZ(); Standard_Real X = XYZ.X(); Standard_Real Y = XYZ.Y(); Standard_Real Z = XYZ.Z(); Standard_Real D = sqrt(X * X + Y * Y + Z * Z); Standard_ConstructionError_Raise_if (D <= gp::Resolution(), ""); coord.SetX(X / D); coord.SetY(Y / D); coord.SetZ(Z / D); } inline gp_Dir::gp_Dir (const gp_XYZ& XYZ) { Standard_Real X = XYZ.X(); Standard_Real Y = XYZ.Y(); Standard_Real Z = XYZ.Z(); Standard_Real D = sqrt(X * X + Y * Y + Z * Z); Standard_ConstructionError_Raise_if (D <= gp::Resolution(), ""); coord.SetX(X / D); coord.SetY(Y / D); coord.SetZ(Z / D); } inline gp_Dir::gp_Dir (const Standard_Real Xv, const Standard_Real Yv, const Standard_Real Zv) { Standard_Real D = sqrt (Xv * Xv + Yv * Yv + Zv * Zv); Standard_ConstructionError_Raise_if (D <= gp::Resolution(), ""); coord.SetX(Xv / D); coord.SetY(Yv / D); coord.SetZ(Zv / D); } inline void gp_Dir::SetCoord (const Standard_Integer Index, const Standard_Real Xi) { Standard_Real X = coord.X(); Standard_Real Y = coord.Y(); Standard_Real Z = coord.Z(); Standard_OutOfRange_Raise_if (Index < 1 || Index > 3, " "); if (Index == 1) X = Xi; else if (Index == 2) Y = Xi; else Z = Xi; Standard_Real D = sqrt (X * X + Y * Y + Z * Z); Standard_ConstructionError_Raise_if (D <= gp::Resolution(), ""); coord.SetX(X / D); coord.SetY(Y / D); coord.SetZ(Z / D); } inline void gp_Dir::SetCoord (const Standard_Real Xv, const Standard_Real Yv, const Standard_Real Zv) { Standard_Real D = sqrt(Xv * Xv + Yv * Yv + Zv * Zv); Standard_ConstructionError_Raise_if(D <= gp::Resolution(), ""); coord.SetX(Xv / D); coord.SetY(Yv / D); coord.SetZ(Zv / D); } inline void gp_Dir::SetX (const Standard_Real X) { Standard_Real Y = coord.Y(); Standard_Real Z = coord.Z(); Standard_Real D = sqrt (X * X + Y * Y + Z * Z); Standard_ConstructionError_Raise_if (D <= gp::Resolution(), ""); coord.SetX(X / D); coord.SetY(Y / D); coord.SetZ(Z / D); } inline void gp_Dir::SetY (const Standard_Real Y) { Standard_Real Z = coord.Z(); Standard_Real X = coord.X(); Standard_Real D = sqrt (X * X + Y * Y + Z * Z); Standard_ConstructionError_Raise_if (D <= gp::Resolution(), ""); coord.SetX(X / D); coord.SetY(Y / D); coord.SetZ(Z / D); } inline void gp_Dir::SetZ (const Standard_Real Z) { Standard_Real X = coord.X(); Standard_Real Y = coord.Y(); Standard_Real D = sqrt (X * X + Y * Y + Z * Z); Standard_ConstructionError_Raise_if (D <= gp::Resolution(), ""); coord.SetX(X / D); coord.SetY(Y / D); coord.SetZ(Z / D); } inline void gp_Dir::SetXYZ (const gp_XYZ& XYZ) { Standard_Real X = XYZ.X(); Standard_Real Y = XYZ.Y(); Standard_Real Z = XYZ.Z(); Standard_Real D = sqrt(X * X + Y * Y + Z * Z); Standard_ConstructionError_Raise_if (D <= gp::Resolution(), ""); coord.SetX(X / D); coord.SetY(Y / D); coord.SetZ(Z / D); } inline Standard_Real gp_Dir::Coord (const Standard_Integer Index) const { return coord.Coord (Index);} inline void gp_Dir::Coord (Standard_Real& Xv, Standard_Real& Yv, Standard_Real& Zv) const { coord.Coord (Xv, Yv, Zv); } inline Standard_Real gp_Dir::X() const { return coord.X() ; } inline Standard_Real gp_Dir::Y() const { return coord.Y() ; } inline Standard_Real gp_Dir::Z() const { return coord.Z() ; } inline const gp_XYZ& gp_Dir::XYZ () const { return coord; } inline Standard_Boolean gp_Dir::IsEqual (const gp_Dir& Other, const Standard_Real AngularTolerance) const { return Angle (Other) <= AngularTolerance; } inline Standard_Boolean gp_Dir::IsNormal (const gp_Dir& Other, const Standard_Real AngularTolerance) const { Standard_Real Ang = Standard_PI / 2.0 - Angle (Other); if (Ang < 0) Ang = - Ang; return Ang <= AngularTolerance; } inline Standard_Boolean gp_Dir::IsOpposite (const gp_Dir& Other, const Standard_Real AngularTolerance) const { return Standard_PI - Angle (Other) <= AngularTolerance; } inline Standard_Boolean gp_Dir::IsParallel (const gp_Dir& Other, const Standard_Real AngularTolerance) const { Standard_Real Ang = Angle (Other); return Ang <= AngularTolerance || Standard_PI - Ang <= AngularTolerance; } inline void gp_Dir::Cross (const gp_Dir& Right) { coord.Cross (Right.coord); Standard_Real D = coord.Modulus (); Standard_ConstructionError_Raise_if (D <= gp::Resolution(), ""); coord.Divide (D); } inline gp_Dir gp_Dir::Crossed (const gp_Dir& Right) const { gp_Dir V = *this; V.coord.Cross (Right.coord); Standard_Real D = V.coord.Modulus(); Standard_ConstructionError_Raise_if (D <= gp::Resolution(), ""); V.coord.Divide (D); return V; } inline void gp_Dir::CrossCross (const gp_Dir& V1, const gp_Dir& V2) { coord.CrossCross (V1.coord, V2.coord); Standard_Real D = coord.Modulus(); Standard_ConstructionError_Raise_if (D <= gp::Resolution(), ""); coord.Divide(D); } inline gp_Dir gp_Dir::CrossCrossed (const gp_Dir& V1, const gp_Dir& V2) const { gp_Dir V = *this; (V.coord).CrossCross (V1.coord, V2.coord); Standard_Real D = V.coord.Modulus(); Standard_ConstructionError_Raise_if (D <= gp::Resolution(), ""); V.coord.Divide(D); return V; } inline Standard_Real gp_Dir::Dot (const gp_Dir& Other) const { return coord.Dot (Other.coord); } inline Standard_Real gp_Dir::DotCross (const gp_Dir& V1, const gp_Dir& V2) const { return coord.Dot (V1.coord.Crossed (V2.coord)); } inline void gp_Dir::Reverse () { coord.Reverse(); } inline gp_Dir gp_Dir::Reversed () const { gp_Dir V = *this; V.coord.Reverse (); return V; } inline void gp_Dir::Rotate (const gp_Ax1& A1, const Standard_Real Ang) { gp_Trsf T; T.SetRotation (A1, Ang); coord.Multiply (T.HVectorialPart ()); } inline gp_Dir gp_Dir::Rotated (const gp_Ax1& A1, const Standard_Real Ang) const { gp_Dir V = *this; V.Rotate (A1, Ang); return V; } inline gp_Dir gp_Dir::Transformed (const gp_Trsf& T) const { gp_Dir V = *this; V.Transform (T); return V; }