Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-12 09:17:22

0001 // Copyright (c) 1991-1999 Matra Datavision
0002 // Copyright (c) 1999-2014 OPEN CASCADE SAS
0003 //
0004 // This file is part of Open CASCADE Technology software library.
0005 //
0006 // This library is free software; you can redistribute it and/or modify it under
0007 // the terms of the GNU Lesser General Public License version 2.1 as published
0008 // by the Free Software Foundation, with special exception defined in the file
0009 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0010 // distribution for complete text of the license and disclaimer of any warranty.
0011 //
0012 // Alternatively, this file may be used under the terms of Open CASCADE
0013 // commercial license or contractual agreement.
0014 
0015 #ifndef _gp_Ax22d_HeaderFile
0016 #define _gp_Ax22d_HeaderFile
0017 
0018 #include <gp_Ax2d.hxx>
0019 #include <gp_Dir2d.hxx>
0020 #include <gp_Pnt2d.hxx>
0021 #include <gp_Trsf2d.hxx>
0022 #include <gp_Vec2d.hxx>
0023 
0024 //! Describes a coordinate system in a plane (2D space).
0025 //! A coordinate system is defined by:
0026 //! -   its origin (also referred to as its "Location point"), and
0027 //! -   two orthogonal unit vectors, respectively, called the "X
0028 //! Direction" and the "Y Direction".
0029 //! A gp_Ax22d may be right-handed ("direct sense") or
0030 //! left-handed ("inverse" or "indirect sense").
0031 //! You use a gp_Ax22d to:
0032 //! - describe 2D geometric entities, in particular to position
0033 //! them. The local coordinate system of a geometric
0034 //! entity serves for the same purpose as the STEP
0035 //! function "axis placement two axes", or
0036 //! -   define geometric transformations.
0037 //! Note: we refer to the "X Axis" and "Y Axis" as the axes having:
0038 //! -   the origin of the coordinate system as their origin, and
0039 //! -   the unit vectors "X Direction" and "Y Direction",
0040 //! respectively, as their unit vectors.
0041 class gp_Ax22d
0042 {
0043 public:
0044   DEFINE_STANDARD_ALLOC
0045 
0046   //! Creates an object representing the reference
0047   //! coordinate system (OXY).
0048   constexpr gp_Ax22d() noexcept
0049       : vydir(gp_Dir2d::D::Y)
0050   // vxdir default ctor creates X direction (1, 0)
0051   {
0052   }
0053 
0054   //! Creates a coordinate system with origin theP and where:
0055   //! -   theVx is the "X Direction", and
0056   //! -   the "Y Direction" is orthogonal to theVx and
0057   //! oriented so that the cross products theVx^"Y
0058   //! Direction" and theVx^theVy have the same sign.
0059   //! Raises ConstructionError if theVx and theVy are parallel (same or opposite orientation).
0060   constexpr gp_Ax22d(const gp_Pnt2d& theP, const gp_Dir2d& theVx, const gp_Dir2d& theVy)
0061       : point(theP),
0062         vydir(theVy),
0063         vxdir(theVx)
0064   {
0065     const double aValue = theVx.Crossed(theVy);
0066     if (aValue >= 0.0)
0067     {
0068       vydir.SetCoord(-vxdir.Y(), vxdir.X());
0069     }
0070     else
0071     {
0072       vydir.SetCoord(vxdir.Y(), -vxdir.X());
0073     }
0074   }
0075 
0076   //! Creates a coordinate system with origin theP and "X Direction"
0077   //! theV, which is:
0078   //! -   right-handed if theIsSense is true (default value), or
0079   //! -   left-handed if theIsSense is false
0080   constexpr gp_Ax22d(const gp_Pnt2d& theP, const gp_Dir2d& theV, const bool theIsSense = true)
0081       : point(theP),
0082         vxdir(theV)
0083   {
0084     if (theIsSense)
0085     {
0086       vydir.SetCoord(-theV.Y(), theV.X());
0087     }
0088     else
0089     {
0090       vydir.SetCoord(theV.Y(), -theV.X());
0091     }
0092   }
0093 
0094   //! Creates a coordinate system where its origin is the origin of
0095   //! theA and its "X Direction" is the unit vector of theA, which is:
0096   //! -   right-handed if theIsSense is true (default value), or
0097   //! -   left-handed if theIsSense is false.
0098   constexpr gp_Ax22d(const gp_Ax2d& theA, const bool theIsSense = true)
0099       : point(theA.Location()),
0100         vxdir(theA.Direction())
0101   {
0102     if (theIsSense)
0103     {
0104       vydir.SetCoord(-vxdir.Y(), vxdir.X());
0105     }
0106     else
0107     {
0108       vydir.SetCoord(vxdir.Y(), -vxdir.X());
0109     }
0110   }
0111 
0112   //! Assigns the origin and the two unit vectors of the
0113   //! coordinate system theA1 to this coordinate system.
0114   constexpr void SetAxis(const gp_Ax22d& theA1) noexcept
0115   {
0116     point = theA1.Location();
0117     vxdir = theA1.XDirection();
0118     vydir = theA1.YDirection();
0119   }
0120 
0121   //! Changes the XAxis and YAxis ("Location" point and "Direction")
0122   //! of <me>.
0123   //! The "YDirection" is recomputed in the same sense as before.
0124   constexpr void SetXAxis(const gp_Ax2d& theA1);
0125 
0126   //! Changes the XAxis and YAxis ("Location" point and "Direction") of <me>.
0127   //! The "XDirection" is recomputed in the same sense as before.
0128   constexpr void SetYAxis(const gp_Ax2d& theA1);
0129 
0130   //! Changes the "Location" point (origin) of <me>.
0131   constexpr void SetLocation(const gp_Pnt2d& theP) noexcept { point = theP; }
0132 
0133   //! Assigns theVx to the "X Direction" of
0134   //! this coordinate system. The other unit vector of this
0135   //! coordinate system is recomputed, normal to theVx ,
0136   //! without modifying the orientation (right-handed or
0137   //! left-handed) of this coordinate system.
0138   constexpr void SetXDirection(const gp_Dir2d& theVx);
0139 
0140   //! Assigns theVy to the "Y Direction" of
0141   //! this coordinate system. The other unit vector of this
0142   //! coordinate system is recomputed, normal to theVy,
0143   //! without modifying the orientation (right-handed or
0144   //! left-handed) of this coordinate system.
0145   constexpr void SetYDirection(const gp_Dir2d& theVy);
0146 
0147   //! Returns an axis, for which
0148   //! -   the origin is that of this coordinate system, and
0149   //! -   the unit vector is either the "X Direction" of this coordinate system.
0150   //! Note: the result is the "X Axis" of this coordinate system.
0151   gp_Ax2d XAxis() const { return gp_Ax2d(point, vxdir); }
0152 
0153   //! Returns an axis, for which
0154   //! -   the origin is that of this coordinate system, and
0155   //! - the unit vector is either the "Y Direction" of this coordinate system.
0156   //! Note: the result is the "Y Axis" of this coordinate system.
0157   gp_Ax2d YAxis() const { return gp_Ax2d(point, vydir); }
0158 
0159   //! Returns the "Location" point (origin) of <me>.
0160   constexpr const gp_Pnt2d& Location() const noexcept { return point; }
0161 
0162   //! Returns the "XDirection" of <me>.
0163   constexpr const gp_Dir2d& XDirection() const noexcept { return vxdir; }
0164 
0165   //! Returns the "YDirection" of <me>.
0166   constexpr const gp_Dir2d& YDirection() const noexcept { return vydir; }
0167 
0168   Standard_EXPORT void Mirror(const gp_Pnt2d& theP) noexcept;
0169 
0170   //! Performs the symmetrical transformation of an axis
0171   //! placement with respect to the point theP which is the
0172   //! center of the symmetry.
0173   //! Warnings :
0174   //! The main direction of the axis placement is not changed.
0175   //! The "XDirection" and the "YDirection" are reversed.
0176   //! So the axis placement stay right handed.
0177   [[nodiscard]] Standard_EXPORT gp_Ax22d Mirrored(const gp_Pnt2d& theP) const noexcept;
0178 
0179   Standard_EXPORT void Mirror(const gp_Ax2d& theA) noexcept;
0180 
0181   //! Performs the symmetrical transformation of an axis
0182   //! placement with respect to an axis placement which
0183   //! is the axis of the symmetry.
0184   //! The transformation is performed on the "Location"
0185   //! point, on the "XDirection" and "YDirection".
0186   //! The resulting main "Direction" is the cross product between
0187   //! the "XDirection" and the "YDirection" after transformation.
0188   [[nodiscard]] Standard_EXPORT gp_Ax22d Mirrored(const gp_Ax2d& theA) const noexcept;
0189 
0190   void Rotate(const gp_Pnt2d& theP, const double theAng);
0191 
0192   //! Rotates an axis placement. <theA1> is the axis of the
0193   //! rotation. theAng is the angular value of the rotation
0194   //! in radians.
0195   [[nodiscard]] gp_Ax22d Rotated(const gp_Pnt2d& theP, const double theAng) const
0196   {
0197     gp_Ax22d aTemp = *this;
0198     aTemp.Rotate(theP, theAng);
0199     return aTemp;
0200   }
0201 
0202   void Scale(const gp_Pnt2d& theP, const double theS);
0203 
0204   //! Applies a scaling transformation on the axis placement.
0205   //! The "Location" point of the axisplacement is modified.
0206   //! Warnings:
0207   //! If the scale <theS> is negative:
0208   //! . the main direction of the axis placement is not changed.
0209   //! . The "XDirection" and the "YDirection" are reversed.
0210   //! So the axis placement stay right handed.
0211   [[nodiscard]] gp_Ax22d Scaled(const gp_Pnt2d& theP, const double theS) const
0212   {
0213     gp_Ax22d aTemp = *this;
0214     aTemp.Scale(theP, theS);
0215     return aTemp;
0216   }
0217 
0218   void Transform(const gp_Trsf2d& theT) noexcept;
0219 
0220   //! Transforms an axis placement with a Trsf.
0221   //! The "Location" point, the "XDirection" and the
0222   //! "YDirection" are transformed with theT. The resulting
0223   //! main "Direction" of <me> is the cross product between
0224   //! the "XDirection" and the "YDirection" after transformation.
0225   [[nodiscard]] gp_Ax22d Transformed(const gp_Trsf2d& theT) const
0226   {
0227     gp_Ax22d aTemp = *this;
0228     aTemp.Transform(theT);
0229     return aTemp;
0230   }
0231 
0232   constexpr void Translate(const gp_Vec2d& theV) noexcept { point.Translate(theV); }
0233 
0234   //! Translates an axis plaxement in the direction of the vector
0235   //! <theV>. The magnitude of the translation is the vector's magnitude.
0236   [[nodiscard]] constexpr gp_Ax22d Translated(const gp_Vec2d& theV) const noexcept
0237   {
0238     gp_Ax22d aTemp = *this;
0239     aTemp.Translate(theV);
0240     return aTemp;
0241   }
0242 
0243   constexpr void Translate(const gp_Pnt2d& theP1, const gp_Pnt2d& theP2) noexcept
0244   {
0245     point.Translate(theP1, theP2);
0246   }
0247 
0248   //! Translates an axis placement from the point <theP1> to the
0249   //! point <theP2>.
0250   [[nodiscard]] constexpr gp_Ax22d Translated(const gp_Pnt2d& theP1,
0251                                               const gp_Pnt2d& theP2) const noexcept
0252   {
0253     gp_Ax22d aTemp = *this;
0254     aTemp.Translate(theP1, theP2);
0255     return aTemp;
0256   }
0257 
0258   //! Dumps the content of me into the stream
0259   Standard_EXPORT void DumpJson(Standard_OStream& theOStream, int theDepth = -1) const;
0260 
0261 private:
0262   gp_Pnt2d point;
0263   gp_Dir2d vydir;
0264   gp_Dir2d vxdir;
0265 };
0266 
0267 //=================================================================================================
0268 
0269 inline constexpr void gp_Ax22d::SetXAxis(const gp_Ax2d& theA1)
0270 {
0271   const bool isSign = (vxdir.Crossed(vydir)) >= 0.0;
0272   point             = theA1.Location();
0273   vxdir             = theA1.Direction();
0274   if (isSign)
0275   {
0276     vydir.SetCoord(-vxdir.Y(), vxdir.X());
0277   }
0278   else
0279   {
0280     vydir.SetCoord(vxdir.Y(), -vxdir.X());
0281   }
0282 }
0283 
0284 //=================================================================================================
0285 
0286 inline constexpr void gp_Ax22d::SetYAxis(const gp_Ax2d& theA1)
0287 {
0288   const bool isSign = (vxdir.Crossed(vydir)) >= 0.0;
0289   point             = theA1.Location();
0290   vydir             = theA1.Direction();
0291   if (isSign)
0292   {
0293     vxdir.SetCoord(vydir.Y(), -vydir.X());
0294   }
0295   else
0296   {
0297     vxdir.SetCoord(-vydir.Y(), vydir.X());
0298   }
0299 }
0300 
0301 //=================================================================================================
0302 
0303 inline constexpr void gp_Ax22d::SetXDirection(const gp_Dir2d& theVx)
0304 {
0305   const bool isSign = (vxdir.Crossed(vydir)) >= 0.0;
0306   vxdir             = theVx;
0307   if (isSign)
0308   {
0309     vydir.SetCoord(-theVx.Y(), theVx.X());
0310   }
0311   else
0312   {
0313     vydir.SetCoord(theVx.Y(), -theVx.X());
0314   }
0315 }
0316 
0317 //=================================================================================================
0318 
0319 inline constexpr void gp_Ax22d::SetYDirection(const gp_Dir2d& theVy)
0320 {
0321   const bool isSign = (vxdir.Crossed(vydir)) >= 0.0;
0322   vydir             = theVy;
0323   if (isSign)
0324   {
0325     vxdir.SetCoord(theVy.Y(), -theVy.X());
0326   }
0327   else
0328   {
0329     vxdir.SetCoord(-theVy.Y(), theVy.X());
0330   }
0331 }
0332 
0333 //=================================================================================================
0334 
0335 inline void gp_Ax22d::Rotate(const gp_Pnt2d& theP, const double theAng)
0336 {
0337   gp_Pnt2d aTemp = point;
0338   aTemp.Rotate(theP, theAng);
0339   point = aTemp;
0340   vxdir.Rotate(theAng);
0341   vydir.Rotate(theAng);
0342 }
0343 
0344 //=================================================================================================
0345 
0346 inline void gp_Ax22d::Scale(const gp_Pnt2d& theP, const double theS)
0347 {
0348   gp_Pnt2d aTemp = point;
0349   aTemp.Scale(theP, theS);
0350   point = aTemp;
0351   if (theS < 0.0)
0352   {
0353     vxdir.Reverse();
0354     vydir.Reverse();
0355   }
0356 }
0357 
0358 //=================================================================================================
0359 
0360 inline void gp_Ax22d::Transform(const gp_Trsf2d& theT) noexcept
0361 {
0362   gp_Pnt2d aTemp = point;
0363   aTemp.Transform(theT);
0364   point = aTemp;
0365   vxdir.Transform(theT);
0366   vydir.Transform(theT);
0367 }
0368 
0369 #endif // _gp_Ax22d_HeaderFile