Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-10-05 09:22:21

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_Ax2d_HeaderFile
0016 #define _gp_Ax2d_HeaderFile
0017 
0018 #include <gp_Pnt2d.hxx>
0019 #include <gp_Dir2d.hxx>
0020 
0021 class gp_Trsf2d;
0022 class gp_Vec2d;
0023 
0024 //! Describes an axis in the plane (2D space).
0025 //! An axis is defined by:
0026 //! -   its origin (also referred to as its "Location point"), and
0027 //! -   its unit vector (referred to as its "Direction").
0028 //! An axis implicitly defines a direct, right-handed
0029 //! coordinate system in 2D space by:
0030 //! -   its origin,
0031 //! - its "Direction" (giving the "X Direction" of the coordinate system), and
0032 //! -   the unit vector normal to "Direction" (positive angle
0033 //! measured in the trigonometric sense).
0034 //! An axis is used:
0035 //! -   to describe 2D geometric entities (for example, the
0036 //! axis which defines angular coordinates on a circle).
0037 //! It serves for the same purpose as the STEP function
0038 //! "axis placement one axis", or
0039 //! -   to define geometric transformations (axis of
0040 //! symmetry, axis of rotation, and so on).
0041 //! Note: to define a left-handed 2D coordinate system, use gp_Ax22d.
0042 class gp_Ax2d
0043 {
0044 public:
0045   DEFINE_STANDARD_ALLOC
0046 
0047   //! Creates an axis object representing X axis of the reference coordinate system.
0048   constexpr gp_Ax2d() noexcept
0049       : loc(0., 0.)
0050   // vdir(1.,0.) use default ctor of gp_Dir2d, as it creates the same dir (1,0)
0051   {
0052   }
0053 
0054   //! Creates an Ax2d.
0055   //! <theP> is the "Location" point of the axis placement
0056   //! and theV is the "Direction" of the axis placement.
0057   constexpr gp_Ax2d(const gp_Pnt2d& theP, const gp_Dir2d& theV) noexcept
0058       : loc(theP),
0059         vdir(theV)
0060   {
0061   }
0062 
0063   //! Creates an axis with the given location point and standard direction.
0064   constexpr gp_Ax2d(const gp_Pnt2d& theP, const gp_Dir2d::D theDir) noexcept
0065       : loc(theP),
0066         vdir(theDir)
0067   {
0068   }
0069 
0070   //! Creates an axis at the origin with the given standard direction.
0071   //! Replaces gp::OX2d(), gp::OY2d() static functions.
0072   constexpr explicit gp_Ax2d(const gp_Dir2d::D theDir) noexcept
0073       : loc(0., 0.),
0074         vdir(theDir)
0075   {
0076   }
0077 
0078   //! Changes the "Location" point (origin) of <me>.
0079   constexpr void SetLocation(const gp_Pnt2d& theP) noexcept { loc = theP; }
0080 
0081   //! Changes the direction of <me>.
0082   constexpr void SetDirection(const gp_Dir2d& theV) noexcept { vdir = theV; }
0083 
0084   //! Returns the origin of <me>.
0085   constexpr const gp_Pnt2d& Location() const noexcept { return loc; }
0086 
0087   //! Returns the direction of <me>.
0088   constexpr const gp_Dir2d& Direction() const noexcept { return vdir; }
0089 
0090   //! Returns True if:
0091   //! . the angle between <me> and <Other> is lower or equal
0092   //! to <AngularTolerance> and
0093   //! . the distance between <me>.Location() and <Other> is lower
0094   //! or equal to <LinearTolerance> and
0095   //! . the distance between <Other>.Location() and <me> is lower
0096   //! or equal to LinearTolerance.
0097   Standard_EXPORT bool IsCoaxial(const gp_Ax2d& Other,
0098                                  const double   AngularTolerance,
0099                                  const double   LinearTolerance) const;
0100 
0101   //! Returns true if this axis and the axis theOther are normal to each other.
0102   //! That is, if the angle between the two axes is equal to Pi/2 or -Pi/2.
0103   //! Note: the tolerance criterion is given by theAngularTolerance.
0104   bool IsNormal(const gp_Ax2d& theOther, const double theAngularTolerance) const
0105   {
0106     return vdir.IsNormal(theOther.vdir, theAngularTolerance);
0107   }
0108 
0109   //! Returns true if this axis and the axis theOther are parallel, and have opposite orientations.
0110   //! That is, if the angle between the two axes is equal to Pi or -Pi.
0111   //! Note: the tolerance criterion is given by theAngularTolerance.
0112   bool IsOpposite(const gp_Ax2d& theOther, const double theAngularTolerance) const
0113   {
0114     return vdir.IsOpposite(theOther.vdir, theAngularTolerance);
0115   }
0116 
0117   //! Returns true if this axis and the axis theOther are parallel,
0118   //! and have either the same or opposite orientations.
0119   //! That is, if the angle between the two axes is equal to 0, Pi or -Pi.
0120   //! Note: the tolerance criterion is given by theAngularTolerance.
0121   bool IsParallel(const gp_Ax2d& theOther, const double theAngularTolerance) const
0122   {
0123     return vdir.IsParallel(theOther.vdir, theAngularTolerance);
0124   }
0125 
0126   //! Computes the angle, in radians, between this axis and the axis theOther.
0127   //! The value of the angle is between -Pi and Pi.
0128   double Angle(const gp_Ax2d& theOther) const { return vdir.Angle(theOther.vdir); }
0129 
0130   //! Reverses the direction of <me> and assigns the result to this axis.
0131   constexpr void Reverse() noexcept { vdir.Reverse(); }
0132 
0133   //! Computes a new axis placement with a direction opposite to the direction of <me>.
0134   [[nodiscard]] constexpr gp_Ax2d Reversed() const noexcept
0135   {
0136     gp_Ax2d aTemp = *this;
0137     aTemp.Reverse();
0138     return aTemp;
0139   }
0140 
0141   Standard_EXPORT void Mirror(const gp_Pnt2d& P) noexcept;
0142 
0143   //! Performs the symmetrical transformation of an axis
0144   //! placement with respect to the point P which is the
0145   //! center of the symmetry.
0146   [[nodiscard]] Standard_EXPORT gp_Ax2d Mirrored(const gp_Pnt2d& P) const noexcept;
0147 
0148   Standard_EXPORT void Mirror(const gp_Ax2d& A) noexcept;
0149 
0150   //! Performs the symmetrical transformation of an axis
0151   //! placement with respect to an axis placement which
0152   //! is the axis of the symmetry.
0153   [[nodiscard]] Standard_EXPORT gp_Ax2d Mirrored(const gp_Ax2d& A) const noexcept;
0154 
0155   void Rotate(const gp_Pnt2d& theP, const double theAng)
0156   {
0157     loc.Rotate(theP, theAng);
0158     vdir.Rotate(theAng);
0159   }
0160 
0161   //! Rotates an axis placement. <theP> is the center of the rotation.
0162   //! theAng is the angular value of the rotation in radians.
0163   [[nodiscard]] gp_Ax2d Rotated(const gp_Pnt2d& theP, const double theAng) const
0164   {
0165     gp_Ax2d anA = *this;
0166     anA.Rotate(theP, theAng);
0167     return anA;
0168   }
0169 
0170   Standard_EXPORT void Scale(const gp_Pnt2d& P, const double S);
0171 
0172   //! Applies a scaling transformation on the axis placement.
0173   //! The "Location" point of the axisplacement is modified.
0174   //! The "Direction" is reversed if the scale is negative.
0175   [[nodiscard]] gp_Ax2d Scaled(const gp_Pnt2d& theP, const double theS) const
0176   {
0177     gp_Ax2d anA = *this;
0178     anA.Scale(theP, theS);
0179     return anA;
0180   }
0181 
0182   void Transform(const gp_Trsf2d& theT)
0183   {
0184     loc.Transform(theT);
0185     vdir.Transform(theT);
0186   }
0187 
0188   //! Transforms an axis placement with a Trsf.
0189   [[nodiscard]] gp_Ax2d Transformed(const gp_Trsf2d& theT) const
0190   {
0191     gp_Ax2d anA = *this;
0192     anA.Transform(theT);
0193     return anA;
0194   }
0195 
0196   constexpr void Translate(const gp_Vec2d& theV) noexcept { loc.Translate(theV); }
0197 
0198   //! Translates an axis placement in the direction of the vector theV.
0199   //! The magnitude of the translation is the vector's magnitude.
0200   [[nodiscard]] constexpr gp_Ax2d Translated(const gp_Vec2d& theV) const noexcept
0201   {
0202     gp_Ax2d anA = *this;
0203     (anA.loc).Translate(theV);
0204     return anA;
0205   }
0206 
0207   constexpr void Translate(const gp_Pnt2d& theP1, const gp_Pnt2d& theP2) noexcept
0208   {
0209     loc.Translate(theP1, theP2);
0210   }
0211 
0212   //! Translates an axis placement from the point theP1 to the point theP2.
0213   [[nodiscard]] constexpr gp_Ax2d Translated(const gp_Pnt2d& theP1,
0214                                              const gp_Pnt2d& theP2) const noexcept
0215   {
0216     gp_Ax2d anA = *this;
0217     (anA.loc).Translate(theP1, theP2);
0218     return anA;
0219   }
0220 
0221   //! Dumps the content of me into the stream
0222   Standard_EXPORT void DumpJson(Standard_OStream& theOStream, int theDepth = -1) const;
0223 
0224 private:
0225   gp_Pnt2d loc;
0226   gp_Dir2d vdir;
0227 };
0228 
0229 #endif // _gp_Ax2d_HeaderFile