From d5477f8c82f80b2f1fb6dd0362180e01d6ac87e1 Mon Sep 17 00:00:00 2001 From: mkrylova Date: Wed, 17 Feb 2021 13:49:32 +0300 Subject: [PATCH] 0032137: Coding Rules - merge redundant .lxx files into header files within Package gp - merged .lxx files into header files within Package gp - fixed code style --- src/DsgPrs/DsgPrs.hxx | 2 + src/IntAna/IntAna_Curve.hxx | 2 + src/PrsDim/PrsDim.hxx | 1 + src/PrsDim/PrsDim_Dimension.hxx | 1 + src/PrsDim/PrsDim_FixRelation.hxx | 2 + src/StdPrs/StdPrs_Isolines.hxx | 1 + src/gp/FILES | 36 -- src/gp/gp.cxx | 2 +- src/gp/gp.hxx | 129 +----- src/gp/gp.lxx | 19 - src/gp/gp_Ax1.cxx | 2 +- src/gp/gp_Ax1.hxx | 222 +++++----- src/gp/gp_Ax1.lxx | 128 ------ src/gp/gp_Ax2.cxx | 2 +- src/gp/gp_Ax2.hxx | 291 +++++++++---- src/gp/gp_Ax2.lxx | 212 ---------- src/gp/gp_Ax22d.cxx | 3 +- src/gp/gp_Ax22d.hxx | 364 +++++++++++------ src/gp/gp_Ax22d.lxx | 184 --------- src/gp/gp_Ax2d.cxx | 2 +- src/gp/gp_Ax2d.hxx | 214 +++++----- src/gp/gp_Ax2d.lxx | 127 ------ src/gp/gp_Ax3.cxx | 2 +- src/gp/gp_Ax3.hxx | 409 +++++++++++++------ src/gp/gp_Ax3.lxx | 200 --------- src/gp/gp_Circ.cxx | 2 +- src/gp/gp_Circ.hxx | 270 ++++++------ src/gp/gp_Circ.lxx | 153 ------- src/gp/gp_Circ2d.cxx | 3 +- src/gp/gp_Circ2d.hxx | 370 +++++++++++------ src/gp/gp_Circ2d.lxx | 203 --------- src/gp/gp_Cone.cxx | 3 +- src/gp/gp_Cone.hxx | 317 +++++++++------ src/gp/gp_Cone.lxx | 168 -------- src/gp/gp_Cylinder.cxx | 3 +- src/gp/gp_Cylinder.hxx | 257 +++++++----- src/gp/gp_Cylinder.lxx | 136 ------- src/gp/gp_Dir.cxx | 3 +- src/gp/gp_Dir.hxx | 538 ++++++++++++++++-------- src/gp/gp_Dir.lxx | 254 ------------ src/gp/gp_Dir2d.cxx | 3 +- src/gp/gp_Dir2d.hxx | 432 ++++++++++++++------ src/gp/gp_Dir2d.lxx | 197 --------- src/gp/gp_Elips.cxx | 3 +- src/gp/gp_Elips.hxx | 400 ++++++++++++------ src/gp/gp_Elips.lxx | 224 ---------- src/gp/gp_Elips2d.cxx | 3 +- src/gp/gp_Elips2d.hxx | 444 ++++++++++++++------ src/gp/gp_Elips2d.lxx | 249 ------------ src/gp/gp_GTrsf.cxx | 2 +- src/gp/gp_GTrsf.hxx | 375 +++++++++++------ src/gp/gp_GTrsf.lxx | 189 --------- src/gp/gp_GTrsf2d.cxx | 2 +- src/gp/gp_GTrsf2d.hxx | 310 +++++++++----- src/gp/gp_GTrsf2d.lxx | 131 ------ src/gp/gp_Hypr.cxx | 3 +- src/gp/gp_Hypr.hxx | 444 +++++++++++++------- src/gp/gp_Hypr.lxx | 261 ------------ src/gp/gp_Hypr2d.cxx | 2 +- src/gp/gp_Hypr2d.hxx | 481 +++++++++++++++------- src/gp/gp_Hypr2d.lxx | 288 ------------- src/gp/gp_Lin.cxx | 3 +- src/gp/gp_Lin.hxx | 281 +++++++------ src/gp/gp_Lin.lxx | 150 ------- src/gp/gp_Lin2d.cxx | 2 +- src/gp/gp_Lin2d.hxx | 289 +++++++------ src/gp/gp_Lin2d.lxx | 164 -------- src/gp/gp_Mat.cxx | 2 +- src/gp/gp_Mat.hxx | 655 ++++++++++++++++++++++-------- src/gp/gp_Mat.lxx | 355 ---------------- src/gp/gp_Mat2d.cxx | 2 +- src/gp/gp_Mat2d.hxx | 550 +++++++++++++++++-------- src/gp/gp_Mat2d.lxx | 268 ------------ src/gp/gp_Parab.cxx | 3 +- src/gp/gp_Parab.hxx | 303 +++++++++----- src/gp/gp_Parab.lxx | 167 -------- src/gp/gp_Parab2d.cxx | 2 +- src/gp/gp_Parab2d.hxx | 293 ++++++++----- src/gp/gp_Parab2d.lxx | 166 -------- src/gp/gp_Pln.cxx | 3 +- src/gp/gp_Pln.hxx | 376 ++++++++++------- src/gp/gp_Pln.lxx | 193 --------- src/gp/gp_Pnt.cxx | 2 +- src/gp/gp_Pnt.hxx | 316 ++++++++------ src/gp/gp_Pnt.lxx | 178 -------- src/gp/gp_Pnt2d.cxx | 2 +- src/gp/gp_Pnt2d.hxx | 267 +++++++----- src/gp/gp_Pnt2d.lxx | 155 ------- src/gp/gp_Quaternion.cxx | 1 + src/gp/gp_Quaternion.hxx | 348 ++++++++++------ src/gp/gp_Quaternion.lxx | 341 ---------------- src/gp/gp_Sphere.cxx | 2 +- src/gp/gp_Sphere.hxx | 272 ++++++++----- src/gp/gp_Sphere.lxx | 135 ------ src/gp/gp_Torus.cxx | 2 +- src/gp/gp_Torus.hxx | 321 +++++++++------ src/gp/gp_Torus.lxx | 165 -------- src/gp/gp_Trsf.cxx | 2 +- src/gp/gp_Trsf.hxx | 326 +++++++++------ src/gp/gp_Trsf.lxx | 126 ------ src/gp/gp_Trsf2d.cxx | 2 +- src/gp/gp_Trsf2d.hxx | 318 ++++++++++----- src/gp/gp_Trsf2d.lxx | 145 ------- src/gp/gp_Vec.cxx | 2 +- src/gp/gp_Vec.hxx | 654 +++++++++++++++++------------ src/gp/gp_Vec.lxx | 324 --------------- src/gp/gp_Vec2d.cxx | 2 +- src/gp/gp_Vec2d.hxx | 528 ++++++++++++++---------- src/gp/gp_Vec2d.lxx | 246 ----------- src/gp/gp_XY.cxx | 2 +- src/gp/gp_XY.hxx | 492 ++++++++++++---------- src/gp/gp_XY.lxx | 229 ----------- src/gp/gp_XYZ.cxx | 2 +- src/gp/gp_XYZ.hxx | 633 ++++++++++++++++++----------- src/gp/gp_XYZ.lxx | 313 -------------- 115 files changed, 8693 insertions(+), 12067 deletions(-) delete mode 100644 src/gp/gp.lxx delete mode 100644 src/gp/gp_Ax1.lxx delete mode 100644 src/gp/gp_Ax2.lxx delete mode 100644 src/gp/gp_Ax22d.lxx delete mode 100644 src/gp/gp_Ax2d.lxx delete mode 100644 src/gp/gp_Ax3.lxx delete mode 100644 src/gp/gp_Circ.lxx delete mode 100644 src/gp/gp_Circ2d.lxx delete mode 100644 src/gp/gp_Cone.lxx delete mode 100644 src/gp/gp_Cylinder.lxx delete mode 100644 src/gp/gp_Dir.lxx delete mode 100644 src/gp/gp_Dir2d.lxx delete mode 100644 src/gp/gp_Elips.lxx delete mode 100644 src/gp/gp_Elips2d.lxx delete mode 100644 src/gp/gp_GTrsf.lxx delete mode 100644 src/gp/gp_GTrsf2d.lxx delete mode 100644 src/gp/gp_Hypr.lxx delete mode 100644 src/gp/gp_Hypr2d.lxx delete mode 100644 src/gp/gp_Lin.lxx delete mode 100644 src/gp/gp_Lin2d.lxx delete mode 100644 src/gp/gp_Mat.lxx delete mode 100644 src/gp/gp_Mat2d.lxx delete mode 100644 src/gp/gp_Parab.lxx delete mode 100644 src/gp/gp_Parab2d.lxx delete mode 100644 src/gp/gp_Pln.lxx delete mode 100644 src/gp/gp_Pnt.lxx delete mode 100644 src/gp/gp_Pnt2d.lxx delete mode 100644 src/gp/gp_Quaternion.lxx delete mode 100644 src/gp/gp_Sphere.lxx delete mode 100644 src/gp/gp_Torus.lxx delete mode 100644 src/gp/gp_Trsf.lxx delete mode 100644 src/gp/gp_Trsf2d.lxx delete mode 100644 src/gp/gp_Vec.lxx delete mode 100644 src/gp/gp_Vec2d.lxx delete mode 100644 src/gp/gp_XY.lxx delete mode 100644 src/gp/gp_XYZ.lxx diff --git a/src/DsgPrs/DsgPrs.hxx b/src/DsgPrs/DsgPrs.hxx index 06cc1f2034..0d8dc44f32 100644 --- a/src/DsgPrs/DsgPrs.hxx +++ b/src/DsgPrs/DsgPrs.hxx @@ -20,6 +20,8 @@ #include #include #include +#include +#include #include class Geom_Curve; diff --git a/src/IntAna/IntAna_Curve.hxx b/src/IntAna/IntAna_Curve.hxx index 9aa08baf85..4a3d35d220 100644 --- a/src/IntAna/IntAna_Curve.hxx +++ b/src/IntAna/IntAna_Curve.hxx @@ -23,6 +23,8 @@ #include #include +#include +#include #include //! Definition of a parametric Curve which is the result diff --git a/src/PrsDim/PrsDim.hxx b/src/PrsDim/PrsDim.hxx index c865cb71af..f272c89cdd 100644 --- a/src/PrsDim/PrsDim.hxx +++ b/src/PrsDim/PrsDim.hxx @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include diff --git a/src/PrsDim/PrsDim_Dimension.hxx b/src/PrsDim/PrsDim_Dimension.hxx index bc2047b145..13bf0c6e3d 100644 --- a/src/PrsDim/PrsDim_Dimension.hxx +++ b/src/PrsDim/PrsDim_Dimension.hxx @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include diff --git a/src/PrsDim/PrsDim_FixRelation.hxx b/src/PrsDim/PrsDim_FixRelation.hxx index dcb7b583c1..4de0383e91 100644 --- a/src/PrsDim/PrsDim_FixRelation.hxx +++ b/src/PrsDim/PrsDim_FixRelation.hxx @@ -17,6 +17,8 @@ #ifndef _PrsDim_FixRelation_HeaderFile #define _PrsDim_FixRelation_HeaderFile +#include +#include #include #include diff --git a/src/StdPrs/StdPrs_Isolines.hxx b/src/StdPrs/StdPrs_Isolines.hxx index 244c29610a..ab3f5f538c 100644 --- a/src/StdPrs/StdPrs_Isolines.hxx +++ b/src/StdPrs/StdPrs_Isolines.hxx @@ -18,6 +18,7 @@ #include #include +#include #include #include #include diff --git a/src/gp/FILES b/src/gp/FILES index 02ead9cff6..06e80cf7ab 100644 --- a/src/gp/FILES +++ b/src/gp/FILES @@ -1,116 +1,80 @@ gp.cxx gp.hxx -gp.lxx gp_Ax1.cxx gp_Ax1.hxx -gp_Ax1.lxx gp_Ax2.cxx gp_Ax2.hxx -gp_Ax2.lxx gp_Ax2d.cxx gp_Ax2d.hxx -gp_Ax2d.lxx gp_Ax3.cxx gp_Ax3.hxx -gp_Ax3.lxx gp_Ax22d.cxx gp_Ax22d.hxx -gp_Ax22d.lxx gp_Circ.cxx gp_Circ.hxx -gp_Circ.lxx gp_Circ2d.cxx gp_Circ2d.hxx -gp_Circ2d.lxx gp_Cone.cxx gp_Cone.hxx -gp_Cone.lxx gp_Cylinder.cxx gp_Cylinder.hxx -gp_Cylinder.lxx gp_Dir.cxx gp_Dir.hxx -gp_Dir.lxx gp_Dir2d.cxx gp_Dir2d.hxx -gp_Dir2d.lxx gp_Elips.cxx gp_Elips.hxx -gp_Elips.lxx gp_Elips2d.cxx gp_Elips2d.hxx -gp_Elips2d.lxx gp_EulerSequence.hxx gp_GTrsf.cxx gp_GTrsf.hxx -gp_GTrsf.lxx gp_GTrsf2d.cxx gp_GTrsf2d.hxx -gp_GTrsf2d.lxx gp_Hypr.cxx gp_Hypr.hxx -gp_Hypr.lxx gp_Hypr2d.cxx gp_Hypr2d.hxx -gp_Hypr2d.lxx gp_Lin.cxx gp_Lin.hxx -gp_Lin.lxx gp_Lin2d.cxx gp_Lin2d.hxx -gp_Lin2d.lxx gp_Mat.cxx gp_Mat.hxx -gp_Mat.lxx gp_Mat2d.cxx gp_Mat2d.hxx -gp_Mat2d.lxx gp_Parab.cxx gp_Parab.hxx -gp_Parab.lxx gp_Parab2d.cxx gp_Parab2d.hxx -gp_Parab2d.lxx gp_Pln.cxx gp_Pln.hxx -gp_Pln.lxx gp_Pnt.cxx gp_Pnt.hxx -gp_Pnt.lxx gp_Pnt2d.cxx gp_Pnt2d.hxx -gp_Pnt2d.lxx gp_Quaternion.cxx gp_Quaternion.hxx -gp_Quaternion.lxx gp_QuaternionNLerp.hxx gp_QuaternionSLerp.hxx gp_Sphere.cxx gp_Sphere.hxx -gp_Sphere.lxx gp_Torus.cxx gp_Torus.hxx -gp_Torus.lxx gp_Trsf.cxx gp_Trsf.hxx -gp_Trsf.lxx gp_Trsf2d.cxx gp_Trsf2d.hxx -gp_Trsf2d.lxx gp_TrsfForm.hxx gp_TrsfNLerp.hxx gp_Vec.cxx gp_Vec.hxx -gp_Vec.lxx gp_Vec2d.cxx gp_Vec2d.hxx -gp_Vec2d.lxx gp_Vec2f.hxx gp_Vec3f.hxx gp_VectorWithNullMagnitude.hxx gp_XY.cxx gp_XY.hxx -gp_XY.lxx gp_XYZ.cxx gp_XYZ.hxx -gp_XYZ.lxx diff --git a/src/gp/gp.cxx b/src/gp/gp.cxx index e269c3bda7..96ebebcf2c 100644 --- a/src/gp/gp.cxx +++ b/src/gp/gp.cxx @@ -12,8 +12,8 @@ // Alternatively, this file may be used under the terms of Open CASCADE // commercial license or contractual agreement. - #include + #include #include #include diff --git a/src/gp/gp.hxx b/src/gp/gp.hxx index f6914eb82f..df23c4d1b7 100644 --- a/src/gp/gp.hxx +++ b/src/gp/gp.hxx @@ -20,8 +20,8 @@ #include #include #include - #include + class gp_Pnt; class gp_Dir; class gp_Ax1; @@ -29,43 +29,6 @@ class gp_Ax2; class gp_Pnt2d; class gp_Dir2d; class gp_Ax2d; -class gp_XYZ; -class gp_Mat; -class gp_Quaternion; -class gp_Trsf; -class gp_GTrsf; -class gp_Pnt; -class gp_Vec; -class gp_Dir; -class gp_Ax1; -class gp_Ax2; -class gp_Ax3; -class gp_Lin; -class gp_Circ; -class gp_Elips; -class gp_Hypr; -class gp_Parab; -class gp_Pln; -class gp_Cylinder; -class gp_Sphere; -class gp_Torus; -class gp_Cone; -class gp_XY; -class gp_Mat2d; -class gp_Trsf2d; -class gp_GTrsf2d; -class gp_Pnt2d; -class gp_Vec2d; -class gp_Dir2d; -class gp_Ax2d; -class gp_Ax22d; -class gp_Lin2d; -class gp_Circ2d; -class gp_Elips2d; -class gp_Hypr2d; -class gp_Parab2d; - - //! The geometric processor package, called gp, provides an //! implementation of entities used : @@ -82,7 +45,6 @@ public: DEFINE_STANDARD_ALLOC - //! Method of package gp //! //! In geometric computations, defines the tolerance criterion @@ -91,122 +53,65 @@ public: //! example, to avoid division by zero in geometric //! computations. In the documentation, tolerance criterion is //! always referred to as gp::Resolution(). - static Standard_Real Resolution(); - + static Standard_Real Resolution() { return RealSmall(); } + //! Identifies a Cartesian point with coordinates X = Y = Z = 0.0.0 Standard_EXPORT static const gp_Pnt& Origin(); - + //! Returns a unit vector with the combination (1,0,0) Standard_EXPORT static const gp_Dir& DX(); - + //! Returns a unit vector with the combination (0,1,0) Standard_EXPORT static const gp_Dir& DY(); - + //! Returns a unit vector with the combination (0,0,1) Standard_EXPORT static const gp_Dir& DZ(); - + //! Identifies an axis where its origin is Origin //! and its unit vector coordinates X = 1.0, Y = Z = 0.0 Standard_EXPORT static const gp_Ax1& OX(); - + //! Identifies an axis where its origin is Origin //! and its unit vector coordinates Y = 1.0, X = Z = 0.0 Standard_EXPORT static const gp_Ax1& OY(); - + //! Identifies an axis where its origin is Origin //! and its unit vector coordinates Z = 1.0, Y = X = 0.0 Standard_EXPORT static const gp_Ax1& OZ(); - + //! Identifies a coordinate system where its origin is Origin, //! and its "main Direction" and "X Direction" coordinates //! Z = 1.0, X = Y =0.0 and X direction coordinates X = 1.0, Y = Z = 0.0 Standard_EXPORT static const gp_Ax2& XOY(); - + //! Identifies a coordinate system where its origin is Origin, //! and its "main Direction" and "X Direction" coordinates //! Y = 1.0, X = Z =0.0 and X direction coordinates Z = 1.0, X = Y = 0.0 Standard_EXPORT static const gp_Ax2& ZOX(); - + //! Identifies a coordinate system where its origin is Origin, //! and its "main Direction" and "X Direction" coordinates //! X = 1.0, Z = Y =0.0 and X direction coordinates Y = 1.0, X = Z = 0.0 //! In 2D space Standard_EXPORT static const gp_Ax2& YOZ(); - + //! Identifies a Cartesian point with coordinates X = Y = 0.0 Standard_EXPORT static const gp_Pnt2d& Origin2d(); - + //! Returns a unit vector with the combinations (1,0) Standard_EXPORT static const gp_Dir2d& DX2d(); - + //! Returns a unit vector with the combinations (0,1) Standard_EXPORT static const gp_Dir2d& DY2d(); - + //! Identifies an axis where its origin is Origin2d //! and its unit vector coordinates are: X = 1.0, Y = 0.0 Standard_EXPORT static const gp_Ax2d& OX2d(); - + //! Identifies an axis where its origin is Origin2d //! and its unit vector coordinates are Y = 1.0, X = 0.0 Standard_EXPORT static const gp_Ax2d& OY2d(); - - - -protected: - - - - - -private: - - - - -friend class gp_XYZ; -friend class gp_Mat; -friend class gp_Quaternion; -friend class gp_Trsf; -friend class gp_GTrsf; -friend class gp_Pnt; -friend class gp_Vec; -friend class gp_Dir; -friend class gp_Ax1; -friend class gp_Ax2; -friend class gp_Ax3; -friend class gp_Lin; -friend class gp_Circ; -friend class gp_Elips; -friend class gp_Hypr; -friend class gp_Parab; -friend class gp_Pln; -friend class gp_Cylinder; -friend class gp_Sphere; -friend class gp_Torus; -friend class gp_Cone; -friend class gp_XY; -friend class gp_Mat2d; -friend class gp_Trsf2d; -friend class gp_GTrsf2d; -friend class gp_Pnt2d; -friend class gp_Vec2d; -friend class gp_Dir2d; -friend class gp_Ax2d; -friend class gp_Ax22d; -friend class gp_Lin2d; -friend class gp_Circ2d; -friend class gp_Elips2d; -friend class gp_Hypr2d; -friend class gp_Parab2d; - }; - -#include - - - - - #endif // _gp_HeaderFile diff --git a/src/gp/gp.lxx b/src/gp/gp.lxx deleted file mode 100644 index b67bb9a7ed..0000000000 --- a/src/gp/gp.lxx +++ /dev/null @@ -1,19 +0,0 @@ -// Created on: 1992-07-21 -// Copyright (c) 1992-1999 Matra Datavision -// Copyright (c) 1999-2014 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -inline Standard_Real gp::Resolution () -{ - return RealSmall(); -} diff --git a/src/gp/gp_Ax1.cxx b/src/gp/gp_Ax1.cxx index 19a5cfb286..892b453022 100644 --- a/src/gp/gp_Ax1.cxx +++ b/src/gp/gp_Ax1.cxx @@ -19,9 +19,9 @@ #define No_Standard_OutOfRange +#include #include -#include #include #include #include diff --git a/src/gp/gp_Ax1.hxx b/src/gp/gp_Ax1.hxx index 3efc5e17fd..4e92b97f4f 100644 --- a/src/gp/gp_Ax1.hxx +++ b/src/gp/gp_Ax1.hxx @@ -15,21 +15,13 @@ #ifndef _gp_Ax1_HeaderFile #define _gp_Ax1_HeaderFile -#include -#include -#include - #include #include -#include -#include -class gp_Pnt; -class gp_Dir; + class gp_Ax2; class gp_Trsf; class gp_Vec; - //! Describes an axis in 3D space. //! An axis is defined by: //! - its origin (also referred to as its "Location point"), and @@ -48,27 +40,28 @@ public: DEFINE_STANDARD_ALLOC - //! Creates an axis object representing Z axis of //! the reference coordinate system. - gp_Ax1(); - + gp_Ax1() + : loc(0.,0.,0.), vdir(0.,0.,1.) + {} //! P is the location point and V is the direction of . - gp_Ax1(const gp_Pnt& P, const gp_Dir& V); - + gp_Ax1 (const gp_Pnt& theP, const gp_Dir& theV) + : loc(theP), vdir (theV) + {} + //! Assigns V as the "Direction" of this axis. - void SetDirection (const gp_Dir& V); - + void SetDirection (const gp_Dir& theV) { vdir = theV; } + //! Assigns P as the origin of this axis. - void SetLocation (const gp_Pnt& P); - + void SetLocation (const gp_Pnt& theP) { loc = theP; } + //! Returns the direction of . - const gp_Dir& Direction() const; - + const gp_Dir& Direction() const { return vdir; } + //! Returns the location point of . - const gp_Pnt& Location() const; - + const gp_Pnt& Location() const { return loc; } //! Returns True if : //! . the angle between and is lower or equal @@ -78,132 +71,157 @@ public: //! . the distance between .Location() and is lower //! or equal to LinearTolerance. Standard_EXPORT Standard_Boolean IsCoaxial (const gp_Ax1& Other, const Standard_Real AngularTolerance, const Standard_Real LinearTolerance) const; - - //! Returns True if the direction of the and - //! are normal to each other. + //! Returns True if the direction of this and another axis are normal to each other. //! That is, if the angle between the two axes is equal to Pi/2. - //! Note: the tolerance criterion is given by AngularTolerance.. - Standard_Boolean IsNormal (const gp_Ax1& Other, const Standard_Real AngularTolerance) const; - + //! Note: the tolerance criterion is given by theAngularTolerance. + Standard_Boolean IsNormal (const gp_Ax1& theOther, const Standard_Real theAngularTolerance) const + { + return vdir.IsNormal (theOther.vdir, theAngularTolerance); + } - //! Returns True if the direction of and are - //! parallel with opposite orientation. That is, if the angle - //! between the two axes is equal to Pi. - //! Note: the tolerance criterion is given by AngularTolerance. - Standard_Boolean IsOpposite (const gp_Ax1& Other, const Standard_Real AngularTolerance) const; - + //! Returns True if the direction of this and another axis are parallel with opposite orientation. + //! That is, if the angle between the two axes is equal to Pi. + //! Note: the tolerance criterion is given by theAngularTolerance. + Standard_Boolean IsOpposite (const gp_Ax1& theOther, const Standard_Real theAngularTolerance) const + { + return vdir.IsOpposite (theOther.vdir, theAngularTolerance); + } - //! Returns True if the direction of and are - //! parallel with same orientation or opposite orientation. That - //! is, if the angle between the two axes is equal to 0 or Pi. - //! Note: the tolerance criterion is given by - //! AngularTolerance. - Standard_Boolean IsParallel (const gp_Ax1& Other, const Standard_Real AngularTolerance) const; - + //! Returns True if the direction of this and another axis are parallel with same orientation or opposite orientation. + //! That is, if the angle between the two axes is equal to 0 or Pi. + //! Note: the tolerance criterion is given by theAngularTolerance. + Standard_Boolean IsParallel (const gp_Ax1& theOther, const Standard_Real theAngularTolerance) const + { + return vdir.IsParallel(theOther.vdir, theAngularTolerance); + } + + //! Computes the angular value, in radians, between this.Direction() and theOther.Direction(). + //! Returns the angle between 0 and 2*PI radians. + Standard_Real Angle (const gp_Ax1& theOther) const { return vdir.Angle (theOther.vdir); } + + //! Reverses the unit vector of this axis and assigns the result to this axis. + void Reverse() { vdir.Reverse(); } - //! Computes the angular value, in radians, between .Direction() and - //! .Direction(). Returns the angle between 0 and 2*PI - //! radians. - Standard_Real Angle (const gp_Ax1& Other) const; - - //! Reverses the unit vector of this axis. - //! and assigns the result to this axis. - void Reverse(); - //! Reverses the unit vector of this axis and creates a new one. - Standard_NODISCARD gp_Ax1 Reversed() const; - + Standard_NODISCARD gp_Ax1 Reversed() const + { + gp_Dir D = vdir.Reversed(); + return gp_Ax1 (loc, D); + } //! Performs the symmetrical transformation of an axis //! placement with respect to the point P which is the //! center of the symmetry and assigns the result to this axis. Standard_EXPORT void Mirror (const gp_Pnt& P); - + //! Performs the symmetrical transformation of an axis //! placement with respect to the point P which is the //! center of the symmetry and creates a new axis. Standard_NODISCARD Standard_EXPORT gp_Ax1 Mirrored (const gp_Pnt& P) const; - //! Performs the symmetrical transformation of an axis //! placement with respect to an axis placement which //! is the axis of the symmetry and assigns the result to this axis. Standard_EXPORT void Mirror (const gp_Ax1& A1); - //! Performs the symmetrical transformation of an axis //! placement with respect to an axis placement which //! is the axis of the symmetry and creates a new axis. Standard_NODISCARD Standard_EXPORT gp_Ax1 Mirrored (const gp_Ax1& A1) const; - //! Performs the symmetrical transformation of an axis //! placement with respect to a plane. The axis placement //! locates the plane of the symmetry : //! (Location, XDirection, YDirection) and assigns the result to this axis. Standard_EXPORT void Mirror (const gp_Ax2& A2); - //! Performs the symmetrical transformation of an axis //! placement with respect to a plane. The axis placement //! locates the plane of the symmetry : //! (Location, XDirection, YDirection) and creates a new axis. Standard_NODISCARD Standard_EXPORT gp_Ax1 Mirrored (const gp_Ax2& A2) const; - - //! Rotates this axis at an angle Ang (in radians) about the axis A1 + + //! Rotates this axis at an angle theAngRad (in radians) about the axis theA1 //! and assigns the result to this axis. - void Rotate (const gp_Ax1& A1, const Standard_Real Ang); - - //! Rotates this axis at an angle Ang (in radians) about the axis A1 + void Rotate (const gp_Ax1& theA1, const Standard_Real theAngRad) + { + loc .Rotate (theA1, theAngRad); + vdir.Rotate (theA1, theAngRad); + } + + //! Rotates this axis at an angle theAngRad (in radians) about the axis theA1 //! and creates a new one. - Standard_NODISCARD gp_Ax1 Rotated (const gp_Ax1& A1, const Standard_Real Ang) const; - + Standard_NODISCARD gp_Ax1 Rotated (const gp_Ax1& theA1, const Standard_Real theAngRad) const + { + gp_Ax1 A = *this; + A.Rotate (theA1, theAngRad); + return A; + } //! Applies a scaling transformation to this axis with: - //! - scale factor S, and - //! - center P and assigns the result to this axis. - void Scale (const gp_Pnt& P, const Standard_Real S); - + //! - scale factor theS, and + //! - center theP and assigns the result to this axis. + void Scale (const gp_Pnt& theP, const Standard_Real theS) + { + loc.Scale (theP, theS); + if (theS < 0.0) { vdir.Reverse(); } + } //! Applies a scaling transformation to this axis with: - //! - scale factor S, and - //! - center P and creates a new axis. - Standard_NODISCARD gp_Ax1 Scaled (const gp_Pnt& P, const Standard_Real S) const; - - //! Applies the transformation T to this axis. - //! and assigns the result to this axis. - void Transform (const gp_Trsf& T); - + //! - scale factor theS, and + //! - center theP and creates a new axis. + Standard_NODISCARD gp_Ax1 Scaled (const gp_Pnt& theP, const Standard_Real theS) const + { + gp_Ax1 A1 = *this; + A1.Scale (theP, theS); + return A1; + } - //! Applies the transformation T to this axis and creates a new one. + //! Applies the transformation theT to this axis and assigns the result to this axis. + void Transform (const gp_Trsf& theT) + { + loc .Transform (theT); + vdir.Transform (theT); + } + + //! Applies the transformation theT to this axis and creates a new one. //! - //! Translates an axis plaxement in the direction of the vector - //! . The magnitude of the translation is the vector's magnitude. - Standard_NODISCARD gp_Ax1 Transformed (const gp_Trsf& T) const; - + //! Translates an axis plaxement in the direction of the vector . + //! The magnitude of the translation is the vector's magnitude. + Standard_NODISCARD gp_Ax1 Transformed (const gp_Trsf& theT) const + { + gp_Ax1 A1 = *this; + A1.Transform (theT); + return A1; + } - //! Translates this axis by the vector V, - //! and assigns the result to this axis. - void Translate (const gp_Vec& V); - + //! Translates this axis by the vector theV, and assigns the result to this axis. + void Translate (const gp_Vec& theV) { loc.Translate (theV); } - //! Translates this axis by the vector V, + //! Translates this axis by the vector theV, //! and creates a new one. - Standard_NODISCARD gp_Ax1 Translated (const gp_Vec& V) const; - + Standard_NODISCARD gp_Ax1 Translated (const gp_Vec& theV) const + { + gp_Ax1 A1 = *this; + (A1.loc).Translate (theV); + return A1; + } //! Translates this axis by: - //! the vector (P1, P2) defined from point P1 to point P2. + //! the vector (theP1, theP2) defined from point theP1 to point theP2. //! and assigns the result to this axis. - void Translate (const gp_Pnt& P1, const gp_Pnt& P2); - + void Translate (const gp_Pnt& theP1, const gp_Pnt& theP2) { loc.Translate (theP1, theP2); } //! Translates this axis by: - //! the vector (P1, P2) defined from point P1 to point P2. + //! the vector (theP1, theP2) defined from point theP1 to point theP2. //! and creates a new one. - Standard_NODISCARD gp_Ax1 Translated (const gp_Pnt& P1, const gp_Pnt& P2) const; - + Standard_NODISCARD gp_Ax1 Translated (const gp_Pnt& theP1, const gp_Pnt& theP2) const + { + gp_Ax1 A1 = *this; + (A1.loc).Translate (theP1, theP2); + return A1; + } //! Dumps the content of me into the stream Standard_EXPORT void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const; @@ -211,27 +229,11 @@ public: //! Inits the content of me from the stream Standard_EXPORT Standard_Boolean InitFromJson (const Standard_SStream& theSStream, Standard_Integer& theStreamPos); -protected: - - - - - private: - - gp_Pnt loc; gp_Dir vdir; - }; - -#include - - - - - #endif // _gp_Ax1_HeaderFile diff --git a/src/gp/gp_Ax1.lxx b/src/gp/gp_Ax1.lxx deleted file mode 100644 index 0ec76ea9fe..0000000000 --- a/src/gp/gp_Ax1.lxx +++ /dev/null @@ -1,128 +0,0 @@ -// Copyright (c) 1995-1999 Matra Datavision -// Copyright (c) 1999-2014 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -// JCV, LPA 07/92 - -inline gp_Ax1::gp_Ax1() : loc(0.,0.,0.), vdir(0.,0.,1.) -{ } - -inline gp_Ax1::gp_Ax1 (const gp_Pnt& P, - const gp_Dir& V) : loc(P), vdir(V) -{ } - -inline void gp_Ax1::SetDirection (const gp_Dir& V) -{ vdir = V; } - -inline void gp_Ax1::SetLocation (const gp_Pnt& P) -{ loc = P; } - -inline const gp_Dir& gp_Ax1::Direction () const -{ return vdir; } - -inline const gp_Pnt& gp_Ax1::Location () const -{ return loc; } - -inline Standard_Boolean gp_Ax1::IsNormal -(const gp_Ax1& Other, - const Standard_Real AngularTolerance) const -{ return vdir.IsNormal(Other.vdir, AngularTolerance); } - -inline Standard_Boolean gp_Ax1::IsOpposite -(const gp_Ax1& Other, - const Standard_Real AngularTolerance) const -{ return vdir.IsOpposite(Other.vdir, AngularTolerance); } - -inline Standard_Boolean gp_Ax1::IsParallel -(const gp_Ax1& Other, - const Standard_Real AngularTolerance) const -{ return vdir.IsParallel(Other.vdir, AngularTolerance); } - -inline Standard_Real gp_Ax1::Angle (const gp_Ax1& Other) const -{ return vdir.Angle (Other.vdir); } - -inline void gp_Ax1::Reverse () -{ vdir.Reverse(); } - -inline gp_Ax1 gp_Ax1::Reversed () const -{ - gp_Dir D = vdir.Reversed(); - return gp_Ax1(loc, D); -} - -inline void gp_Ax1::Rotate (const gp_Ax1& A1, const Standard_Real Ang) -{ - loc.Rotate(A1, Ang); - vdir.Rotate(A1 , Ang); -} - -inline gp_Ax1 gp_Ax1::Rotated (const gp_Ax1& A1, - const Standard_Real Ang) const -{ - gp_Ax1 A = *this; - A.Rotate (A1, Ang); - return A; -} - -inline void gp_Ax1::Scale (const gp_Pnt& P, - const Standard_Real S) -{ - loc.Scale (P, S); - if (S < 0.0) vdir.Reverse(); -} - -inline gp_Ax1 gp_Ax1::Scaled (const gp_Pnt& P, - const Standard_Real S) const -{ - gp_Ax1 A1 = *this; - A1.Scale (P, S); - return A1; -} - -inline void gp_Ax1::Transform (const gp_Trsf& T) -{ - loc.Transform(T); - vdir.Transform(T); -} - -inline gp_Ax1 gp_Ax1::Transformed (const gp_Trsf& T) const -{ - gp_Ax1 A1 = *this; - A1.Transform (T); - return A1; -} - -inline void gp_Ax1::Translate (const gp_Vec& V) -{ loc.Translate (V); } - -inline gp_Ax1 gp_Ax1::Translated (const gp_Vec& V) const -{ - gp_Ax1 A1 = *this; - (A1.loc).Translate (V); - return A1; -} - -inline void gp_Ax1::Translate (const gp_Pnt& P1, - const gp_Pnt& P2) -{ - loc.Translate (P1, P2); -} - -inline gp_Ax1 gp_Ax1::Translated (const gp_Pnt& P1, - const gp_Pnt& P2) const -{ - gp_Ax1 A1 = *this; - (A1.loc).Translate (P1, P2); - return A1; -} - diff --git a/src/gp/gp_Ax2.cxx b/src/gp/gp_Ax2.cxx index 4a1ed084c8..b1747c521e 100644 --- a/src/gp/gp_Ax2.cxx +++ b/src/gp/gp_Ax2.cxx @@ -19,10 +19,10 @@ #define No_Standard_OutOfRange +#include #include #include -#include #include #include #include diff --git a/src/gp/gp_Ax2.hxx b/src/gp/gp_Ax2.hxx index 43536b47de..d768bda507 100644 --- a/src/gp/gp_Ax2.hxx +++ b/src/gp/gp_Ax2.hxx @@ -15,23 +15,15 @@ #ifndef _gp_Ax2_HeaderFile #define _gp_Ax2_HeaderFile -#include -#include -#include - #include #include -#include -#include +#include + class Standard_ConstructionError; class gp_Pnt; -class gp_Dir; -class gp_Ax1; class gp_Trsf; class gp_Vec; - - //! Describes a right-handed coordinate system in 3D space. //! A coordinate system is defined by: //! - its origin (also referred to as its "Location point"), and @@ -66,11 +58,11 @@ public: DEFINE_STANDARD_ALLOC - //! Creates an object corresponding to the reference //! coordinate system (OXYZ). - gp_Ax2(); - + gp_Ax2() : vydir(0.,1.,0.) + // vxdir(1.,0.,0.) use default ctor of gp_Dir, as it creates the same dir(1,0,0) + {} //! Creates an axis placement with an origin P such that: //! - N is the Direction, and @@ -78,14 +70,20 @@ public: //! defined by the vectors (N, Vx): "X //! Direction" = (N ^ Vx) ^ N, //! Exception: raises ConstructionError if N and Vx are parallel (same or opposite orientation). - gp_Ax2(const gp_Pnt& P, const gp_Dir& N, const gp_Dir& Vx); - + gp_Ax2 (const gp_Pnt& P, const gp_Dir& N, const gp_Dir& Vx) + : axis (P, N), + vydir (N), + vxdir (N) + { + vxdir.CrossCross(Vx, N); + vydir.Cross(vxdir); + } //! Creates - a coordinate system with an origin P, where V //! gives the "main Direction" (here, "X Direction" and "Y //! Direction" are defined automatically). Standard_EXPORT gp_Ax2(const gp_Pnt& P, const gp_Dir& V); - + //! Assigns the origin and "main Direction" of the axis A1 to //! this coordinate system, then recomputes its "X Direction" and "Y Direction". //! Note: The new "X Direction" is computed as follows: @@ -95,7 +93,6 @@ public: //! Standard_ConstructionError if A1 is parallel to the "X //! Direction" of this coordinate system. void SetAxis (const gp_Ax1& A1); - //! Changes the "main Direction" of this coordinate system, //! then recomputes its "X Direction" and "Y Direction". @@ -105,11 +102,9 @@ public: //! Standard_ConstructionError if V is parallel to the "X //! Direction" of this coordinate system. void SetDirection (const gp_Dir& V); - //! Changes the "Location" point (origin) of . - void SetLocation (const gp_Pnt& P); - + void SetLocation (const gp_Pnt& theP) { axis.SetLocation (theP); } //! Changes the "Xdirection" of . The main direction //! "Direction" is not modified, the "Ydirection" is modified. @@ -118,8 +113,11 @@ public: //! Exceptions //! Standard_ConstructionError if Vx or Vy is parallel to //! the "main Direction" of this coordinate system. - void SetXDirection (const gp_Dir& Vx); - + void SetXDirection (const gp_Dir& theVx) + { + vxdir = axis.Direction().CrossCrossed (theVx, axis.Direction()); + vydir = axis.Direction().Crossed (vxdir); + } //! Changes the "Ydirection" of . The main direction is not //! modified but the "Xdirection" is changed. @@ -129,45 +127,41 @@ public: //! Exceptions //! Standard_ConstructionError if Vx or Vy is parallel to //! the "main Direction" of this coordinate system. - void SetYDirection (const gp_Dir& Vy); - + void SetYDirection (const gp_Dir& theVy) + { + vxdir = theVy.Crossed (axis.Direction()); + vydir = (axis.Direction()).Crossed (vxdir); + } //! Computes the angular value, in radians, between the main direction of - //! and the main direction of . Returns the angle + //! and the main direction of . Returns the angle //! between 0 and PI in radians. - Standard_Real Angle (const gp_Ax2& Other) const; - + Standard_Real Angle (const gp_Ax2& theOther) const { return axis.Angle (theOther.axis); } //! Returns the main axis of . It is the "Location" point //! and the main "Direction". - const gp_Ax1& Axis() const; - + const gp_Ax1& Axis() const { return axis; } //! Returns the main direction of . - const gp_Dir& Direction() const; - + const gp_Dir& Direction() const { return axis.Direction(); } //! Returns the "Location" point (origin) of . - const gp_Pnt& Location() const; - + const gp_Pnt& Location() const { return axis.Location(); } //! Returns the "XDirection" of . - const gp_Dir& XDirection() const; - + const gp_Dir& XDirection() const { return vxdir; } //! Returns the "YDirection" of . - const gp_Dir& YDirection() const; - + const gp_Dir& YDirection() const { return vydir; } + Standard_Boolean IsCoplanar (const gp_Ax2& Other, const Standard_Real LinearTolerance, const Standard_Real AngularTolerance) const; - //! Returns True if //! . the distance between and the "Location" point of A1 //! is lower of equal to LinearTolerance and //! . the main direction of and the direction of A1 are normal. //! Note: the tolerance criterion for angular equality is given by AngularTolerance. - Standard_Boolean IsCoplanar (const gp_Ax1& A1, const Standard_Real LinearTolerance, const Standard_Real AngularTolerance) const; - + Standard_Boolean IsCoplanar (const gp_Ax1& A1, const Standard_Real LinearTolerance, const Standard_Real AngularTolerance) const; //! Performs a symmetrical transformation of this coordinate //! system with respect to: @@ -185,7 +179,6 @@ public: //! This maintains the right-handed property of the //! coordinate system. Standard_EXPORT void Mirror (const gp_Pnt& P); - //! Performs a symmetrical transformation of this coordinate //! system with respect to: @@ -203,7 +196,6 @@ public: //! This maintains the right-handed property of the //! coordinate system. Standard_NODISCARD Standard_EXPORT gp_Ax2 Mirrored (const gp_Pnt& P) const; - //! Performs a symmetrical transformation of this coordinate //! system with respect to: @@ -221,7 +213,6 @@ public: //! This maintains the right-handed property of the //! coordinate system. Standard_EXPORT void Mirror (const gp_Ax1& A1); - //! Performs a symmetrical transformation of this coordinate //! system with respect to: @@ -239,7 +230,6 @@ public: //! This maintains the right-handed property of the //! coordinate system. Standard_NODISCARD Standard_EXPORT gp_Ax2 Mirrored (const gp_Ax1& A1) const; - //! Performs a symmetrical transformation of this coordinate //! system with respect to: @@ -258,7 +248,6 @@ public: //! This maintains the right-handed property of the //! coordinate system. Standard_EXPORT void Mirror (const gp_Ax2& A2); - //! Performs a symmetrical transformation of this coordinate //! system with respect to: @@ -277,17 +266,37 @@ public: //! This maintains the right-handed property of the //! coordinate system. Standard_NODISCARD Standard_EXPORT gp_Ax2 Mirrored (const gp_Ax2& A2) const; - - void Rotate (const gp_Ax1& A1, const Standard_Real Ang); - - //! Rotates an axis placement. is the axis of the - //! rotation . Ang is the angular value of the rotation - //! in radians. - Standard_NODISCARD gp_Ax2 Rotated (const gp_Ax1& A1, const Standard_Real Ang) const; - - void Scale (const gp_Pnt& P, const Standard_Real S); - + void Rotate (const gp_Ax1& theA1, const Standard_Real theAng) + { + gp_Pnt aTemp = axis.Location(); + aTemp.Rotate (theA1, theAng); + axis.SetLocation (aTemp); + vxdir.Rotate (theA1, theAng); + vydir.Rotate (theA1, theAng); + axis.SetDirection (vxdir.Crossed (vydir)); + } + + //! Rotates an axis placement. is the axis of the rotation. + //! theAng is the angular value of the rotation in radians. + Standard_NODISCARD gp_Ax2 Rotated (const gp_Ax1& theA1, const Standard_Real theAng) const + { + gp_Ax2 aTemp = *this; + aTemp.Rotate (theA1, theAng); + return aTemp; + } + + void Scale (const gp_Pnt& theP, const Standard_Real theS) + { + gp_Pnt aTemp = axis.Location(); + aTemp.Scale (theP, theS); + axis.SetLocation (aTemp); + if (theS < 0.0) + { + vxdir.Reverse(); + vydir.Reverse(); + } + } //! Applies a scaling transformation on the axis placement. //! The "Location" point of the axisplacement is modified. @@ -296,32 +305,54 @@ public: //! . the main direction of the axis placement is not changed. //! . The "XDirection" and the "YDirection" are reversed. //! So the axis placement stay right handed. - Standard_NODISCARD gp_Ax2 Scaled (const gp_Pnt& P, const Standard_Real S) const; - - void Transform (const gp_Trsf& T); - + Standard_NODISCARD gp_Ax2 Scaled (const gp_Pnt& theP, const Standard_Real theS) const + { + gp_Ax2 aTemp = *this; + aTemp.Scale (theP, theS); + return aTemp; + } + + void Transform (const gp_Trsf& theT) + { + gp_Pnt aTemp = axis.Location(); + aTemp.Transform (theT); + axis.SetLocation (aTemp); + vxdir.Transform (theT); + vydir.Transform (theT); + axis.SetDirection (vxdir.Crossed (vydir)); + } //! Transforms an axis placement with a Trsf. - //! The "Location" point, the "XDirection" and the - //! "YDirection" are transformed with T. The resulting - //! main "Direction" of is the cross product between + //! The "Location" point, the "XDirection" and the "YDirection" are transformed with theT. + //! The resulting main "Direction" of is the cross product between //! the "XDirection" and the "YDirection" after transformation. - Standard_NODISCARD gp_Ax2 Transformed (const gp_Trsf& T) const; - - void Translate (const gp_Vec& V); + Standard_NODISCARD gp_Ax2 Transformed (const gp_Trsf& theT) const + { + gp_Ax2 aTemp = *this; + aTemp.Transform (theT); + return aTemp; + } + void Translate (const gp_Vec& theV) { axis.Translate (theV); } - //! Translates an axis plaxement in the direction of the vector - //! . The magnitude of the translation is the vector's magnitude. - Standard_NODISCARD gp_Ax2 Translated (const gp_Vec& V) const; - - void Translate (const gp_Pnt& P1, const gp_Pnt& P2); - + //! Translates an axis plaxement in the direction of the vector . + //! The magnitude of the translation is the vector's magnitude. + Standard_NODISCARD gp_Ax2 Translated (const gp_Vec& theV) const + { + gp_Ax2 aTemp = *this; + aTemp.Translate (theV); + return aTemp; + } - //! Translates an axis placement from the point to the - //! point . - Standard_NODISCARD gp_Ax2 Translated (const gp_Pnt& P1, const gp_Pnt& P2) const; + void Translate (const gp_Pnt& theP1, const gp_Pnt& theP2) { axis.Translate (theP1, theP2); } + //! Translates an axis placement from the point to the point . + Standard_NODISCARD gp_Ax2 Translated (const gp_Pnt& theP1, const gp_Pnt& theP2) const + { + gp_Ax2 aTemp = *this; + aTemp.Translate (theP1, theP2); + return aTemp; + } //! Dumps the content of me into the stream Standard_EXPORT void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const; @@ -329,30 +360,114 @@ public: //! Inits the content of me from the stream Standard_EXPORT Standard_Boolean InitFromJson (const Standard_SStream& theSStream, Standard_Integer& theStreamPos); - - -protected: - - - - - private: - - gp_Ax1 axis; gp_Dir vydir; gp_Dir vxdir; - }; +// ======================================================================= +// function : SetAxis +// purpose : +// ======================================================================= +inline void gp_Ax2::SetAxis (const gp_Ax1& theA1) +{ + Standard_Real a = theA1.Direction() * vxdir; + if (Abs(Abs(a) - 1.) <= Precision::Angular()) + { + if (a > 0.) + { + vxdir = vydir; + vydir = axis.Direction(); + axis = theA1; + } + else + { + vxdir = axis.Direction(); + axis = theA1; + } + } + else + { + axis = theA1; + vxdir = axis.Direction().CrossCrossed (vxdir, axis.Direction()); + vydir = axis.Direction().Crossed (vxdir); + } +} -#include - - +// ======================================================================= +// function : SetDirection +// purpose : +// ======================================================================= +inline void gp_Ax2::SetDirection (const gp_Dir& theV) +{ + Standard_Real a = theV * vxdir; + if (Abs(Abs(a) - 1.) <= Precision::Angular()) + { + if(a > 0.) + { + vxdir = vydir; + vydir = axis.Direction(); + axis.SetDirection (theV); + } + else + { + vxdir = axis.Direction(); + axis.SetDirection (theV); + } + } + else + { + axis.SetDirection (theV); + vxdir = theV.CrossCrossed (vxdir, theV); + vydir = theV.Crossed (vxdir); + } +} +// ======================================================================= +// function : IsCoplanar +// purpose : +// ======================================================================= +inline Standard_Boolean gp_Ax2::IsCoplanar (const gp_Ax2& theOther, + const Standard_Real theLinearTolerance, + const Standard_Real theAngularTolerance) const +{ + const gp_Dir& DD = axis.Direction(); + const gp_Pnt& PP = axis.Location(); + const gp_Pnt& OP = theOther.axis.Location(); + Standard_Real D1 = (DD.X() * (OP.X() - PP.X()) + + DD.Y() * (OP.Y() - PP.Y()) + + DD.Z() * (OP.Z() - PP.Z())); + if (D1 < 0) + { + D1 = -D1; + } + return D1 <= theLinearTolerance + && axis.IsParallel (theOther.axis, theAngularTolerance); +} +// ======================================================================= +// function : IsCoplanar +// purpose : +// ======================================================================= +inline Standard_Boolean gp_Ax2::IsCoplanar (const gp_Ax1& theA, + const Standard_Real theLinearTolerance, + const Standard_Real theAngularTolerance) const +{ + const gp_Dir& DD = axis.Direction(); + const gp_Pnt& PP = axis.Location(); + const gp_Pnt& AP = theA.Location(); + Standard_Real D1 = (DD.X() * (AP.X() - PP.X()) + + DD.Y() * (AP.Y() - PP.Y()) + + DD.Z() * (AP.Z() - PP.Z())); + if (D1 < 0) + { + D1 = -D1; + } + return D1 <= theLinearTolerance + && axis.IsNormal (theA, theAngularTolerance); +} #endif // _gp_Ax2_HeaderFile diff --git a/src/gp/gp_Ax2.lxx b/src/gp/gp_Ax2.lxx deleted file mode 100644 index 3e94b37be6..0000000000 --- a/src/gp/gp_Ax2.lxx +++ /dev/null @@ -1,212 +0,0 @@ -// Copyright (c) 1996-1999 Matra Datavision -// Copyright (c) 1999-2014 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -#include - -inline gp_Ax2::gp_Ax2() - : - vydir(0.,1.,0.) - // vxdir(1.,0.,0.) use default ctor of gp_Dir, as it creates the same dir(1,0,0) -{ } - -inline gp_Ax2::gp_Ax2(const gp_Pnt& P, - const gp_Dir& N, - const gp_Dir& Vx) : axis(P, N), vydir(N), vxdir(N) -{ - vxdir.CrossCross(Vx, N); - vydir.Cross(vxdir); -} - -inline void gp_Ax2::SetAxis (const gp_Ax1& A1) -{ - Standard_Real a = A1.Direction() * vxdir; - if(Abs(Abs(a) - 1.) <= Precision::Angular()) { - if(a > 0.) { - vxdir = vydir; - vydir = axis.Direction(); - axis = A1; - } - else { - vxdir = axis.Direction(); - axis = A1; - } - } - else { - axis = A1; - vxdir = axis.Direction().CrossCrossed (vxdir, axis.Direction()); - vydir = axis.Direction().Crossed (vxdir); - } -} - -inline void gp_Ax2::SetDirection (const gp_Dir& V) -{ - Standard_Real a = V * vxdir; - if(Abs(Abs(a) - 1.) <= Precision::Angular()) { - if(a > 0.) { - vxdir = vydir; - vydir = axis.Direction(); - axis.SetDirection (V); - } - else { - vxdir = axis.Direction(); - axis.SetDirection (V); - } - } - else { - axis.SetDirection (V); - vxdir = V.CrossCrossed (vxdir, V); - vydir = V.Crossed (vxdir); - } -} - -inline void gp_Ax2::SetLocation (const gp_Pnt& P) -{ axis.SetLocation(P); } - -inline void gp_Ax2::SetXDirection (const gp_Dir& Vx) -{ - vxdir = axis.Direction().CrossCrossed (Vx, axis.Direction()); - vydir = axis.Direction().Crossed (vxdir); -} - -inline void gp_Ax2::SetYDirection (const gp_Dir& Vy) -{ - vxdir = Vy.Crossed (axis.Direction()); - vydir = (axis.Direction()).Crossed (vxdir); -} - -inline Standard_Real gp_Ax2::Angle (const gp_Ax2& Other) const -{ return axis.Angle (Other.axis); } - -inline const gp_Ax1& gp_Ax2::Axis () const -{ return axis; } - -inline const gp_Dir& gp_Ax2::Direction () const -{ return axis.Direction(); } - -inline const gp_Pnt& gp_Ax2::Location () const -{ return axis.Location(); } - -inline const gp_Dir& gp_Ax2::XDirection () const -{ return vxdir; } - -inline const gp_Dir& gp_Ax2::YDirection () const -{ return vydir; } - -inline Standard_Boolean gp_Ax2::IsCoplanar -(const gp_Ax2& Other, - const Standard_Real LinearTolerance, - const Standard_Real AngularTolerance) const -{ - const gp_Dir& DD = axis.Direction(); - const gp_Pnt& PP = axis.Location (); - const gp_Pnt& OP = Other.axis.Location (); - Standard_Real D1 = (DD.X() * (OP.X() - PP.X()) + - DD.Y() * (OP.Y() - PP.Y()) + - DD.Z() * (OP.Z() - PP.Z())); - if (D1 < 0 ) D1 = - D1; - return (D1 <= LinearTolerance && - axis.IsParallel (Other.axis, AngularTolerance)); -} - -inline Standard_Boolean gp_Ax2::IsCoplanar -(const gp_Ax1& A, - const Standard_Real LinearTolerance, - const Standard_Real AngularTolerance) const -{ - const gp_Dir& DD = axis.Direction(); - const gp_Pnt& PP = axis.Location (); - const gp_Pnt& AP = A .Location (); - Standard_Real D1 = (DD.X() * (AP.X() - PP.X()) + - DD.Y() * (AP.Y() - PP.Y()) + - DD.Z() * (AP.Z() - PP.Z())); - if (D1 < 0) D1 = - D1; - return (D1 <= LinearTolerance && - axis.IsNormal (A, AngularTolerance)); -} - -inline void gp_Ax2::Rotate(const gp_Ax1& A1, const Standard_Real Ang) -{ - gp_Pnt Temp = axis.Location(); - Temp.Rotate (A1, Ang); - axis.SetLocation (Temp); - vxdir.Rotate (A1, Ang); - vydir.Rotate (A1, Ang); - axis.SetDirection (vxdir.Crossed (vydir)); -} - -inline gp_Ax2 gp_Ax2::Rotated(const gp_Ax1& A1, - const Standard_Real Ang) const -{ - gp_Ax2 Temp = *this; - Temp.Rotate (A1, Ang); - return Temp; -} - -inline void gp_Ax2::Scale (const gp_Pnt& P, const Standard_Real S) -{ - gp_Pnt Temp = axis.Location(); - Temp.Scale (P, S); - axis.SetLocation (Temp); - if (S < 0.0) { - vxdir.Reverse (); - vydir.Reverse (); - } -} - -inline gp_Ax2 gp_Ax2::Scaled(const gp_Pnt& P, - const Standard_Real S) const -{ - gp_Ax2 Temp = *this; - Temp.Scale (P, S); - return Temp; -} - -inline void gp_Ax2::Transform (const gp_Trsf& T) -{ - gp_Pnt Temp = axis.Location(); - Temp.Transform (T); - axis.SetLocation (Temp); - vxdir.Transform (T); - vydir.Transform (T); - axis.SetDirection (vxdir.Crossed (vydir)); -} - -inline gp_Ax2 gp_Ax2::Transformed(const gp_Trsf& T) const -{ - gp_Ax2 Temp = *this; - Temp.Transform (T); - return Temp; -} - -inline void gp_Ax2::Translate (const gp_Vec& V) -{ axis.Translate (V); } - -inline gp_Ax2 gp_Ax2::Translated(const gp_Vec& V) const -{ - gp_Ax2 Temp = *this; - Temp.Translate (V); - return Temp; -} - -inline void gp_Ax2::Translate (const gp_Pnt& P1, const gp_Pnt& P2) -{ axis.Translate (P1, P2); } - -inline gp_Ax2 gp_Ax2::Translated (const gp_Pnt& P1, - const gp_Pnt& P2) const -{ - gp_Ax2 Temp = *this; - Temp.Translate (P1, P2); - return Temp; -} - diff --git a/src/gp/gp_Ax22d.cxx b/src/gp/gp_Ax22d.cxx index fc8b27f480..68ce5642ee 100644 --- a/src/gp/gp_Ax22d.cxx +++ b/src/gp/gp_Ax22d.cxx @@ -17,8 +17,9 @@ // LPA, JCV 07/92 passage sur C1. // JCV 07/92 Introduction de la method Dump -#include #include + +#include #include #include #include diff --git a/src/gp/gp_Ax22d.hxx b/src/gp/gp_Ax22d.hxx index 5fdc7076aa..53a3933823 100644 --- a/src/gp/gp_Ax22d.hxx +++ b/src/gp/gp_Ax22d.hxx @@ -15,23 +15,12 @@ #ifndef _gp_Ax22d_HeaderFile #define _gp_Ax22d_HeaderFile -#include -#include -#include - -#include -#include -#include #include -#include -class Standard_ConstructionError; -class gp_Pnt2d; -class gp_Dir2d; -class gp_Ax2d; -class gp_Trsf2d; -class gp_Vec2d; - - +#include +#include +#include +#include +#include //! Describes a coordinate system in a plane (2D space). //! A coordinate system is defined by: @@ -56,106 +45,138 @@ public: DEFINE_STANDARD_ALLOC - //! Creates an object representing the reference //! coordinate system (OXY). - gp_Ax22d(); - + gp_Ax22d() : vydir (0., 1.) + // vxdir(1.,0.) use default ctor of gp_Dir2d, as it creates the same dir(1, 0) + {} - //! Creates a coordinate system with origin P and where: - //! - Vx is the "X Direction", and - //! - the "Y Direction" is orthogonal to Vx and - //! oriented so that the cross products Vx^"Y - //! Direction" and Vx^Vy have the same sign. - //! Raises ConstructionError if Vx and Vy are parallel (same or opposite orientation). - gp_Ax22d(const gp_Pnt2d& P, const gp_Dir2d& Vx, const gp_Dir2d& Vy); - + //! Creates a coordinate system with origin theP and where: + //! - theVx is the "X Direction", and + //! - the "Y Direction" is orthogonal to theVx and + //! oriented so that the cross products theVx^"Y + //! Direction" and theVx^theVy have the same sign. + //! Raises ConstructionError if theVx and theVy are parallel (same or opposite orientation). + gp_Ax22d (const gp_Pnt2d& theP, const gp_Dir2d& theVx, const gp_Dir2d& theVy) + : point (theP), + vydir (theVy), + vxdir (theVx) + { + Standard_Real aValue = theVx.Crossed (theVy); + if (aValue >= 0.0) + { + vydir.SetCoord (-vxdir.Y(), vxdir.X()); + } + else + { + vydir.SetCoord (vxdir.Y(), -vxdir.X()); + } + } - //! Creates - a coordinate system with origin P and "X Direction" - //! V, which is: - //! - right-handed if Sense is true (default value), or - //! - left-handed if Sense is false - gp_Ax22d(const gp_Pnt2d& P, const gp_Dir2d& V, const Standard_Boolean Sense = Standard_True); - + //! Creates - a coordinate system with origin theP and "X Direction" + //! theV, which is: + //! - right-handed if theIsSense is true (default value), or + //! - left-handed if theIsSense is false + gp_Ax22d (const gp_Pnt2d& theP, const gp_Dir2d& theV, const Standard_Boolean theIsSense = Standard_True) + : point (theP), + vxdir (theV) + { + if (theIsSense) + { + vydir.SetCoord (-theV.Y(), theV.X()); + } + else + { + vydir.SetCoord (theV.Y(), -theV.X()); + } + } //! Creates - a coordinate system where its origin is the origin of - //! A and its "X Direction" is the unit vector of A, which is: - //! - right-handed if Sense is true (default value), or - //! - left-handed if Sense is false. - gp_Ax22d(const gp_Ax2d& A, const Standard_Boolean Sense = Standard_True); - + //! theA and its "X Direction" is the unit vector of theA, which is: + //! - right-handed if theIsSense is true (default value), or + //! - left-handed if theIsSense is false. + gp_Ax22d (const gp_Ax2d& theA, const Standard_Boolean theIsSense = Standard_True) + : point (theA.Location()), + vxdir (theA.Direction()) + { + if (theIsSense) + { + vydir.SetCoord (-vxdir.Y(), vxdir.X()); + } + else + { + vydir.SetCoord (vxdir.Y(), -vxdir.X()); + } + } //! Assigns the origin and the two unit vectors of the - //! coordinate system A1 to this coordinate system. - void SetAxis (const gp_Ax22d& A1); - + //! coordinate system theA1 to this coordinate system. + void SetAxis (const gp_Ax22d& theA1) + { + point = theA1.Location(); + vxdir = theA1.XDirection(); + vydir = theA1.YDirection(); + } //! Changes the XAxis and YAxis ("Location" point and "Direction") //! of . //! The "YDirection" is recomputed in the same sense as before. - void SetXAxis (const gp_Ax2d& A1); - + void SetXAxis (const gp_Ax2d& theA1); + //! Changes the XAxis and YAxis ("Location" point and "Direction") of . //! The "XDirection" is recomputed in the same sense as before. - void SetYAxis (const gp_Ax2d& A1); - + void SetYAxis (const gp_Ax2d& theA1); //! Changes the "Location" point (origin) of . - void SetLocation (const gp_Pnt2d& P); - + void SetLocation (const gp_Pnt2d& theP) { point = theP; } - //! Assigns Vx to the "X Direction" of + //! Assigns theVx to the "X Direction" of //! this coordinate system. The other unit vector of this - //! coordinate system is recomputed, normal to Vx , + //! coordinate system is recomputed, normal to theVx , //! without modifying the orientation (right-handed or //! left-handed) of this coordinate system. - void SetXDirection (const gp_Dir2d& Vx); - - //! Assignsr Vy to the "Y Direction" of + void SetXDirection (const gp_Dir2d& theVx); + + //! Assignsr theVy to the "Y Direction" of //! this coordinate system. The other unit vector of this - //! coordinate system is recomputed, normal to Vy, + //! coordinate system is recomputed, normal to theVy, //! without modifying the orientation (right-handed or //! left-handed) of this coordinate system. - void SetYDirection (const gp_Dir2d& Vy); - + void SetYDirection (const gp_Dir2d& theVy); + //! Returns an axis, for which //! - the origin is that of this coordinate system, and //! - the unit vector is either the "X Direction" of this coordinate system. //! Note: the result is the "X Axis" of this coordinate system. - gp_Ax2d XAxis() const; - + gp_Ax2d XAxis() const { return gp_Ax2d (point, vxdir); } + //! Returns an axis, for which //! - the origin is that of this coordinate system, and //! - the unit vector is either the "Y Direction" of this coordinate system. //! Note: the result is the "Y Axis" of this coordinate system. - gp_Ax2d YAxis() const; - + gp_Ax2d YAxis() const { return gp_Ax2d (point, vydir); } //! Returns the "Location" point (origin) of . - const gp_Pnt2d& Location() const; - + const gp_Pnt2d& Location() const { return point; } //! Returns the "XDirection" of . - const gp_Dir2d& XDirection() const; - + const gp_Dir2d& XDirection() const { return vxdir; } //! Returns the "YDirection" of . - const gp_Dir2d& YDirection() const; - - Standard_EXPORT void Mirror (const gp_Pnt2d& P); - + const gp_Dir2d& YDirection() const { return vydir; } + + Standard_EXPORT void Mirror (const gp_Pnt2d& theP); //! Performs the symmetrical transformation of an axis - //! placement with respect to the point P which is the + //! placement with respect to the point theP which is the //! center of the symmetry. //! Warnings : //! The main direction of the axis placement is not changed. //! The "XDirection" and the "YDirection" are reversed. //! So the axis placement stay right handed. - Standard_NODISCARD Standard_EXPORT gp_Ax22d Mirrored (const gp_Pnt2d& P) const; - - Standard_EXPORT void Mirror (const gp_Ax2d& A); - + Standard_NODISCARD Standard_EXPORT gp_Ax22d Mirrored (const gp_Pnt2d& theP) const; + + Standard_EXPORT void Mirror (const gp_Ax2d& theA); //! Performs the symmetrical transformation of an axis //! placement with respect to an axis placement which @@ -164,80 +185,197 @@ public: //! point, on the "XDirection" and "YDirection". //! The resulting main "Direction" is the cross product between //! the "XDirection" and the "YDirection" after transformation. - Standard_NODISCARD Standard_EXPORT gp_Ax22d Mirrored (const gp_Ax2d& A) const; - - void Rotate (const gp_Pnt2d& P, const Standard_Real Ang); - + Standard_NODISCARD Standard_EXPORT gp_Ax22d Mirrored (const gp_Ax2d& theA) const; - //! Rotates an axis placement. is the axis of the - //! rotation . Ang is the angular value of the rotation + void Rotate (const gp_Pnt2d& theP, const Standard_Real theAng); + + //! Rotates an axis placement. is the axis of the + //! rotation . theAng is the angular value of the rotation //! in radians. - Standard_NODISCARD gp_Ax22d Rotated (const gp_Pnt2d& P, const Standard_Real Ang) const; - - void Scale (const gp_Pnt2d& P, const Standard_Real S); - + Standard_NODISCARD gp_Ax22d Rotated (const gp_Pnt2d& theP, const Standard_Real theAng) const + { + gp_Ax22d aTemp = *this; + aTemp.Rotate (theP, theAng); + return aTemp; + } + + void Scale (const gp_Pnt2d& theP, const Standard_Real theS); //! Applies a scaling transformation on the axis placement. //! The "Location" point of the axisplacement is modified. //! Warnings : - //! If the scale is negative : + //! If the scale is negative : //! . the main direction of the axis placement is not changed. //! . The "XDirection" and the "YDirection" are reversed. //! So the axis placement stay right handed. - Standard_NODISCARD gp_Ax22d Scaled (const gp_Pnt2d& P, const Standard_Real S) const; - - void Transform (const gp_Trsf2d& T); - + Standard_NODISCARD gp_Ax22d Scaled (const gp_Pnt2d& theP, const Standard_Real theS) const + { + gp_Ax22d aTemp = *this; + aTemp.Scale (theP, theS); + return aTemp; + } + + void Transform (const gp_Trsf2d& theT); //! Transforms an axis placement with a Trsf. //! The "Location" point, the "XDirection" and the - //! "YDirection" are transformed with T. The resulting + //! "YDirection" are transformed with theT. The resulting //! main "Direction" of is the cross product between //! the "XDirection" and the "YDirection" after transformation. - Standard_NODISCARD gp_Ax22d Transformed (const gp_Trsf2d& T) const; - - void Translate (const gp_Vec2d& V); - + Standard_NODISCARD gp_Ax22d Transformed (const gp_Trsf2d& theT) const + { + gp_Ax22d aTemp = *this; + aTemp.Transform (theT); + return aTemp; + } + + void Translate (const gp_Vec2d& theV) { point.Translate (theV); } //! Translates an axis plaxement in the direction of the vector - //! . The magnitude of the translation is the vector's magnitude. - Standard_NODISCARD gp_Ax22d Translated (const gp_Vec2d& V) const; - - void Translate (const gp_Pnt2d& P1, const gp_Pnt2d& P2); - + //! . The magnitude of the translation is the vector's magnitude. + Standard_NODISCARD gp_Ax22d Translated (const gp_Vec2d& theV) const + { + gp_Ax22d aTemp = *this; + aTemp.Translate (theV); + return aTemp; + } - //! Translates an axis placement from the point to the - //! point . - Standard_NODISCARD gp_Ax22d Translated (const gp_Pnt2d& P1, const gp_Pnt2d& P2) const; + void Translate (const gp_Pnt2d& theP1, const gp_Pnt2d& theP2) { point.Translate (theP1, theP2); } + + //! Translates an axis placement from the point to the + //! point . + Standard_NODISCARD gp_Ax22d Translated (const gp_Pnt2d& theP1, const gp_Pnt2d& theP2) const + { + gp_Ax22d aTemp = *this; + aTemp.Translate (theP1, theP2); + return aTemp; + } //! Dumps the content of me into the stream Standard_EXPORT void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const; - - - -protected: - - - - - private: - - gp_Pnt2d point; gp_Dir2d vydir; gp_Dir2d vxdir; - }; +// ======================================================================= +// function : SetDirection +// purpose : +// ======================================================================= +inline void gp_Ax22d::SetXAxis (const gp_Ax2d& theA1) +{ + Standard_Boolean isSign = (vxdir.Crossed(vydir)) >= 0.0; + point = theA1.Location (); + vxdir = theA1.Direction(); + if (isSign) + { + vydir.SetCoord (-vxdir.Y(), vxdir.X()); + } + else + { + vydir.SetCoord (vxdir.Y(), -vxdir.X()); + } +} -#include +// ======================================================================= +// function : SetDirection +// purpose : +// ======================================================================= +inline void gp_Ax22d::SetYAxis (const gp_Ax2d& theA1) +{ + Standard_Boolean isSign = (vxdir.Crossed(vydir)) >= 0.0; + point = theA1.Location (); + vydir = theA1.Direction(); + if (isSign) + { + vxdir.SetCoord (vydir.Y(), -vydir.X()); + } + else + { + vxdir.SetCoord (-vydir.Y(), vydir.X()); + } +} +// ======================================================================= +// function : SetXDirection +// purpose : +// ======================================================================= +inline void gp_Ax22d::SetXDirection (const gp_Dir2d& theVx) +{ + Standard_Boolean isSign = (vxdir.Crossed(vydir)) >= 0.0; + vxdir = theVx; + if (isSign) + { + vydir.SetCoord (-theVx.Y(), theVx.X()); + } + else + { + vydir.SetCoord (theVx.Y(), -theVx.X()); + } +} +// ======================================================================= +// function : SetYDirection +// purpose : +// ======================================================================= +inline void gp_Ax22d::SetYDirection (const gp_Dir2d& theVy) +{ + Standard_Boolean isSign = (vxdir.Crossed(vydir)) >= 0.0; + vydir = theVy; + if (isSign) + { + vxdir.SetCoord (theVy.Y(), -theVy.X()); + } + else + { + vxdir.SetCoord (-theVy.Y(), theVy.X()); + } +} +// ======================================================================= +// function : Rotate +// purpose : +// ======================================================================= +inline void gp_Ax22d::Rotate (const gp_Pnt2d& theP, const Standard_Real theAng) +{ + gp_Pnt2d aTemp = point; + aTemp.Rotate (theP, theAng); + point = aTemp; + vxdir.Rotate (theAng); + vydir.Rotate (theAng); +} +// ======================================================================= +// function : Scale +// purpose : +// ======================================================================= +inline void gp_Ax22d::Scale (const gp_Pnt2d& theP, const Standard_Real theS) +{ + gp_Pnt2d aTemp = point; + aTemp.Scale (theP, theS); + point = aTemp; + if (theS < 0.0) + { + vxdir.Reverse(); + vydir.Reverse(); + } +} + +// ======================================================================= +// function : Transform +// purpose : +// ======================================================================= +inline void gp_Ax22d::Transform (const gp_Trsf2d& theT) +{ + gp_Pnt2d aTemp = point; + aTemp.Transform (theT); + point = aTemp; + vxdir.Transform (theT); + vydir.Transform (theT); +} #endif // _gp_Ax22d_HeaderFile diff --git a/src/gp/gp_Ax22d.lxx b/src/gp/gp_Ax22d.lxx deleted file mode 100644 index 40d1597465..0000000000 --- a/src/gp/gp_Ax22d.lxx +++ /dev/null @@ -1,184 +0,0 @@ -// Copyright (c) 1996-1999 Matra Datavision -// Copyright (c) 1999-2014 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -inline gp_Ax22d::gp_Ax22d() - : - vydir(0.,1.) - // vxdir(1.,0.) use default ctor of gp_Dir2d, as it creates the same dir(1, 0) -{} - -inline gp_Ax22d::gp_Ax22d(const gp_Pnt2d& P , - const gp_Dir2d& Vx, - const gp_Dir2d& Vy) : - point(P), - vydir(Vy), - vxdir(Vx) -{ - Standard_Real value = Vx.Crossed(Vy); - if (value >= 0.0) vydir.SetCoord(-vxdir.Y(), vxdir.X()); - else vydir.SetCoord( vxdir.Y(),-vxdir.X()); -} - -inline gp_Ax22d::gp_Ax22d(const gp_Pnt2d& P , - const gp_Dir2d& Vx , - const Standard_Boolean Sense) : - point(P), - vxdir(Vx) -{ - if (Sense) vydir.SetCoord(-Vx.Y(), Vx.X()); - else vydir.SetCoord( Vx.Y(),-Vx.X()); -} - -inline gp_Ax22d::gp_Ax22d(const gp_Ax2d& A , - const Standard_Boolean Sense) : - point(A.Location()), - vxdir(A.Direction()) -{ - if (Sense) vydir.SetCoord(-vxdir.Y(), vxdir.X()); - else vydir.SetCoord( vxdir.Y(),-vxdir.X()); -} - -inline void gp_Ax22d::SetAxis(const gp_Ax22d& A1) -{ - point = A1.Location(); - vxdir = A1.XDirection(); - vydir = A1.YDirection(); -} - -inline void gp_Ax22d::SetXAxis (const gp_Ax2d& A1) -{ - Standard_Boolean sign = (vxdir.Crossed(vydir)) >= 0.0; - point = A1.Location (); - vxdir = A1.Direction(); - if (sign) vydir.SetCoord(-vxdir.Y(), vxdir.X()); - else vydir.SetCoord( vxdir.Y(),-vxdir.X()); -} - -inline void gp_Ax22d::SetYAxis (const gp_Ax2d& A1) -{ - Standard_Boolean sign = (vxdir.Crossed(vydir)) >= 0.0; - point = A1.Location (); - vydir = A1.Direction(); - if (sign) vxdir.SetCoord( vydir.Y(),-vydir.X()); - else vxdir.SetCoord(-vydir.Y(), vydir.X()); -} - -inline void gp_Ax22d::SetLocation (const gp_Pnt2d& P) -{ point = P; } - -inline void gp_Ax22d::SetXDirection (const gp_Dir2d& Vx) -{ - Standard_Boolean sign = (vxdir.Crossed(vydir)) >= 0.0; - vxdir = Vx; - if (sign) vydir.SetCoord(-Vx.Y(), Vx.X()); - else vydir.SetCoord( Vx.Y(),-Vx.X()); -} - -inline void gp_Ax22d::SetYDirection (const gp_Dir2d& Vy) -{ - Standard_Boolean sign = (vxdir.Crossed(vydir)) >= 0.0; - vydir = Vy; - if (sign) vxdir.SetCoord( Vy.Y(),-Vy.X()); - else vxdir.SetCoord(-Vy.Y(), Vy.X()); -} - -inline gp_Ax2d gp_Ax22d::XAxis () const -{ return gp_Ax2d(point, vxdir); } - -inline gp_Ax2d gp_Ax22d::YAxis () const -{ return gp_Ax2d(point, vydir); } - -inline const gp_Pnt2d& gp_Ax22d::Location () const -{ return point; } - -inline const gp_Dir2d& gp_Ax22d::XDirection () const -{ return vxdir; } - -inline const gp_Dir2d& gp_Ax22d::YDirection () const -{ return vydir; } - -inline void gp_Ax22d::Rotate (const gp_Pnt2d& P, - const Standard_Real Ang) -{ - gp_Pnt2d Temp = point; - Temp.Rotate (P,Ang); - point = Temp; - vxdir.Rotate (Ang); - vydir.Rotate (Ang); -} - -inline gp_Ax22d gp_Ax22d::Rotated(const gp_Pnt2d& P, - const Standard_Real Ang) const -{ - gp_Ax22d Temp = *this; - Temp.Rotate (P,Ang); - return Temp; -} - -inline void gp_Ax22d::Scale (const gp_Pnt2d& P, - const Standard_Real S) -{ - gp_Pnt2d Temp = point; - Temp.Scale (P, S); - point = Temp; - if (S < 0.0) { - vxdir.Reverse (); - vydir.Reverse (); - } -} - -inline gp_Ax22d gp_Ax22d::Scaled(const gp_Pnt2d& P, - const Standard_Real S) const -{ - gp_Ax22d Temp = *this; - Temp.Scale (P, S); - return Temp; -} - -inline void gp_Ax22d::Transform (const gp_Trsf2d& T) -{ - gp_Pnt2d Temp = point; - Temp.Transform (T); - point = Temp; - vxdir.Transform (T); - vydir.Transform (T); -} - -inline gp_Ax22d gp_Ax22d::Transformed(const gp_Trsf2d& T) const -{ - gp_Ax22d Temp = *this; - Temp.Transform (T); - return Temp; -} - -inline void gp_Ax22d::Translate (const gp_Vec2d& V) -{ point.Translate (V); } - -inline gp_Ax22d gp_Ax22d::Translated(const gp_Vec2d& V) const -{ - gp_Ax22d Temp = *this; - Temp.Translate (V); - return Temp; -} -inline void gp_Ax22d::Translate (const gp_Pnt2d& P1,const gp_Pnt2d& P2) -{ point.Translate (P1, P2); } - -inline gp_Ax22d gp_Ax22d::Translated (const gp_Pnt2d& P1, - const gp_Pnt2d& P2) const -{ - gp_Ax22d Temp = *this; - Temp.Translate (P1, P2); - return Temp; -} - diff --git a/src/gp/gp_Ax2d.cxx b/src/gp/gp_Ax2d.cxx index 6fb6bdfc7d..ae3902b74c 100644 --- a/src/gp/gp_Ax2d.cxx +++ b/src/gp/gp_Ax2d.cxx @@ -18,8 +18,8 @@ #define No_Standard_OutOfRange - #include + #include #include #include diff --git a/src/gp/gp_Ax2d.hxx b/src/gp/gp_Ax2d.hxx index a484c953d4..f034b383ad 100644 --- a/src/gp/gp_Ax2d.hxx +++ b/src/gp/gp_Ax2d.hxx @@ -15,21 +15,12 @@ #ifndef _gp_Ax2d_HeaderFile #define _gp_Ax2d_HeaderFile -#include -#include -#include - #include #include -#include -#include -class gp_Pnt2d; -class gp_Dir2d; + class gp_Trsf2d; class gp_Vec2d; - - //! Describes an axis in the plane (2D space). //! An axis is defined by: //! - its origin (also referred to as its "Location point"), and @@ -54,29 +45,30 @@ public: DEFINE_STANDARD_ALLOC - - //! Creates an axis object representing X axis of - //! the reference coordinate system. - gp_Ax2d(); - + //! Creates an axis object representing X axis of the reference co-ordinate system. + gp_Ax2d() : loc(0.,0.) + //vdir(1.,0.) use default ctor of gp_Dir2d, as it creates the same dir (1,0) + {} + + //! Creates an Ax2d. + //! is the "Location" point of the axis placement + //! and theV is the "Direction" of the axis placement. + gp_Ax2d (const gp_Pnt2d& theP, const gp_Dir2d& theV) + : loc (theP), + vdir (theV) + {} - //! Creates an Ax2d.

is the "Location" point of - //! the axis placement and V is the "Direction" of - //! the axis placement. - gp_Ax2d(const gp_Pnt2d& P, const gp_Dir2d& V); - //! Changes the "Location" point (origin) of . - void SetLocation (const gp_Pnt2d& Locat); - + void SetLocation (const gp_Pnt2d& theP) { loc = theP; } + //! Changes the direction of . - void SetDirection (const gp_Dir2d& V); - + void SetDirection (const gp_Dir2d& theV) { vdir = theV; } + //! Returns the origin of . - const gp_Pnt2d& Location() const; - + const gp_Pnt2d& Location() const { return loc; } + //! Returns the direction of . - const gp_Dir2d& Direction() const; - + const gp_Dir2d& Direction() const { return vdir; } //! Returns True if : //! . the angle between and is lower or equal @@ -87,114 +79,130 @@ public: //! or equal to LinearTolerance. Standard_EXPORT Standard_Boolean IsCoaxial (const gp_Ax2d& Other, const Standard_Real AngularTolerance, const Standard_Real LinearTolerance) const; - //! Returns true if this axis and the axis Other are normal to - //! each other. That is, if the angle between the two axes is equal to Pi/2 or -Pi/2. - //! Note: the tolerance criterion is given by AngularTolerance. - Standard_Boolean IsNormal (const gp_Ax2d& Other, const Standard_Real AngularTolerance) const; - - //! Returns true if this axis and the axis Other are parallel, - //! and have opposite orientations. That is, if the angle - //! between the two axes is equal to Pi or -Pi. - //! Note: the tolerance criterion is given by AngularTolerance. - Standard_Boolean IsOpposite (const gp_Ax2d& Other, const Standard_Real AngularTolerance) const; - - //! Returns true if this axis and the axis Other are parallel, - //! and have either the same or opposite orientations. That - //! is, if the angle between the two axes is equal to 0, Pi or -Pi. - //! Note: the tolerance criterion is given by AngularTolerance. - Standard_Boolean IsParallel (const gp_Ax2d& Other, const Standard_Real AngularTolerance) const; - + //! Returns true if this axis and the axis theOther are normal to each other. + //! That is, if the angle between the two axes is equal to Pi/2 or -Pi/2. + //! Note: the tolerance criterion is given by theAngularTolerance. + Standard_Boolean IsNormal (const gp_Ax2d& theOther, const Standard_Real theAngularTolerance) const + { + return vdir.IsNormal (theOther.vdir, theAngularTolerance); + } + + //! Returns true if this axis and the axis theOther are parallel, and have opposite orientations. + //! That is, if the angle between the two axes is equal to Pi or -Pi. + //! Note: the tolerance criterion is given by theAngularTolerance. + Standard_Boolean IsOpposite (const gp_Ax2d& theOther, const Standard_Real theAngularTolerance) const + { + return vdir.IsOpposite (theOther.vdir, theAngularTolerance); + } + + //! Returns true if this axis and the axis theOther are parallel, + //! and have either the same or opposite orientations. + //! That is, if the angle between the two axes is equal to 0, Pi or -Pi. + //! Note: the tolerance criterion is given by theAngularTolerance. + Standard_Boolean IsParallel (const gp_Ax2d& theOther, const Standard_Real theAngularTolerance) const + { + return vdir.IsParallel (theOther.vdir, theAngularTolerance); + } + + //! Computes the angle, in radians, between this axis and the axis theOther. + //! The value of the angle is between -Pi and Pi. + Standard_Real Angle (const gp_Ax2d& theOther) const { return vdir.Angle (theOther.vdir); } - //! Computes the angle, in radians, between this axis and - //! the axis Other. The value of the angle is between -Pi and Pi. - Standard_Real Angle (const gp_Ax2d& Other) const; - //! Reverses the direction of and assigns the result to this axis. - void Reverse(); - + void Reverse() { vdir.Reverse(); } + + //! Computes a new axis placement with a direction opposite to the direction of . + Standard_NODISCARD gp_Ax2d Reversed() const + { + gp_Ax2d aTemp = *this; + aTemp.Reverse(); + return aTemp; + } - //! Computes a new axis placement with a direction opposite to - //! the direction of . - Standard_NODISCARD gp_Ax2d Reversed() const; - Standard_EXPORT void Mirror (const gp_Pnt2d& P); - //! Performs the symmetrical transformation of an axis //! placement with respect to the point P which is the //! center of the symmetry. Standard_NODISCARD Standard_EXPORT gp_Ax2d Mirrored (const gp_Pnt2d& P) const; - + Standard_EXPORT void Mirror (const gp_Ax2d& A); - //! Performs the symmetrical transformation of an axis //! placement with respect to an axis placement which //! is the axis of the symmetry. Standard_NODISCARD Standard_EXPORT gp_Ax2d Mirrored (const gp_Ax2d& A) const; - - void Rotate (const gp_Pnt2d& P, const Standard_Real Ang); - - //! Rotates an axis placement.

is the center of the - //! rotation . Ang is the angular value of the rotation - //! in radians. - Standard_NODISCARD gp_Ax2d Rotated (const gp_Pnt2d& P, const Standard_Real Ang) const; - + void Rotate (const gp_Pnt2d& theP, const Standard_Real theAng) + { + loc.Rotate (theP, theAng); + vdir.Rotate (theAng); + } + + //! Rotates an axis placement. is the center of the rotation. + //! theAng is the angular value of the rotation in radians. + Standard_NODISCARD gp_Ax2d Rotated (const gp_Pnt2d& theP, const Standard_Real theAng) const + { + gp_Ax2d anA = *this; + anA.Rotate (theP, theAng); + return anA; + } + Standard_EXPORT void Scale (const gp_Pnt2d& P, const Standard_Real S); - //! Applies a scaling transformation on the axis placement. //! The "Location" point of the axisplacement is modified. //! The "Direction" is reversed if the scale is negative. - Standard_NODISCARD gp_Ax2d Scaled (const gp_Pnt2d& P, const Standard_Real S) const; - - void Transform (const gp_Trsf2d& T); - + Standard_NODISCARD gp_Ax2d Scaled (const gp_Pnt2d& theP, const Standard_Real theS) const + { + gp_Ax2d anA = *this; + anA.Scale (theP, theS); + return anA; + } + + void Transform (const gp_Trsf2d& theT) + { + loc .Transform (theT); + vdir.Transform (theT); + } + //! Transforms an axis placement with a Trsf. - Standard_NODISCARD gp_Ax2d Transformed (const gp_Trsf2d& T) const; - - void Translate (const gp_Vec2d& V); - + Standard_NODISCARD gp_Ax2d Transformed (const gp_Trsf2d& theT) const + { + gp_Ax2d anA = *this; + anA.Transform (theT); + return anA; + } - //! Translates an axis placement in the direction of the vector - //! . The magnitude of the translation is the vector's magnitude. - Standard_NODISCARD gp_Ax2d Translated (const gp_Vec2d& V) const; - - void Translate (const gp_Pnt2d& P1, const gp_Pnt2d& P2); - + void Translate (const gp_Vec2d& theV) { loc.Translate (theV); } - //! Translates an axis placement from the point to the - //! point . - Standard_NODISCARD gp_Ax2d Translated (const gp_Pnt2d& P1, const gp_Pnt2d& P2) const; + //! Translates an axis placement in the direction of the vector theV. + //! The magnitude of the translation is the vector's magnitude. + Standard_NODISCARD gp_Ax2d Translated (const gp_Vec2d& theV) const + { + gp_Ax2d anA = *this; + (anA.loc).Translate (theV); + return anA; + } + + void Translate (const gp_Pnt2d& theP1, const gp_Pnt2d& theP2) { loc.Translate (theP1, theP2); } + + //! Translates an axis placement from the point theP1 to the point theP2. + Standard_NODISCARD gp_Ax2d Translated (const gp_Pnt2d& theP1, const gp_Pnt2d& theP2) const + { + gp_Ax2d anA = *this; + (anA.loc).Translate (gp_Vec2d (theP1, theP2)); + return anA; + } //! Dumps the content of me into the stream Standard_EXPORT void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const; - - - -protected: - - - - - private: - - gp_Pnt2d loc; gp_Dir2d vdir; - }; - -#include - - - - - #endif // _gp_Ax2d_HeaderFile diff --git a/src/gp/gp_Ax2d.lxx b/src/gp/gp_Ax2d.lxx deleted file mode 100644 index 37048626a2..0000000000 --- a/src/gp/gp_Ax2d.lxx +++ /dev/null @@ -1,127 +0,0 @@ -// Copyright (c) 1995-1999 Matra Datavision -// Copyright (c) 1999-2014 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -// Modif jcv 08/01/1991 -// JCV, LPA 07/92 - -#include - -inline gp_Ax2d::gp_Ax2d() - : - loc(0.,0.) - //vdir(1.,0.) use default ctor of gp_Dir2d, as it creates the same dir (1,0) -{ } - -inline gp_Ax2d::gp_Ax2d (const gp_Pnt2d& P, - const gp_Dir2d& V) : loc(P), vdir(V) -{ } - -inline void gp_Ax2d::SetLocation(const gp_Pnt2d& P) -{ loc = P; } - -inline void gp_Ax2d::SetDirection(const gp_Dir2d& V) -{ vdir = V; } - -inline const gp_Pnt2d& gp_Ax2d::Location () const -{ return loc; } - -inline const gp_Dir2d& gp_Ax2d::Direction () const -{ return vdir; } - -inline Standard_Boolean gp_Ax2d::IsNormal -(const gp_Ax2d& Other, - const Standard_Real AngularTolerance) const -{ return vdir.IsNormal(Other.vdir, AngularTolerance); } - -inline Standard_Boolean gp_Ax2d::IsOpposite -(const gp_Ax2d& Other, - const Standard_Real AngularTolerance) const -{ return vdir.IsOpposite (Other.vdir, AngularTolerance); } - -inline Standard_Boolean gp_Ax2d::IsParallel -(const gp_Ax2d& Other, - const Standard_Real AngularTolerance) const -{ return vdir.IsParallel(Other.vdir, AngularTolerance); } - -inline Standard_Real gp_Ax2d::Angle (const gp_Ax2d& Other) const -{ return vdir.Angle (Other.vdir); } - -inline void gp_Ax2d::Reverse() -{ vdir.Reverse(); } - -inline gp_Ax2d gp_Ax2d::Reversed() const -{ - gp_Ax2d Temp = *this; - Temp.Reverse (); - return Temp; -} - -inline void gp_Ax2d::Rotate (const gp_Pnt2d& P, - const Standard_Real Ang) -{ - loc.Rotate (P, Ang); - vdir.Rotate (Ang); -} - -inline gp_Ax2d gp_Ax2d::Rotated (const gp_Pnt2d& P, - const Standard_Real Ang) const -{ - gp_Ax2d A = *this; - A.Rotate (P, Ang); - return A; -} - -inline gp_Ax2d gp_Ax2d::Scaled (const gp_Pnt2d& P, - const Standard_Real S) const -{ - gp_Ax2d A = *this; - A.Scale (P, S); - return A; -} - -inline void gp_Ax2d::Transform (const gp_Trsf2d& T) -{ - loc.Transform (T); - vdir.Transform (T); -} - -inline gp_Ax2d gp_Ax2d::Transformed (const gp_Trsf2d& T) const -{ - gp_Ax2d A = *this; - A.Transform (T); - return A; -} - -inline void gp_Ax2d::Translate (const gp_Vec2d& V) -{ loc.Translate (V); } - -inline gp_Ax2d gp_Ax2d::Translated (const gp_Vec2d& V) const -{ - gp_Ax2d A = *this; - (A.loc).Translate (V); - return A; -} - -inline void gp_Ax2d::Translate (const gp_Pnt2d& P1, - const gp_Pnt2d& P2) -{ loc.Translate (P1,P2); } - -inline gp_Ax2d gp_Ax2d::Translated (const gp_Pnt2d& P1, - const gp_Pnt2d& P2) const -{ - gp_Ax2d A = *this; - (A.loc).Translate( gp_Vec2d (P1, P2)); - return A; -} - diff --git a/src/gp/gp_Ax3.cxx b/src/gp/gp_Ax3.cxx index 6e8bd011ef..d02c31bc50 100644 --- a/src/gp/gp_Ax3.cxx +++ b/src/gp/gp_Ax3.cxx @@ -14,10 +14,10 @@ // Alternatively, this file may be used under the terms of Open CASCADE // commercial license or contractual agreement. +#include #include #include -#include #include #include #include diff --git a/src/gp/gp_Ax3.hxx b/src/gp/gp_Ax3.hxx index 80d2205eaf..d7f69a0831 100644 --- a/src/gp/gp_Ax3.hxx +++ b/src/gp/gp_Ax3.hxx @@ -17,22 +17,13 @@ #ifndef _gp_Ax3_HeaderFile #define _gp_Ax3_HeaderFile -#include -#include -#include - #include +#include #include -#include -#include -class Standard_ConstructionError; -class gp_Ax2; -class gp_Pnt; -class gp_Dir; -class gp_Ax1; -class gp_Trsf; -class gp_Vec; +#include +#include +class gp_Trsf; //! Describes a coordinate system in 3D space. Unlike a //! gp_Ax2 coordinate system, a gp_Ax3 can be @@ -74,94 +65,95 @@ public: DEFINE_STANDARD_ALLOC - //! Creates an object corresponding to the reference //! coordinate system (OXYZ). - gp_Ax3(); - + gp_Ax3() : vydir (0., 1., 0.) + // vxdir(1.,0.,0.) use default ctor of gp_Dir, as it creates the same dir(1,0,0) + {} + //! Creates a coordinate system from a right-handed //! coordinate system. - gp_Ax3(const gp_Ax2& A); - - //! Creates a right handed axis placement with the - //! "Location" point P and two directions, N gives the - //! "Direction" and Vx gives the "XDirection". - //! Raises ConstructionError if N and Vx are parallel (same or opposite orientation). - gp_Ax3(const gp_Pnt& P, const gp_Dir& N, const gp_Dir& Vx); - + gp_Ax3 (const gp_Ax2& theA); + + //! Creates a right handed axis placement with the + //! "Location" point theP and two directions, theN gives the + //! "Direction" and theVx gives the "XDirection". + //! Raises ConstructionError if theN and theVx are parallel (same or opposite orientation). + gp_Ax3 (const gp_Pnt& theP, const gp_Dir& theN, const gp_Dir& theVx) + : axis (theP, theN), + vydir(theN), + vxdir(theN) + { + vxdir.CrossCross (theVx, theN); + vydir.Cross (vxdir); + } + + //! Creates an axis placement with the "Location" point + //! and the normal direction . + Standard_EXPORT gp_Ax3 (const gp_Pnt& theP, const gp_Dir& theV); - //! Creates an axis placement with the "Location" point

- //! and the normal direction . - Standard_EXPORT gp_Ax3(const gp_Pnt& P, const gp_Dir& V); - //! Reverses the X direction of . - void XReverse(); - + void XReverse() { vxdir.Reverse(); } + //! Reverses the Y direction of . - void YReverse(); - + void YReverse() { vydir.Reverse(); } + //! Reverses the Z direction of . - void ZReverse(); - - //! Assigns the origin and "main Direction" of the axis A1 to + void ZReverse() { axis.Reverse(); } + + //! Assigns the origin and "main Direction" of the axis theA1 to //! this coordinate system, then recomputes its "X Direction" and "Y Direction". //! Note: //! - The new "X Direction" is computed as follows: //! new "X Direction" = V1 ^(previous "X Direction" ^ V) - //! where V is the "Direction" of A1. + //! where V is the "Direction" of theA1. //! - The orientation of this coordinate system //! (right-handed or left-handed) is not modified. - //! Raises ConstructionError if the "Direction" of and the "XDirection" of + //! Raises ConstructionError if the "Direction" of and the "XDirection" of //! are parallel (same or opposite orientation) because it is //! impossible to calculate the new "XDirection" and the new //! "YDirection". - void SetAxis (const gp_Ax1& A1); - + void SetAxis (const gp_Ax1& theA1); //! Changes the main direction of this coordinate system, //! then recomputes its "X Direction" and "Y Direction". //! Note: //! - The new "X Direction" is computed as follows: - //! new "X Direction" = V ^ (previous "X Direction" ^ V). + //! new "X Direction" = theV ^ (previous "X Direction" ^ theV). //! - The orientation of this coordinate system (left- or right-handed) is not modified. - //! Raises ConstructionError if and the previous "XDirection" are parallel //! because it is impossible to calculate the new "XDirection" //! and the new "YDirection". - void SetDirection (const gp_Dir& V); - + void SetDirection (const gp_Dir& theV); //! Changes the "Location" point (origin) of . - void SetLocation (const gp_Pnt& P); - + void SetLocation (const gp_Pnt& theP) { axis.SetLocation (theP); } //! Changes the "Xdirection" of . The main direction //! "Direction" is not modified, the "Ydirection" is modified. - //! If is not normal to the main direction then - //! is computed as follows XDirection = Direction ^ (Vx ^ Direction). - //! Raises ConstructionError if is parallel (same or opposite + //! If is not normal to the main direction then + //! is computed as follows XDirection = Direction ^ (theVx ^ Direction). + //! Raises ConstructionError if is parallel (same or opposite //! orientation) to the main direction of - void SetXDirection (const gp_Dir& Vx); - + void SetXDirection (const gp_Dir& theVx); //! Changes the "Ydirection" of . The main direction is not //! modified but the "Xdirection" is changed. - //! If is not normal to the main direction then "YDirection" + //! If is not normal to the main direction then "YDirection" //! is computed as follows - //! YDirection = Direction ^ ( ^ Direction). - //! Raises ConstructionError if is parallel to the main direction of - void SetYDirection (const gp_Dir& Vy); - + //! YDirection = Direction ^ ( ^ Direction). + //! Raises ConstructionError if is parallel to the main direction of + void SetYDirection (const gp_Dir& theVy); //! Computes the angular value between the main direction of - //! and the main direction of . Returns the angle + //! and the main direction of . Returns the angle //! between 0 and PI in radians. - Standard_Real Angle (const gp_Ax3& Other) const; - + Standard_Real Angle (const gp_Ax3& theOther) const { return axis.Angle (theOther.axis); } //! Returns the main axis of . It is the "Location" point //! and the main "Direction". - const gp_Ax1& Axis() const; - + const gp_Ax1& Axis() const { return axis; } + //! Computes a right-handed coordinate system with the //! same "X Direction" and "Y Direction" as those of this //! coordinate system, then recomputes the "main Direction". @@ -169,59 +161,52 @@ public: //! returned is the same coordinate system. If this //! coordinate system is left-handed, the result is reversed. gp_Ax2 Ax2() const; - //! Returns the main direction of . - const gp_Dir& Direction() const; - + const gp_Dir& Direction() const { return axis.Direction(); } //! Returns the "Location" point (origin) of . - const gp_Pnt& Location() const; - + const gp_Pnt& Location() const { return axis.Location(); } //! Returns the "XDirection" of . - const gp_Dir& XDirection() const; - + const gp_Dir& XDirection() const { return vxdir; } //! Returns the "YDirection" of . - const gp_Dir& YDirection() const; - + const gp_Dir& YDirection() const { return vydir; } + //! Returns True if the coordinate system is right-handed. i.e. //! XDirection().Crossed(YDirection()).Dot(Direction()) > 0 - Standard_Boolean Direct() const; - + Standard_Boolean Direct() const { return (vxdir.Crossed (vydir).Dot (axis.Direction()) > 0.); } //! Returns True if //! . the distance between the "Location" point of and - //! is lower or equal to LinearTolerance and - //! . the distance between the "Location" point of and - //! is lower or equal to LinearTolerance and + //! is lower or equal to theLinearTolerance and + //! . the distance between the "Location" point of and + //! is lower or equal to theLinearTolerance and //! . the main direction of and the main direction of - //! are parallel (same or opposite orientation). - Standard_Boolean IsCoplanar (const gp_Ax3& Other, const Standard_Real LinearTolerance, const Standard_Real AngularTolerance) const; - + //! are parallel (same or opposite orientation). + Standard_Boolean IsCoplanar (const gp_Ax3& theOther, const Standard_Real theLinearTolerance, const Standard_Real theAngularTolerance) const; + //! Returns True if - //! . the distance between and the "Location" point of A1 - //! is lower of equal to LinearTolerance and - //! . the distance between A1 and the "Location" point of - //! is lower or equal to LinearTolerance and - //! . the main direction of and the direction of A1 are normal. - Standard_Boolean IsCoplanar (const gp_Ax1& A1, const Standard_Real LinearTolerance, const Standard_Real AngularTolerance) const; - - Standard_EXPORT void Mirror (const gp_Pnt& P); - + //! . the distance between and the "Location" point of theA1 + //! is lower of equal to theLinearTolerance and + //! . the distance between theA1 and the "Location" point of + //! is lower or equal to theLinearTolerance and + //! . the main direction of and the direction of theA1 are normal. + Standard_Boolean IsCoplanar (const gp_Ax1& theA1, const Standard_Real theLinearTolerance, const Standard_Real theAngularTolerance) const; + + Standard_EXPORT void Mirror (const gp_Pnt& theP); //! Performs the symmetrical transformation of an axis - //! placement with respect to the point P which is the + //! placement with respect to the point theP which is the //! center of the symmetry. //! Warnings : //! The main direction of the axis placement is not changed. //! The "XDirection" and the "YDirection" are reversed. //! So the axis placement stay right handed. - Standard_NODISCARD Standard_EXPORT gp_Ax3 Mirrored (const gp_Pnt& P) const; - - Standard_EXPORT void Mirror (const gp_Ax1& A1); - + Standard_NODISCARD Standard_EXPORT gp_Ax3 Mirrored (const gp_Pnt& theP) const; + + Standard_EXPORT void Mirror (const gp_Ax1& theA1); //! Performs the symmetrical transformation of an axis //! placement with respect to an axis placement which @@ -230,65 +215,96 @@ public: //! point, on the "XDirection" and "YDirection". //! The resulting main "Direction" is the cross product between //! the "XDirection" and the "YDirection" after transformation. - Standard_NODISCARD Standard_EXPORT gp_Ax3 Mirrored (const gp_Ax1& A1) const; - - Standard_EXPORT void Mirror (const gp_Ax2& A2); - + Standard_NODISCARD Standard_EXPORT gp_Ax3 Mirrored (const gp_Ax1& theA1) const; + + Standard_EXPORT void Mirror (const gp_Ax2& theA2); //! Performs the symmetrical transformation of an axis //! placement with respect to a plane. - //! The axis placement locates the plane of the symmetry : + //! The axis placement locates the plane of the symmetry : //! (Location, XDirection, YDirection). //! The transformation is performed on the "Location" //! point, on the "XDirection" and "YDirection". //! The resulting main "Direction" is the cross product between //! the "XDirection" and the "YDirection" after transformation. - Standard_NODISCARD Standard_EXPORT gp_Ax3 Mirrored (const gp_Ax2& A2) const; - - void Rotate (const gp_Ax1& A1, const Standard_Real Ang); - + Standard_NODISCARD Standard_EXPORT gp_Ax3 Mirrored (const gp_Ax2& theA2) const; - //! Rotates an axis placement. is the axis of the - //! rotation . Ang is the angular value of the rotation + void Rotate (const gp_Ax1& theA1, const Standard_Real theAng) + { + axis.Rotate (theA1, theAng); + vxdir.Rotate (theA1, theAng); + vydir.Rotate (theA1, theAng); + } + + //! Rotates an axis placement. is the axis of the + //! rotation . theAng is the angular value of the rotation //! in radians. - Standard_NODISCARD gp_Ax3 Rotated (const gp_Ax1& A1, const Standard_Real Ang) const; - - void Scale (const gp_Pnt& P, const Standard_Real S); - + Standard_NODISCARD gp_Ax3 Rotated (const gp_Ax1& theA1, const Standard_Real theAng) const + { + gp_Ax3 aTemp = *this; + aTemp.Rotate (theA1, theAng); + return aTemp; + } + + void Scale (const gp_Pnt& theP, const Standard_Real theS) + { + axis.Scale (theP, theS); + if (theS < 0.) + { + vxdir.Reverse(); + vydir.Reverse(); + } + } //! Applies a scaling transformation on the axis placement. //! The "Location" point of the axisplacement is modified. //! Warnings : - //! If the scale is negative : + //! If the scale is negative : //! . the main direction of the axis placement is not changed. //! . The "XDirection" and the "YDirection" are reversed. //! So the axis placement stay right handed. - Standard_NODISCARD gp_Ax3 Scaled (const gp_Pnt& P, const Standard_Real S) const; - - void Transform (const gp_Trsf& T); - + Standard_NODISCARD gp_Ax3 Scaled (const gp_Pnt& theP, const Standard_Real theS) const + { + gp_Ax3 aTemp = *this; + aTemp.Scale (theP, theS); + return aTemp; + } + + void Transform (const gp_Trsf& theT) + { + axis.Transform (theT); + vxdir.Transform (theT); + vydir.Transform (theT); + } //! Transforms an axis placement with a Trsf. //! The "Location" point, the "XDirection" and the - //! "YDirection" are transformed with T. The resulting + //! "YDirection" are transformed with theT. The resulting //! main "Direction" of is the cross product between //! the "XDirection" and the "YDirection" after transformation. - Standard_NODISCARD gp_Ax3 Transformed (const gp_Trsf& T) const; - - void Translate (const gp_Vec& V); - + Standard_NODISCARD gp_Ax3 Transformed (const gp_Trsf& theT) const + { + gp_Ax3 aTemp = *this; + aTemp.Transform (theT); + return aTemp; + } + + void Translate (const gp_Vec& theV) { axis.Translate (theV); } //! Translates an axis plaxement in the direction of the vector - //! . The magnitude of the translation is the vector's magnitude. - Standard_NODISCARD gp_Ax3 Translated (const gp_Vec& V) const; - - void Translate (const gp_Pnt& P1, const gp_Pnt& P2); - + //! . The magnitude of the translation is the vector's magnitude. + Standard_NODISCARD gp_Ax3 Translated (const gp_Vec& theV) const + { + gp_Ax3 aTemp = *this; + aTemp.Translate (theV); + return aTemp; + } - //! Translates an axis placement from the point to the - //! point . - Standard_NODISCARD gp_Ax3 Translated (const gp_Pnt& P1, const gp_Pnt& P2) const; + void Translate (const gp_Pnt& theP1, const gp_Pnt& theP2) { Translate (gp_Vec (theP1, theP2)); } + //! Translates an axis placement from the point to the + //! point . + Standard_NODISCARD gp_Ax3 Translated (const gp_Pnt& theP1, const gp_Pnt& theP2) const { return Translated (gp_Vec (theP1, theP2)); } //! Dumps the content of me into the stream Standard_EXPORT void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const; @@ -296,28 +312,153 @@ public: //! Inits the content of me from the stream Standard_EXPORT Standard_Boolean InitFromJson (const Standard_SStream& theSStream, Standard_Integer& theStreamPos); -protected: - - - - - private: - - gp_Ax1 axis; gp_Dir vydir; gp_Dir vxdir; - }; +// ======================================================================= +// function : gp_Ax3 +// purpose : +// ======================================================================= +inline gp_Ax3::gp_Ax3 (const gp_Ax2& theA) +: axis (theA.Axis()), + vydir (theA.YDirection()), + vxdir (theA.XDirection()) +{} -#include +// ======================================================================= +// function : Ax2 +// purpose : +// ======================================================================= +inline gp_Ax2 gp_Ax3::Ax2()const +{ + gp_Dir aZz = axis.Direction(); + if (!Direct()) + { + aZz.Reverse(); + } + return gp_Ax2 (axis.Location(), aZz, vxdir); +} +// ======================================================================= +// function : SetAxis +// purpose : +// ======================================================================= +inline void gp_Ax3::SetAxis (const gp_Ax1& theA1) +{ + Standard_Boolean isDirect = Direct(); + axis = theA1; + vxdir = axis.Direction().CrossCrossed (vxdir, axis.Direction()); + if (isDirect) + { + vydir = axis.Direction().Crossed (vxdir); + } + else + { + vydir = vxdir.Crossed (axis.Direction()); + } +} +// ======================================================================= +// function : SetDirection +// purpose : +// ======================================================================= +inline void gp_Ax3::SetDirection (const gp_Dir& theV) +{ + Standard_Boolean isDirect = Direct(); + axis.SetDirection (theV); + vxdir = theV.CrossCrossed (vxdir, theV); + if (isDirect) + { + vydir = theV.Crossed (vxdir); + } + else + { + vydir = vxdir.Crossed (theV); + } +} +// ======================================================================= +// function : SetXDirection +// purpose : +// ======================================================================= +inline void gp_Ax3::SetXDirection (const gp_Dir& theVx) +{ + Standard_Boolean isDirect = Direct(); + vxdir = axis.Direction().CrossCrossed (theVx, axis.Direction()); + if (isDirect) + { + vydir = axis.Direction().Crossed (vxdir); + } + else + { + vydir = vxdir.Crossed (axis.Direction()); + } +} +// ======================================================================= +// function : SetYDirection +// purpose : +// ======================================================================= +inline void gp_Ax3::SetYDirection (const gp_Dir& theVy) +{ + Standard_Boolean isDirect = Direct(); + vxdir = theVy.Crossed (axis.Direction()); + vydir = (axis.Direction()).Crossed (vxdir); + if (!isDirect) + { + vxdir.Reverse(); + } +} + +// ======================================================================= +// function : IsCoplanar +// purpose : +// ======================================================================= +inline Standard_Boolean gp_Ax3::IsCoplanar (const gp_Ax3& theOther, + const Standard_Real theLinearTolerance, + const Standard_Real theAngularTolerance)const +{ + gp_Vec aVec (axis.Location(), theOther.axis.Location()); + Standard_Real aD1 = gp_Vec (axis.Direction()).Dot(aVec); + if (aD1 < 0) + { + aD1 = -aD1; + } + Standard_Real aD2 = gp_Vec (theOther.axis.Direction()).Dot(aVec); + if (aD2 < 0) + { + aD2 = -aD2; + } + return (aD1 <= theLinearTolerance && aD2 <= theLinearTolerance && + axis.IsParallel (theOther.axis, theAngularTolerance)); +} + +// ======================================================================= +// function : IsCoplanar +// purpose : +// ======================================================================= +inline Standard_Boolean gp_Ax3::IsCoplanar (const gp_Ax1& theA1, + const Standard_Real theLinearTolerance, + const Standard_Real theAngularTolerance)const +{ + gp_Vec aVec (axis.Location(), theA1.Location()); + Standard_Real aD1 = gp_Vec (axis.Direction()).Dot (aVec); + if (aD1 < 0) + { + aD1 = -aD1; + } + Standard_Real aD2 = (gp_Vec (theA1.Direction()).Crossed (aVec)).Magnitude(); + if (aD2 < 0) + { + aD2 = -aD2; + } + return (aD1 <= theLinearTolerance && aD2 <= theLinearTolerance && + axis.IsNormal (theA1, theAngularTolerance)); +} #endif // _gp_Ax3_HeaderFile diff --git a/src/gp/gp_Ax3.lxx b/src/gp/gp_Ax3.lxx deleted file mode 100644 index 2b4fe6d91a..0000000000 --- a/src/gp/gp_Ax3.lxx +++ /dev/null @@ -1,200 +0,0 @@ -// Copyright (c) 1996-1999 Matra Datavision -// Copyright (c) 1999-2014 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -#include - -inline gp_Ax3::gp_Ax3() - : - vydir(0.,1.,0.) - // vxdir(1.,0.,0.) use default ctor of gp_Dir, as it creates the same dir(1,0,0) -{ } - -inline gp_Ax3::gp_Ax3(const gp_Ax2& A) : -axis(A.Axis()), -vydir(A.YDirection()), -vxdir(A.XDirection()) -{ } - -inline gp_Ax3::gp_Ax3(const gp_Pnt& P, const gp_Dir& N, const gp_Dir& Vx) : -axis(P, N), vydir(N), vxdir(N) -{ - vxdir.CrossCross(Vx, N); - vydir.Cross(vxdir); -} - -inline void gp_Ax3::XReverse() -{ vxdir.Reverse(); } - -inline void gp_Ax3::YReverse() -{ vydir.Reverse(); } - -inline void gp_Ax3::ZReverse() -{ axis.Reverse(); } - -inline void gp_Ax3::SetAxis(const gp_Ax1& A1) -{ - Standard_Boolean direct = Direct(); - axis = A1; - vxdir = axis.Direction().CrossCrossed (vxdir, axis.Direction()); - if(direct) { vydir = axis.Direction().Crossed(vxdir); } - else { vydir = vxdir.Crossed(axis.Direction()); } -} - -inline void gp_Ax3::SetDirection(const gp_Dir& V) -{ - Standard_Boolean direct = Direct(); - axis.SetDirection (V); - vxdir = V.CrossCrossed (vxdir, V); - if (direct) { vydir = V.Crossed (vxdir); } - else { vydir = vxdir.Crossed (V); } -} - -inline void gp_Ax3::SetLocation(const gp_Pnt& P) -{ axis.SetLocation(P); } - -inline void gp_Ax3::SetXDirection(const gp_Dir& Vx) -{ - Standard_Boolean direct = Direct(); - vxdir = axis.Direction().CrossCrossed (Vx, axis.Direction()); - if (direct) { vydir = axis.Direction().Crossed(vxdir); } - else { vydir = vxdir.Crossed(axis.Direction()); } -} - -inline void gp_Ax3::SetYDirection(const gp_Dir& Vy) -{ - Standard_Boolean direct = Direct(); - vxdir = Vy.Crossed (axis.Direction()); - vydir = (axis.Direction()).Crossed (vxdir); - if (!direct) { vxdir.Reverse(); } -} - -inline Standard_Real gp_Ax3::Angle(const gp_Ax3& Other) const -{ return axis.Angle (Other.axis); } - -inline const gp_Ax1& gp_Ax3::Axis()const -{ return axis; } - -inline gp_Ax2 gp_Ax3::Ax2()const -{ - gp_Dir zz = axis.Direction(); - if (!Direct()) { zz.Reverse(); } - return gp_Ax2 (axis.Location(),zz,vxdir); -} - -inline const gp_Dir& gp_Ax3::Direction()const -{ return axis.Direction(); } - -inline const gp_Pnt& gp_Ax3::Location()const -{ return axis.Location(); } - -inline const gp_Dir& gp_Ax3::XDirection()const -{ return vxdir; } - -inline const gp_Dir& gp_Ax3::YDirection()const -{ return vydir; } - -inline Standard_Boolean gp_Ax3::Direct()const -{ return (vxdir.Crossed(vydir).Dot(axis.Direction()) > 0.); } - -inline Standard_Boolean gp_Ax3::IsCoplanar -(const gp_Ax3& Other, - const Standard_Real LinearTolerance, - const Standard_Real AngularTolerance)const -{ - gp_Vec vec(axis.Location(),Other.axis.Location()); - Standard_Real D1 = gp_Vec(axis.Direction() ).Dot(vec); - if (D1 < 0) D1 = - D1; - Standard_Real D2 = gp_Vec(Other.axis.Direction()).Dot(vec); - if (D2 < 0) D2 = - D2; - return (D1 <= LinearTolerance && D2 <= LinearTolerance && - axis.IsParallel (Other.axis, AngularTolerance)); -} - -inline Standard_Boolean gp_Ax3::IsCoplanar -(const gp_Ax1& A1, - const Standard_Real LinearTolerance, - const Standard_Real AngularTolerance)const -{ - gp_Vec vec(axis.Location(),A1.Location()); - Standard_Real D1 = gp_Vec(axis.Direction()).Dot(vec); - if (D1 < 0) D1 = - D1; - Standard_Real D2 = (gp_Vec(A1.Direction()).Crossed(vec)).Magnitude(); - if (D2 < 0) D2 = - D2; - return (D1 <= LinearTolerance && D2 <= LinearTolerance && - axis.IsNormal (A1, AngularTolerance)); -} - -inline void gp_Ax3::Rotate(const gp_Ax1& A1, - const Standard_Real Ang) -{ - axis.Rotate (A1,Ang); - vxdir.Rotate (A1,Ang); - vydir.Rotate (A1,Ang); -} - -inline gp_Ax3 gp_Ax3::Rotated(const gp_Ax1& A1, - const Standard_Real Ang)const -{ - gp_Ax3 Temp = *this; - Temp.Rotate (A1,Ang); - return Temp; -} - -inline void gp_Ax3::Scale(const gp_Pnt& P, const Standard_Real S) -{ - axis.Scale (P,S); - if (S < 0.) { - vxdir.Reverse (); - vydir.Reverse (); - } -} - -inline gp_Ax3 gp_Ax3::Scaled(const gp_Pnt& P, - const Standard_Real S)const -{ - gp_Ax3 Temp = *this; - Temp.Scale (P,S); - return Temp; -} - -inline void gp_Ax3::Transform(const gp_Trsf& T) -{ - axis.Transform (T); - vxdir.Transform (T); - vydir.Transform (T); -} - -inline gp_Ax3 gp_Ax3::Transformed(const gp_Trsf& T)const -{ - gp_Ax3 Temp = *this; - Temp.Transform (T); - return Temp; -} - -inline void gp_Ax3::Translate(const gp_Vec& V) -{ axis.Translate (V); } - -inline gp_Ax3 gp_Ax3::Translated(const gp_Vec& V)const -{ - gp_Ax3 Temp = *this; - Temp.Translate (V); - return Temp; -} - -inline void gp_Ax3::Translate(const gp_Pnt& P1, const gp_Pnt& P2) -{ Translate(gp_Vec(P1,P2)); } - -inline gp_Ax3 gp_Ax3::Translated(const gp_Pnt& P1, const gp_Pnt& P2)const -{ return Translated(gp_Vec(P1,P2)); } - diff --git a/src/gp/gp_Circ.cxx b/src/gp/gp_Circ.cxx index bd859ac98a..baae99e6a7 100644 --- a/src/gp/gp_Circ.cxx +++ b/src/gp/gp_Circ.cxx @@ -12,10 +12,10 @@ // Alternatively, this file may be used under the terms of Open CASCADE // commercial license or contractual agreement. +#include #include #include -#include #include #include #include diff --git a/src/gp/gp_Circ.hxx b/src/gp/gp_Circ.hxx index 1347755168..524767f211 100644 --- a/src/gp/gp_Circ.hxx +++ b/src/gp/gp_Circ.hxx @@ -15,22 +15,12 @@ #ifndef _gp_Circ_HeaderFile #define _gp_Circ_HeaderFile -#include -#include -#include - -#include -#include #include -#include -class Standard_ConstructionError; -class gp_Ax2; -class gp_Ax1; -class gp_Pnt; -class gp_Trsf; -class gp_Vec; - - +#include +#include +#include +#include +#include //! Describes a circle in 3D space. //! A circle is defined by its radius and positioned in space @@ -64,173 +54,227 @@ public: DEFINE_STANDARD_ALLOC - //! Creates an indefinite circle. - gp_Circ(); - + gp_Circ() : radius (RealLast()) + {} //! A2 locates the circle and gives its orientation in 3D space. //! Warnings : - //! It is not forbidden to create a circle with Radius = 0.0 Raises ConstructionError if Radius < 0.0 - gp_Circ(const gp_Ax2& A2, const Standard_Real Radius); - + //! It is not forbidden to create a circle with theRadius = 0.0 Raises ConstructionError if theRadius < 0.0 + gp_Circ (const gp_Ax2& theA2, const Standard_Real theRadius) + : pos (theA2), + radius(theRadius) + { + Standard_ConstructionError_Raise_if (theRadius < 0.0, "gp_Circ() - radius should be positive number"); + } //! Changes the main axis of the circle. It is the axis //! perpendicular to the plane of the circle. - //! Raises ConstructionError if the direction of A1 + //! Raises ConstructionError if the direction of theA1 //! is parallel to the "XAxis" of the circle. - void SetAxis (const gp_Ax1& A1); - + void SetAxis (const gp_Ax1& theA1) { pos.SetAxis (theA1); } //! Changes the "Location" point (center) of the circle. - void SetLocation (const gp_Pnt& P); - + void SetLocation (const gp_Pnt& theP) { pos.SetLocation (theP); } + //! Changes the position of the circle. - void SetPosition (const gp_Ax2& A2); - + void SetPosition (const gp_Ax2& theA2) { pos = theA2; } + //! Modifies the radius of this circle. - //! Warning. This class does not prevent the creation of a circle where Radius is null. + //! Warning. This class does not prevent the creation of a circle where theRadius is null. //! Exceptions - //! Standard_ConstructionError if Radius is negative. - void SetRadius (const Standard_Real Radius); - + //! Standard_ConstructionError if theRadius is negative. + void SetRadius (const Standard_Real theRadius) + { + Standard_ConstructionError_Raise_if (theRadius < 0.0, "gp_Circ::SetRadius() - radius should be positive number"); + radius = theRadius; + } + //! Computes the area of the circle. - Standard_Real Area() const; - + Standard_Real Area() const { return M_PI * radius * radius; } //! Returns the main axis of the circle. //! It is the axis perpendicular to the plane of the circle, //! passing through the "Location" point (center) of the circle. - const gp_Ax1& Axis() const; - + const gp_Ax1& Axis() const { return pos.Axis(); } + //! Computes the circumference of the circle. - Standard_Real Length() const; - + Standard_Real Length() const { return 2. * M_PI * radius; } //! Returns the center of the circle. It is the //! "Location" point of the local coordinate system //! of the circle - const gp_Pnt& Location() const; - + const gp_Pnt& Location() const { return pos.Location(); } //! Returns the position of the circle. //! It is the local coordinate system of the circle. - const gp_Ax2& Position() const; - + const gp_Ax2& Position() const { return pos; } + //! Returns the radius of this circle. - Standard_Real Radius() const; - + Standard_Real Radius() const { return radius; } //! Returns the "XAxis" of the circle. //! This axis is perpendicular to the axis of the conic. //! This axis and the "Yaxis" define the plane of the conic. - gp_Ax1 XAxis() const; - + gp_Ax1 XAxis() const { return gp_Ax1 (pos.Location(), pos.XDirection()); } //! Returns the "YAxis" of the circle. //! This axis and the "Xaxis" define the plane of the conic. //! The "YAxis" is perpendicular to the "Xaxis". - gp_Ax1 YAxis() const; - + gp_Ax1 YAxis() const { return gp_Ax1 (pos.Location(), pos.YDirection()); } - //! Computes the minimum of distance between the point P and + //! Computes the minimum of distance between the point theP and //! any point on the circumference of the circle. - Standard_Real Distance (const gp_Pnt& P) const; - + Standard_Real Distance (const gp_Pnt& theP) const { return sqrt (SquareDistance (theP)); } - //! Computes the square distance between and the point P. - Standard_Real SquareDistance (const gp_Pnt& P) const; - + //! Computes the square distance between and the point theP. + Standard_Real SquareDistance (const gp_Pnt& theP) const + { + gp_Vec aV (Location(), theP); + Standard_Real aX = aV.Dot (pos.XDirection()); + Standard_Real anY = aV.Dot (pos.YDirection()); + Standard_Real aZ = aV.Dot (pos.Direction()); + Standard_Real aT = sqrt (aX * aX + anY * anY) - radius; + return (aT * aT + aZ * aZ); + } - //! Returns True if the point P is on the circumference. - //! The distance between and

must be lower or - //! equal to LinearTolerance. - Standard_Boolean Contains (const gp_Pnt& P, const Standard_Real LinearTolerance) const; - - Standard_EXPORT void Mirror (const gp_Pnt& P); - + //! Returns True if the point theP is on the circumference. + //! The distance between and must be lower or + //! equal to theLinearTolerance. + Standard_Boolean Contains (const gp_Pnt& theP, const Standard_Real theLinearTolerance) const { return Distance (theP) <= theLinearTolerance; } + + Standard_EXPORT void Mirror (const gp_Pnt& theP); //! Performs the symmetrical transformation of a circle - //! with respect to the point P which is the center of the + //! with respect to the point theP which is the center of the //! symmetry. - Standard_NODISCARD Standard_EXPORT gp_Circ Mirrored (const gp_Pnt& P) const; - - Standard_EXPORT void Mirror (const gp_Ax1& A1); - + Standard_NODISCARD Standard_EXPORT gp_Circ Mirrored (const gp_Pnt& theP) const; + + Standard_EXPORT void Mirror (const gp_Ax1& theA1); //! Performs the symmetrical transformation of a circle with //! respect to an axis placement which is the axis of the //! symmetry. - Standard_NODISCARD Standard_EXPORT gp_Circ Mirrored (const gp_Ax1& A1) const; - - Standard_EXPORT void Mirror (const gp_Ax2& A2); - + Standard_NODISCARD Standard_EXPORT gp_Circ Mirrored (const gp_Ax1& theA1) const; + + Standard_EXPORT void Mirror (const gp_Ax2& theA2); //! Performs the symmetrical transformation of a circle with respect - //! to a plane. The axis placement A2 locates the plane of the + //! to a plane. The axis placement theA2 locates the plane of the //! of the symmetry : (Location, XDirection, YDirection). - Standard_NODISCARD Standard_EXPORT gp_Circ Mirrored (const gp_Ax2& A2) const; - - void Rotate (const gp_Ax1& A1, const Standard_Real Ang); - + Standard_NODISCARD Standard_EXPORT gp_Circ Mirrored (const gp_Ax2& theA2) const; - //! Rotates a circle. A1 is the axis of the rotation. - //! Ang is the angular value of the rotation in radians. - Standard_NODISCARD gp_Circ Rotated (const gp_Ax1& A1, const Standard_Real Ang) const; - - void Scale (const gp_Pnt& P, const Standard_Real S); - + void Rotate (const gp_Ax1& theA1, const Standard_Real theAng) { pos.Rotate (theA1, theAng); } - //! Scales a circle. S is the scaling value. + //! Rotates a circle. theA1 is the axis of the rotation. + //! theAng is the angular value of the rotation in radians. + Standard_NODISCARD gp_Circ Rotated (const gp_Ax1& theA1, const Standard_Real theAng) const + { + gp_Circ aC = *this; + aC.pos.Rotate (theA1, theAng); + return aC; + } + + void Scale (const gp_Pnt& theP, const Standard_Real theS); + + //! Scales a circle. theS is the scaling value. //! Warnings : - //! If S is negative the radius stay positive but + //! If theS is negative the radius stay positive but //! the "XAxis" and the "YAxis" are reversed as for //! an ellipse. - Standard_NODISCARD gp_Circ Scaled (const gp_Pnt& P, const Standard_Real S) const; - - void Transform (const gp_Trsf& T); - + Standard_NODISCARD gp_Circ Scaled (const gp_Pnt& theP, const Standard_Real theS) const; - //! Transforms a circle with the transformation T from class Trsf. - Standard_NODISCARD gp_Circ Transformed (const gp_Trsf& T) const; - - void Translate (const gp_Vec& V); - + void Transform (const gp_Trsf& theT); - //! Translates a circle in the direction of the vector V. + //! Transforms a circle with the transformation theT from class Trsf. + Standard_NODISCARD gp_Circ Transformed (const gp_Trsf& theT) const; + + void Translate (const gp_Vec& theV) { pos.Translate (theV); } + + //! Translates a circle in the direction of the vector theV. //! The magnitude of the translation is the vector's magnitude. - Standard_NODISCARD gp_Circ Translated (const gp_Vec& V) const; - - void Translate (const gp_Pnt& P1, const gp_Pnt& P2); - - - //! Translates a circle from the point P1 to the point P2. - Standard_NODISCARD gp_Circ Translated (const gp_Pnt& P1, const gp_Pnt& P2) const; - - - - -protected: - - + Standard_NODISCARD gp_Circ Translated (const gp_Vec& theV) const + { + gp_Circ aC = *this; + aC.pos.Translate (theV); + return aC; + } + void Translate (const gp_Pnt& theP1, const gp_Pnt& theP2) { pos.Translate (theP1, theP2); } + //! Translates a circle from the point theP1 to the point theP2. + Standard_NODISCARD gp_Circ Translated (const gp_Pnt& theP1, const gp_Pnt& theP2) const + { + gp_Circ aC = *this; + aC.pos.Translate (theP1, theP2); + return aC; + } private: - - gp_Ax2 pos; Standard_Real radius; - }; +// ======================================================================= +// function : Scale +// purpose : +// ======================================================================= +inline void gp_Circ::Scale (const gp_Pnt& theP, const Standard_Real theS) +{ + radius *= theS; + if (radius < 0) + { + radius = -radius; + } + pos.Scale (theP, theS); +} -#include - - +// ======================================================================= +// function : Scaled +// purpose : +// ======================================================================= +inline gp_Circ gp_Circ::Scaled (const gp_Pnt& theP, const Standard_Real theS) const +{ + gp_Circ aC = *this; + aC.radius *= theS; + if (aC.radius < 0) + { + aC.radius = -aC.radius; + } + aC.pos.Scale (theP, theS); + return aC; +} +// ======================================================================= +// function : Transform +// purpose : +// ======================================================================= +inline void gp_Circ::Transform (const gp_Trsf& theT) +{ + radius *= theT.ScaleFactor(); + if (radius < 0) + { + radius = -radius; + } + pos.Transform (theT); +} +// ======================================================================= +// function : Transformed +// purpose : +// ======================================================================= +inline gp_Circ gp_Circ::Transformed (const gp_Trsf& theT) const +{ + gp_Circ aC = *this; + aC.radius *= theT.ScaleFactor(); + if (aC.radius < 0) + { + aC.radius = -aC.radius; + } + aC.pos.Transform (theT); + return aC; +} #endif // _gp_Circ_HeaderFile diff --git a/src/gp/gp_Circ.lxx b/src/gp/gp_Circ.lxx deleted file mode 100644 index 39006dc3f1..0000000000 --- a/src/gp/gp_Circ.lxx +++ /dev/null @@ -1,153 +0,0 @@ -// Copyright (c) 1995-1999 Matra Datavision -// Copyright (c) 1999-2014 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -#include -#include -#include -#include - -inline gp_Circ::gp_Circ () : radius(RealLast()) -{ } - -inline gp_Circ::gp_Circ (const gp_Ax2& A2, - const Standard_Real R) : pos(A2), radius(R) -{ - Standard_ConstructionError_Raise_if (R < 0.0, "gp_Circ() - radius should be positive number"); -} - -inline void gp_Circ::SetAxis (const gp_Ax1& A1) -{ pos.SetAxis (A1); } - -inline void gp_Circ::SetLocation (const gp_Pnt& P) -{ pos.SetLocation (P); } - -inline void gp_Circ::SetPosition (const gp_Ax2& A2) -{ pos = A2; } - -inline void gp_Circ::SetRadius (const Standard_Real R) -{ - Standard_ConstructionError_Raise_if (R < 0.0, "gp_Circ::SetRadius() - radius should be positive number"); - radius = R; -} - -inline Standard_Real gp_Circ::Area() const -{ return M_PI * radius * radius; } - -inline const gp_Ax1& gp_Circ::Axis () const -{ return pos.Axis(); } - -inline Standard_Real gp_Circ::Length() const -{ return 2. * M_PI * radius; } - -inline const gp_Pnt& gp_Circ::Location () const -{ return pos.Location(); } - -inline const gp_Ax2& gp_Circ::Position() const -{ return pos; } - -inline Standard_Real gp_Circ::Radius() const -{ return radius; } - -inline gp_Ax1 gp_Circ::XAxis () const -{return gp_Ax1(pos.Location(), pos.XDirection());} - -inline gp_Ax1 gp_Circ::YAxis () const -{return gp_Ax1(pos.Location(), pos.YDirection());} - -inline Standard_Real gp_Circ::Distance (const gp_Pnt& P) const -{ return sqrt(SquareDistance(P)); } - -inline Standard_Real gp_Circ::SquareDistance (const gp_Pnt& P) const -{ - gp_Vec V(Location(),P); - Standard_Real x = V.Dot(pos.XDirection()); - Standard_Real y = V.Dot(pos.YDirection()); - Standard_Real z = V.Dot(pos.Direction ()); - Standard_Real t = sqrt( x*x + y*y) - radius; - return (t*t + z*z); -} - -inline Standard_Boolean gp_Circ::Contains -(const gp_Pnt& P, - const Standard_Real LinearTolerance) const -{ return Distance(P) <= LinearTolerance; } - -inline void gp_Circ::Rotate (const gp_Ax1& A1, - const Standard_Real Ang) -{ pos.Rotate(A1, Ang); } - -inline gp_Circ gp_Circ::Rotated (const gp_Ax1& A1, - const Standard_Real Ang) const -{ - gp_Circ C = *this; - C.pos.Rotate(A1, Ang); - return C; -} - -inline void gp_Circ::Scale (const gp_Pnt& P, - const Standard_Real S) -{ - radius *= S; - if (radius < 0) radius = - radius; - pos.Scale(P, S); -} - -inline gp_Circ gp_Circ::Scaled (const gp_Pnt& P, - const Standard_Real S) const -{ - gp_Circ C = *this; - C.radius *= S; - if (C.radius < 0) C.radius = - C.radius; - C.pos.Scale(P, S); - return C; -} - -inline void gp_Circ::Transform (const gp_Trsf& T) -{ - radius *= T.ScaleFactor(); - if (radius < 0) radius = - radius; - pos.Transform(T); -} - -inline gp_Circ gp_Circ::Transformed (const gp_Trsf& T) const -{ - gp_Circ C = *this; - C.radius *= T.ScaleFactor(); - if (C.radius < 0) C.radius = - C.radius; - C.pos.Transform(T); - return C; -} - -inline void gp_Circ::Translate (const gp_Vec& V) -{ pos.Translate(V); } - -inline gp_Circ gp_Circ::Translated (const gp_Vec& V) const -{ - gp_Circ C = *this; - C.pos.Translate(V); - return C; -} - -inline void gp_Circ::Translate (const gp_Pnt& P1, - const gp_Pnt& P2) -{pos.Translate(P1,P2);} - -inline gp_Circ gp_Circ::Translated (const gp_Pnt& P1, - const gp_Pnt& P2) const -{ - gp_Circ C = *this; - C.pos.Translate(P1, P2); - return C; -} - diff --git a/src/gp/gp_Circ2d.cxx b/src/gp/gp_Circ2d.cxx index 64cfca96ce..0a24ad35a4 100644 --- a/src/gp/gp_Circ2d.cxx +++ b/src/gp/gp_Circ2d.cxx @@ -14,9 +14,10 @@ //modif JCV 10/01/91 suite a la deuxieme revue de projet toolkit geometry +#include + #include #include -#include #include #include #include diff --git a/src/gp/gp_Circ2d.hxx b/src/gp/gp_Circ2d.hxx index 8cf4047e67..5a816450e4 100644 --- a/src/gp/gp_Circ2d.hxx +++ b/src/gp/gp_Circ2d.hxx @@ -15,21 +15,12 @@ #ifndef _gp_Circ2d_HeaderFile #define _gp_Circ2d_HeaderFile -#include -#include -#include - #include -#include -#include #include -class Standard_ConstructionError; -class gp_Ax2d; -class gp_Ax22d; -class gp_Pnt2d; -class gp_Trsf2d; -class gp_Vec2d; - +#include +#include +#include +#include //! Describes a circle in the plane (2D space). //! A circle is defined by its radius and positioned in the @@ -61,181 +52,318 @@ public: DEFINE_STANDARD_ALLOC - //! creates an indefinite circle. - gp_Circ2d(); - + gp_Circ2d() + : radius (RealLast()) + {} - //! The location point of XAxis is the center of the circle. + //! The location point of theXAxis is the center of the circle. //! Warnings : - //! It is not forbidden to create a circle with Radius = 0.0 Raises ConstructionError if Radius < 0.0. - //! Raised if Radius < 0.0. - gp_Circ2d(const gp_Ax2d& XAxis, const Standard_Real Radius, const Standard_Boolean Sense = Standard_True); - + //! It is not forbidden to create a circle with theRadius = 0.0 Raises ConstructionError if theRadius < 0.0. + //! Raised if theRadius < 0.0. + gp_Circ2d (const gp_Ax2d& theXAxis, const Standard_Real theRadius, const Standard_Boolean theIsSense = Standard_True) + : radius (theRadius) + { + Standard_ConstructionError_Raise_if (theRadius < 0.0, "gp_Circ2d() - radius should be positive number"); + pos = gp_Ax22d (theXAxis, theIsSense); + } - //! Axis defines the Xaxis and Yaxis of the circle which defines + //! theAxis defines the Xaxis and Yaxis of the circle which defines //! the origin and the sense of parametrization. - //! The location point of Axis is the center of the circle. + //! The location point of theAxis is the center of the circle. //! Warnings : - //! It is not forbidden to create a circle with Radius = 0.0 Raises ConstructionError if Radius < 0.0. - //! Raised if Radius < 0.0. - gp_Circ2d(const gp_Ax22d& Axis, const Standard_Real Radius); - + //! It is not forbidden to create a circle with theRadius = 0.0 Raises ConstructionError if theRadius < 0.0. + //! Raised if theRadius < 0.0. + gp_Circ2d (const gp_Ax22d& theAxis, const Standard_Real theRadius) + : pos (theAxis), + radius (theRadius) + { + Standard_ConstructionError_Raise_if (theRadius < 0.0, "gp_Circ2d() - radius should be positive number"); + } + //! Changes the location point (center) of the circle. - void SetLocation (const gp_Pnt2d& P); - + void SetLocation (const gp_Pnt2d& theP) { pos.SetLocation (theP); } + //! Changes the X axis of the circle. - void SetXAxis (const gp_Ax2d& A); - + void SetXAxis (const gp_Ax2d& theA) { pos.SetXAxis (theA); } + //! Changes the X axis of the circle. - void SetAxis (const gp_Ax22d& A); - + void SetAxis (const gp_Ax22d& theA) { pos.SetAxis (theA); } + //! Changes the Y axis of the circle. - void SetYAxis (const gp_Ax2d& A); - + void SetYAxis (const gp_Ax2d& theA) { pos.SetYAxis (theA); } + //! Modifies the radius of this circle. //! This class does not prevent the creation of a circle where - //! Radius is null. + //! theRadius is null. //! Exceptions - //! Standard_ConstructionError if Radius is negative. - void SetRadius (const Standard_Real Radius); - + //! Standard_ConstructionError if theRadius is negative. + void SetRadius (const Standard_Real theRadius) + { + Standard_ConstructionError_Raise_if (theRadius < 0.0, "gp_Circ2d::SetRadius() - radius should be positive number"); + radius = theRadius; + } + //! Computes the area of the circle. - Standard_Real Area() const; - + Standard_Real Area() const { return M_PI * radius * radius; } //! Returns the normalized coefficients from the implicit equation //! of the circle : - //! A * (X**2) + B * (Y**2) + 2*C*(X*Y) + 2*D*X + 2*E*Y + F = 0.0 - void Coefficients (Standard_Real& A, Standard_Real& B, Standard_Real& C, Standard_Real& D, Standard_Real& E, Standard_Real& F) const; - - //! Does contain P ? - //! Returns True if the distance between P and any point on + //! theA * (X**2) + theB * (Y**2) + 2*theC*(X*Y) + 2*theD*X + 2*theE*Y + theF = 0.0 + void Coefficients (Standard_Real& theA, Standard_Real& theB, + Standard_Real& theC, Standard_Real& theD, + Standard_Real& theE, Standard_Real& theF) const; + + //! Does contain theP ? + //! Returns True if the distance between theP and any point on //! the circumference of the circle is lower of equal to - //! . - Standard_Boolean Contains (const gp_Pnt2d& P, const Standard_Real LinearTolerance) const; - + //! . + Standard_Boolean Contains (const gp_Pnt2d& theP, const Standard_Real theLinearTolerance) const + { + return Distance (theP) <= theLinearTolerance; + } - //! Computes the minimum of distance between the point P and any + //! Computes the minimum of distance between the point theP and any //! point on the circumference of the circle. - Standard_Real Distance (const gp_Pnt2d& P) const; - + Standard_Real Distance (const gp_Pnt2d& theP) const; + + //! Computes the square distance between and the point theP. + Standard_Real SquareDistance (const gp_Pnt2d& theP) const; - //! Computes the square distance between and the point P. - Standard_Real SquareDistance (const gp_Pnt2d& P) const; - //! computes the circumference of the circle. - Standard_Real Length() const; - + Standard_Real Length() const { return 2. * M_PI * radius; } + //! Returns the location point (center) of the circle. - const gp_Pnt2d& Location() const; - + const gp_Pnt2d& Location() const { return pos.Location(); } + //! Returns the radius value of the circle. - Standard_Real Radius() const; - + Standard_Real Radius() const { return radius; } + //! returns the position of the circle. - const gp_Ax22d& Axis() const; - + const gp_Ax22d& Axis() const { return pos; } + //! returns the position of the circle. Idem Axis(me). - const gp_Ax22d& Position() const; - + const gp_Ax22d& Position() const { return pos; } + //! returns the X axis of the circle. - gp_Ax2d XAxis() const; - + gp_Ax2d XAxis() const { return gp_Ax2d (pos.XAxis()); } + //! Returns the Y axis of the circle. //! Reverses the direction of the circle. - gp_Ax2d YAxis() const; - + gp_Ax2d YAxis() const { return gp_Ax2d (pos.YAxis()); } + //! Reverses the orientation of the local coordinate system //! of this circle (the "Y Direction" is reversed) and therefore //! changes the implicit orientation of this circle. //! Reverse assigns the result to this circle, - void Reverse(); - + void Reverse() + { + gp_Dir2d aTemp = pos.YDirection(); + aTemp.Reverse(); + pos.SetAxis (gp_Ax22d (pos.Location(), pos.XDirection(), aTemp)); + } + //! Reverses the orientation of the local coordinate system //! of this circle (the "Y Direction" is reversed) and therefore //! changes the implicit orientation of this circle. //! Reversed creates a new circle. - Standard_NODISCARD gp_Circ2d Reversed() const; - + Standard_NODISCARD gp_Circ2d Reversed() const; + //! Returns true if the local coordinate system is direct //! and false in the other case. - Standard_Boolean IsDirect() const; - - Standard_EXPORT void Mirror (const gp_Pnt2d& P); - + Standard_Boolean IsDirect() const + { + return (pos.XDirection().Crossed (pos.YDirection())) >= 0.0; + } + + Standard_EXPORT void Mirror (const gp_Pnt2d& theP); //! Performs the symmetrical transformation of a circle with respect - //! to the point P which is the center of the symmetry - Standard_NODISCARD Standard_EXPORT gp_Circ2d Mirrored (const gp_Pnt2d& P) const; - - Standard_EXPORT void Mirror (const gp_Ax2d& A); - + //! to the point theP which is the center of the symmetry + Standard_NODISCARD Standard_EXPORT gp_Circ2d Mirrored (const gp_Pnt2d& theP) const; + + Standard_EXPORT void Mirror (const gp_Ax2d& theA); //! Performs the symmetrical transformation of a circle with respect //! to an axis placement which is the axis of the symmetry. - Standard_NODISCARD Standard_EXPORT gp_Circ2d Mirrored (const gp_Ax2d& A) const; - - void Rotate (const gp_Pnt2d& P, const Standard_Real Ang); - + Standard_NODISCARD Standard_EXPORT gp_Circ2d Mirrored (const gp_Ax2d& theA) const; - //! Rotates a circle. P is the center of the rotation. + void Rotate (const gp_Pnt2d& theP, const Standard_Real theAng) + { + pos.Rotate (theP, theAng); + } + + //! Rotates a circle. theP is the center of the rotation. //! Ang is the angular value of the rotation in radians. - Standard_NODISCARD gp_Circ2d Rotated (const gp_Pnt2d& P, const Standard_Real Ang) const; - - void Scale (const gp_Pnt2d& P, const Standard_Real S); - + Standard_NODISCARD gp_Circ2d Rotated (const gp_Pnt2d& theP, const Standard_Real theAng) const + { + gp_Circ2d aCirc = *this; + aCirc.pos.Rotate (theP, theAng); + return aCirc; + } - //! Scales a circle. S is the scaling value. + void Scale (const gp_Pnt2d& theP, const Standard_Real theS); + + //! Scales a circle. theS is the scaling value. //! Warnings : - //! If S is negative the radius stay positive but + //! If theS is negative the radius stay positive but //! the "XAxis" and the "YAxis" are reversed as for //! an ellipse. - Standard_NODISCARD gp_Circ2d Scaled (const gp_Pnt2d& P, const Standard_Real S) const; - - void Transform (const gp_Trsf2d& T); - + Standard_NODISCARD gp_Circ2d Scaled (const gp_Pnt2d& theP, const Standard_Real theS) const; - //! Transforms a circle with the transformation T from class Trsf2d. - Standard_NODISCARD gp_Circ2d Transformed (const gp_Trsf2d& T) const; - - void Translate (const gp_Vec2d& V); - + void Transform (const gp_Trsf2d& theT); - //! Translates a circle in the direction of the vector V. + //! Transforms a circle with the transformation theT from class Trsf2d. + Standard_NODISCARD gp_Circ2d Transformed (const gp_Trsf2d& theT) const; + + void Translate (const gp_Vec2d& theV) { pos.Translate (theV); } + + //! Translates a circle in the direction of the vector theV. //! The magnitude of the translation is the vector's magnitude. - Standard_NODISCARD gp_Circ2d Translated (const gp_Vec2d& V) const; - - void Translate (const gp_Pnt2d& P1, const gp_Pnt2d& P2); - - - //! Translates a circle from the point P1 to the point P2. - Standard_NODISCARD gp_Circ2d Translated (const gp_Pnt2d& P1, const gp_Pnt2d& P2) const; - - - - -protected: - - + Standard_NODISCARD gp_Circ2d Translated (const gp_Vec2d& theV) const + { + gp_Circ2d aCirc = *this; + aCirc.pos.Translate (theV); + return aCirc; + } + void Translate (const gp_Pnt2d& theP1, const gp_Pnt2d& theP2) { pos.Translate (theP1, theP2); } + //! Translates a circle from the point theP1 to the point theP2. + Standard_NODISCARD gp_Circ2d Translated (const gp_Pnt2d& theP1, const gp_Pnt2d& theP2) const + { + gp_Circ2d aCirc = *this; + aCirc.pos.Translate (theP1, theP2); + return aCirc; + } private: - - gp_Ax22d pos; Standard_Real radius; - }; +// ======================================================================= +// function : Coefficients +// purpose : +// ======================================================================= +inline void gp_Circ2d::Coefficients (Standard_Real& theA, + Standard_Real& theB, + Standard_Real& theC, + Standard_Real& theD, + Standard_Real& theE, + Standard_Real& theF) const +{ + Standard_Real aXc = pos.Location().X(); + Standard_Real anYc = pos.Location().Y(); + theA = 1.0; + theB = 1.0; + theC = 0.0; + theD = - aXc; + theE = - anYc; + theF = aXc * aXc + anYc * anYc - radius * radius; +} -#include +// ======================================================================= +// function : Distance +// purpose : +// ======================================================================= +inline Standard_Real gp_Circ2d::Distance (const gp_Pnt2d& theP) const +{ + gp_XY aCoord = theP.XY(); + aCoord.Subtract (pos.Location().XY()); + Standard_Real aD = radius - aCoord.Modulus(); + if (aD < 0) + { + aD = -aD; + } + return aD; +} +// ======================================================================= +// function : Reversed +// purpose : +// ======================================================================= +inline gp_Circ2d gp_Circ2d::Reversed() const +{ + gp_Circ2d aCirc = *this; + gp_Dir2d aTemp = pos.YDirection(); + aTemp.Reverse(); + aCirc.pos.SetAxis (gp_Ax22d(pos.Location(), pos.XDirection(), aTemp)); + return aCirc; +} +// ======================================================================= +// function : SquareDistance +// purpose : +// ======================================================================= +inline Standard_Real gp_Circ2d::SquareDistance (const gp_Pnt2d& theP) const +{ + gp_XY aCoord = theP.XY(); + aCoord.Subtract (pos.Location().XY()); + Standard_Real aD = radius - aCoord.Modulus(); + return aD * aD; +} +// ======================================================================= +// function : Scale +// purpose : +// ======================================================================= +inline void gp_Circ2d::Scale (const gp_Pnt2d& theP, const Standard_Real theS) +{ + radius *= theS; + if (radius < 0) + { + radius = -radius; + } + pos.Scale (theP, theS); +} +// ======================================================================= +// function : Scaled +// purpose : +// ======================================================================= +inline gp_Circ2d gp_Circ2d::Scaled (const gp_Pnt2d& theP, const Standard_Real theS) const +{ + gp_Circ2d aCirc = *this; + aCirc.radius *= theS; + if (aCirc.radius < 0) + { + aCirc.radius = -aCirc.radius; + } + aCirc.pos.Scale (theP, theS); + return aCirc; +} + +// ======================================================================= +// function : Transform +// purpose : +// ======================================================================= +inline void gp_Circ2d::Transform (const gp_Trsf2d& theT) +{ + radius *= theT.ScaleFactor(); + if (radius < 0) + { + radius = -radius; + } + pos.Transform (theT); +} + +// ======================================================================= +// function : Transformed +// purpose : +// ======================================================================= +inline gp_Circ2d gp_Circ2d::Transformed (const gp_Trsf2d& theT) const +{ + gp_Circ2d aCirc = *this; + aCirc.radius *= theT.ScaleFactor(); + if (aCirc.radius < 0) + { + aCirc.radius = -aCirc.radius; + } + aCirc.pos.Transform (theT); + return aCirc; +} #endif // _gp_Circ2d_HeaderFile diff --git a/src/gp/gp_Circ2d.lxx b/src/gp/gp_Circ2d.lxx deleted file mode 100644 index 40aa9587a7..0000000000 --- a/src/gp/gp_Circ2d.lxx +++ /dev/null @@ -1,203 +0,0 @@ -// Copyright (c) 1995-1999 Matra Datavision -// Copyright (c) 1999-2014 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -#include - -inline gp_Circ2d::gp_Circ2d () : radius(RealLast()) -{ } - -inline gp_Circ2d::gp_Circ2d (const gp_Ax2d& XAxis, - const Standard_Real Radius, - const Standard_Boolean Sense) : radius(Radius) -{ - Standard_ConstructionError_Raise_if (Radius < 0.0, "gp_Circ2d() - radius should be positive number"); - pos = gp_Ax22d(XAxis,Sense); -} - -inline gp_Circ2d::gp_Circ2d (const gp_Ax22d& Axis, - const Standard_Real Radius) : - pos(Axis), - radius(Radius) -{ - Standard_ConstructionError_Raise_if (Radius < 0.0, "gp_Circ2d() - radius should be positive number"); -} - -inline void gp_Circ2d::SetLocation (const gp_Pnt2d& P) -{ pos.SetLocation (P); } - -inline void gp_Circ2d::SetXAxis (const gp_Ax2d& A) -{ pos.SetXAxis(A); } - -inline void gp_Circ2d::SetAxis (const gp_Ax22d& A) -{ pos.SetAxis(A);} - -inline void gp_Circ2d::SetYAxis (const gp_Ax2d& A) -{ pos.SetYAxis(A); } - -inline void gp_Circ2d::SetRadius (const Standard_Real Radius) -{ - Standard_ConstructionError_Raise_if (Radius < 0.0, "gp_Circ2d::SetRadius() - radius should be positive number"); - radius = Radius; -} - -inline Standard_Real gp_Circ2d::Area() const -{ return M_PI * radius * radius; } - -inline void gp_Circ2d::Coefficients (Standard_Real& A, - Standard_Real& B, - Standard_Real& C, - Standard_Real& D, - Standard_Real& E, - Standard_Real& F) const -{ - Standard_Real Xc = pos.Location().X(); - Standard_Real Yc = pos.Location().Y(); - A = 1.0; - B = 1.0; - C = 0.0; - D = - Xc; - E = - Yc; - F = Xc * Xc + Yc * Yc - radius * radius; -} - -inline Standard_Boolean gp_Circ2d::Contains -(const gp_Pnt2d& P, - const Standard_Real LinearTolerance) const -{ return Distance(P) <= LinearTolerance; } - -inline Standard_Real gp_Circ2d::Distance (const gp_Pnt2d& P) const -{ - gp_XY Coord = P.XY(); - Coord.Subtract (pos.Location().XY()); - Standard_Real D = radius - Coord.Modulus(); - if (D < 0) D = - D; - return D; -} - -inline Standard_Real gp_Circ2d::SquareDistance (const gp_Pnt2d& P) const -{ - gp_XY Coord = P.XY(); - Coord.Subtract (pos.Location().XY()); - Standard_Real D = radius - Coord.Modulus(); - return D * D; -} - -inline Standard_Real gp_Circ2d::Length() const -{ return 2. * M_PI * radius; } - -inline const gp_Pnt2d& gp_Circ2d::Location () const -{return pos.Location(); } - -inline Standard_Real gp_Circ2d::Radius() const -{ return radius; } - -inline const gp_Ax22d& gp_Circ2d::Axis () const -{ return pos; } - -inline const gp_Ax22d& gp_Circ2d::Position () const -{ return pos; } - -inline gp_Ax2d gp_Circ2d::XAxis () const -{ return gp_Ax2d (pos.XAxis()); } - -inline gp_Ax2d gp_Circ2d::YAxis () const -{ return gp_Ax2d (pos.YAxis()); } - -inline void gp_Circ2d::Reverse() -{ - gp_Dir2d Temp = pos.YDirection (); - Temp.Reverse (); - pos.SetAxis(gp_Ax22d(pos.Location(),pos.XDirection(),Temp)); -} - -inline gp_Circ2d gp_Circ2d::Reversed() const -{ - gp_Circ2d C = *this; - gp_Dir2d Temp = pos.YDirection (); - Temp.Reverse (); - C.pos.SetAxis(gp_Ax22d(pos.Location(),pos.XDirection(),Temp)); - return C; -} - -inline Standard_Boolean gp_Circ2d::IsDirect() const -{ return (pos.XDirection().Crossed(pos.YDirection())) >= 0.0; } - -inline void gp_Circ2d::Rotate (const gp_Pnt2d& P, - const Standard_Real Ang) -{pos.Rotate (P, Ang);} - -inline gp_Circ2d gp_Circ2d::Rotated (const gp_Pnt2d& P, - const Standard_Real Ang) const -{ - gp_Circ2d C = *this; - C.pos.Rotate (P, Ang); - return C; -} - -inline void gp_Circ2d::Scale (const gp_Pnt2d& P, - const Standard_Real S) -{ - radius *= S; - if (radius < 0) radius = - radius; - pos.Scale(P, S); -} - -inline gp_Circ2d gp_Circ2d::Scaled (const gp_Pnt2d& P, - const Standard_Real S) const -{ - gp_Circ2d C = *this; - C.radius *= S; - if (C.radius < 0) C.radius = - C.radius; - C.pos.Scale(P, S); - return C; -} - -inline void gp_Circ2d::Transform (const gp_Trsf2d& T) -{ - radius *= T.ScaleFactor(); - if (radius < 0) radius = - radius; - pos.Transform(T); -} - -inline gp_Circ2d gp_Circ2d::Transformed (const gp_Trsf2d& T) const -{ - gp_Circ2d C = *this; - C.radius *= T.ScaleFactor(); - if (C.radius < 0) C.radius = - C.radius; - C.pos.Transform(T); - return C; -} - -inline void gp_Circ2d::Translate (const gp_Vec2d& V) -{ pos.Translate(V); } - -inline gp_Circ2d gp_Circ2d::Translated (const gp_Vec2d& V) const -{ - gp_Circ2d C = *this; - C.pos.Translate(V); - return C; -} - -inline void gp_Circ2d::Translate (const gp_Pnt2d& P1, - const gp_Pnt2d& P2) -{ pos.Translate(P1, P2); } - -inline gp_Circ2d gp_Circ2d::Translated (const gp_Pnt2d& P1, - const gp_Pnt2d& P2) const -{ - gp_Circ2d C = *this; - C.pos.Translate(P1, P2); - return C; -} - diff --git a/src/gp/gp_Cone.cxx b/src/gp/gp_Cone.cxx index 34b595f686..a213943b8c 100644 --- a/src/gp/gp_Cone.cxx +++ b/src/gp/gp_Cone.cxx @@ -15,10 +15,11 @@ // LPA, JCV 07/92 passage sur C1. // JCV 07/92 Introduction de la method Dump +#include + #include #include #include -#include #include #include #include diff --git a/src/gp/gp_Cone.hxx b/src/gp/gp_Cone.hxx index 4110baed9e..94ab6ed9e9 100644 --- a/src/gp/gp_Cone.hxx +++ b/src/gp/gp_Cone.hxx @@ -15,24 +15,9 @@ #ifndef _gp_Cone_HeaderFile #define _gp_Cone_HeaderFile -#include -#include -#include - -#include -#include -#include -#include #include -class Standard_ConstructionError; -class gp_Ax3; -class gp_Ax1; -class gp_Pnt; -class gp_Ax2; -class gp_Trsf; -class gp_Vec; - - +#include +#include //! Defines an infinite conical surface. //! A cone is defined by its half-angle (can be negative) at the apex and @@ -69,176 +54,272 @@ public: DEFINE_STANDARD_ALLOC - //! Creates an indefinite Cone. - gp_Cone(); - + gp_Cone() + : radius (RealLast()), + semiAngle (M_PI * 0.25) + {} - //! Creates an infinite conical surface. A3 locates the cone + //! Creates an infinite conical surface. theA3 locates the cone //! in the space and defines the reference plane of the surface. //! Ang is the conical surface semi-angle. Its absolute value is in range //! ]0, PI/2[. - //! Radius is the radius of the circle in the reference plane of + //! theRadius is the radius of the circle in the reference plane of //! the cone. - //! Raises ConstructionError - //! * if Radius is lower than 0.0 - //! * Abs(Ang) < Resolution from gp or Abs(Ang) >= (PI/2) - Resolution. - gp_Cone(const gp_Ax3& A3, const Standard_Real Ang, const Standard_Real Radius); - + //! theRaises ConstructionError + //! * if theRadius is lower than 0.0 + //! * Abs(theAng) < Resolution from gp or Abs(theAng) >= (PI/2) - Resolution. + gp_Cone (const gp_Ax3& theA3, const Standard_Real theAng, const Standard_Real theRadius); + //! Changes the symmetry axis of the cone. Raises ConstructionError - //! the direction of A1 is parallel to the "XDirection" + //! the direction of theA1 is parallel to the "XDirection" //! of the coordinate system of the cone. - void SetAxis (const gp_Ax1& A1); - + void SetAxis (const gp_Ax1& theA1) { pos.SetAxis (theA1); } + //! Changes the location of the cone. - void SetLocation (const gp_Pnt& Loc); - + void SetLocation (const gp_Pnt& theLoc) { pos.SetLocation (theLoc); } //! Changes the local coordinate system of the cone. //! This coordinate system defines the reference plane of the cone. - void SetPosition (const gp_Ax3& A3); - + void SetPosition (const gp_Ax3& theA3) { pos = theA3; } //! Changes the radius of the cone in the reference plane of //! the cone. - //! Raised if R < 0.0 - void SetRadius (const Standard_Real R); - + //! Raised if theR < 0.0 + void SetRadius (const Standard_Real theR) + { + Standard_ConstructionError_Raise_if (theR < 0.0, "gp_Cone::SetRadius() - radius should be positive number"); + radius = theR; + } //! Changes the semi-angle of the cone. //! Semi-angle can be negative. Its absolute value - //! Abs(Ang) is in range ]0,PI/2[. - //! Raises ConstructionError if Abs(Ang) < Resolution from gp or Abs(Ang) >= PI/2 - Resolution - void SetSemiAngle (const Standard_Real Ang); - + //! Abs(theAng) is in range ]0,PI/2[. + //! Raises ConstructionError if Abs(theAng) < Resolution from gp or Abs(theAng) >= PI/2 - Resolution + void SetSemiAngle (const Standard_Real theAng); //! Computes the cone's top. The Apex of the cone is on the //! negative side of the symmetry axis of the cone. - gp_Pnt Apex() const; - + gp_Pnt Apex() const + { + gp_XYZ aCoord = pos.Direction().XYZ(); + aCoord.Multiply (-radius / Tan (semiAngle)); + aCoord.Add (pos.Location().XYZ()); + return gp_Pnt (aCoord); + } + //! Reverses the U parametrization of the cone //! reversing the YAxis. - void UReverse(); - + void UReverse() { pos.YReverse(); } + //! Reverses the V parametrization of the cone reversing the ZAxis. - void VReverse(); - + void VReverse() + { + pos.ZReverse(); + semiAngle = -semiAngle; + } + //! Returns true if the local coordinate system of this cone is right-handed. - Standard_Boolean Direct() const; - + Standard_Boolean Direct() const { return pos.Direct(); } + //! returns the symmetry axis of the cone. - const gp_Ax1& Axis() const; - + const gp_Ax1& Axis() const { return pos.Axis(); } //! Computes the coefficients of the implicit equation of the quadric //! in the absolute cartesian coordinates system : - //! A1.X**2 + A2.Y**2 + A3.Z**2 + 2.(B1.X.Y + B2.X.Z + B3.Y.Z) + - //! 2.(C1.X + C2.Y + C3.Z) + D = 0.0 - Standard_EXPORT void Coefficients (Standard_Real& A1, Standard_Real& A2, Standard_Real& A3, Standard_Real& B1, Standard_Real& B2, Standard_Real& B3, Standard_Real& C1, Standard_Real& C2, Standard_Real& C3, Standard_Real& D) const; - + //! theA1.X**2 + theA2.Y**2 + theA3.Z**2 + 2.(theB1.X.Y + theB2.X.Z + theB3.Y.Z) + + //! 2.(theC1.X + theC2.Y + theC3.Z) + theD = 0.0 + Standard_EXPORT void Coefficients (Standard_Real& theA1, Standard_Real& theA2, Standard_Real& theA3, + Standard_Real& theB1, Standard_Real& theB2, Standard_Real& theB3, + Standard_Real& theC1, Standard_Real& theC2, Standard_Real& theC3, Standard_Real& theD) const; + //! returns the "Location" point of the cone. - const gp_Pnt& Location() const; - + const gp_Pnt& Location() const { return pos.Location(); } //! Returns the local coordinates system of the cone. - const gp_Ax3& Position() const; - + const gp_Ax3& Position() const { return pos; } //! Returns the radius of the cone in the reference plane. - Standard_Real RefRadius() const; - + Standard_Real RefRadius() const { return radius; } + //! Returns the half-angle at the apex of this cone. //! Attention! Semi-angle can be negative. - Standard_Real SemiAngle() const; - + Standard_Real SemiAngle() const { return semiAngle; } + //! Returns the XAxis of the reference plane. - gp_Ax1 XAxis() const; - + gp_Ax1 XAxis() const { return gp_Ax1 (pos.Location(), pos.XDirection()); } + //! Returns the YAxis of the reference plane. - gp_Ax1 YAxis() const; - - Standard_EXPORT void Mirror (const gp_Pnt& P); - + gp_Ax1 YAxis() const { return gp_Ax1 (pos.Location(), pos.YDirection()); } + + Standard_EXPORT void Mirror (const gp_Pnt& theP); //! Performs the symmetrical transformation of a cone - //! with respect to the point P which is the center of the + //! with respect to the point theP which is the center of the //! symmetry. - Standard_NODISCARD Standard_EXPORT gp_Cone Mirrored (const gp_Pnt& P) const; - - Standard_EXPORT void Mirror (const gp_Ax1& A1); - + Standard_NODISCARD Standard_EXPORT gp_Cone Mirrored (const gp_Pnt& theP) const; + + Standard_EXPORT void Mirror (const gp_Ax1& theA1); //! Performs the symmetrical transformation of a cone with //! respect to an axis placement which is the axis of the //! symmetry. - Standard_NODISCARD Standard_EXPORT gp_Cone Mirrored (const gp_Ax1& A1) const; - - Standard_EXPORT void Mirror (const gp_Ax2& A2); - + Standard_NODISCARD Standard_EXPORT gp_Cone Mirrored (const gp_Ax1& theA1) const; + + Standard_EXPORT void Mirror (const gp_Ax2& theA2); //! Performs the symmetrical transformation of a cone with respect - //! to a plane. The axis placement A2 locates the plane of the + //! to a plane. The axis placement theA2 locates the plane of the //! of the symmetry : (Location, XDirection, YDirection). - Standard_NODISCARD Standard_EXPORT gp_Cone Mirrored (const gp_Ax2& A2) const; - - void Rotate (const gp_Ax1& A1, const Standard_Real Ang); - + Standard_NODISCARD Standard_EXPORT gp_Cone Mirrored (const gp_Ax2& theA2) const; - //! Rotates a cone. A1 is the axis of the rotation. + void Rotate (const gp_Ax1& theA1, const Standard_Real theAng) { pos.Rotate (theA1, theAng); } + + //! Rotates a cone. theA1 is the axis of the rotation. //! Ang is the angular value of the rotation in radians. - Standard_NODISCARD gp_Cone Rotated (const gp_Ax1& A1, const Standard_Real Ang) const; - - void Scale (const gp_Pnt& P, const Standard_Real S); - + Standard_NODISCARD gp_Cone Rotated (const gp_Ax1& theA1, const Standard_Real theAng) const + { + gp_Cone aCone = *this; + aCone.pos.Rotate (theA1, theAng); + return aCone; + } - //! Scales a cone. S is the scaling value. - //! The absolute value of S is used to scale the cone - Standard_NODISCARD gp_Cone Scaled (const gp_Pnt& P, const Standard_Real S) const; - - void Transform (const gp_Trsf& T); - + void Scale (const gp_Pnt& theP, const Standard_Real theS); - //! Transforms a cone with the transformation T from class Trsf. - Standard_NODISCARD gp_Cone Transformed (const gp_Trsf& T) const; - - void Translate (const gp_Vec& V); - + //! Scales a cone. theS is the scaling value. + //! The absolute value of theS is used to scale the cone + Standard_NODISCARD gp_Cone Scaled (const gp_Pnt& theP, const Standard_Real theS) const; - //! Translates a cone in the direction of the vector V. + void Transform (const gp_Trsf& theT); + + //! Transforms a cone with the transformation theT from class Trsf. + Standard_NODISCARD gp_Cone Transformed (const gp_Trsf& theT) const; + + void Translate (const gp_Vec& theV) { pos.Translate (theV); } + + //! Translates a cone in the direction of the vector theV. //! The magnitude of the translation is the vector's magnitude. - Standard_NODISCARD gp_Cone Translated (const gp_Vec& V) const; - - void Translate (const gp_Pnt& P1, const gp_Pnt& P2); - + Standard_NODISCARD gp_Cone Translated (const gp_Vec& theV) const + { + gp_Cone aCone = *this; + aCone.pos.Translate (theV); + return aCone; + } + + void Translate (const gp_Pnt& theP1, const gp_Pnt& theP2) { pos.Translate (theP1, theP2); } //! Translates a cone from the point P1 to the point P2. - Standard_NODISCARD gp_Cone Translated (const gp_Pnt& P1, const gp_Pnt& P2) const; - - - - -protected: - - - - + Standard_NODISCARD gp_Cone Translated (const gp_Pnt& theP1, const gp_Pnt& theP2) const + { + gp_Cone aCone = *this; + aCone.pos.Translate (theP1, theP2); + return aCone; + } private: - - gp_Ax3 pos; Standard_Real radius; Standard_Real semiAngle; - }; +// ======================================================================= +// function : gp_Cone +// purpose : +// ======================================================================= +inline gp_Cone::gp_Cone (const gp_Ax3& theA3, + const Standard_Real theAng, + const Standard_Real theRadius) +: pos (theA3), + radius (theRadius), + semiAngle (theAng) +{ + Standard_Real aVal = theAng; + if (aVal < 0) + { + aVal = -aVal; + } + Standard_ConstructionError_Raise_if (theRadius < 0. || aVal <= gp::Resolution() || M_PI * 0.5 - aVal <= gp::Resolution(), + "gp_Cone() - invalid construction parameters"); +} -#include +// ======================================================================= +// function : SetSemiAngle +// purpose : +// ======================================================================= +inline void gp_Cone::SetSemiAngle (const Standard_Real theAng) +{ + Standard_Real aVal = theAng; + if (aVal < 0) + { + aVal = -aVal; + } + Standard_ConstructionError_Raise_if (aVal <= gp::Resolution() || M_PI * 0.5 - aVal <= gp::Resolution(), + "gp_Cone::SetSemiAngle() - invalid angle range"); + semiAngle = theAng; +} +// ======================================================================= +// function : Scale +// purpose : +// ======================================================================= +inline void gp_Cone::Scale (const gp_Pnt& theP, + const Standard_Real theS) +{ + pos.Scale (theP, theS); + radius *= theS; + if (radius < 0) + { + radius = -radius; + } +} +// ======================================================================= +// function : Scaled +// purpose : +// ======================================================================= +inline gp_Cone gp_Cone::Scaled (const gp_Pnt& theP, + const Standard_Real theS) const +{ + gp_Cone aC = *this; + aC.pos.Scale (theP, theS); + aC.radius *= theS; + if (aC.radius < 0) + { + aC.radius = -aC.radius; + } + return aC; +} +// ======================================================================= +// function : Transform +// purpose : +// ======================================================================= +inline void gp_Cone::Transform (const gp_Trsf& theT) +{ + pos.Transform (theT); + radius *= theT.ScaleFactor(); + if (radius < 0) + { + radius = -radius; + } +} +// ======================================================================= +// function : Transformed +// purpose : +// ======================================================================= +inline gp_Cone gp_Cone::Transformed (const gp_Trsf& theT) const +{ + gp_Cone aC = *this; + aC.pos.Transform (theT); + aC.radius *= theT.ScaleFactor(); + if (aC.radius < 0) + { + aC.radius = -aC.radius; + } + return aC; +} #endif // _gp_Cone_HeaderFile diff --git a/src/gp/gp_Cone.lxx b/src/gp/gp_Cone.lxx deleted file mode 100644 index 3a73a727ed..0000000000 --- a/src/gp/gp_Cone.lxx +++ /dev/null @@ -1,168 +0,0 @@ -// Copyright (c) 1995-1999 Matra Datavision -// Copyright (c) 1999-2014 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -#include -#include - -inline gp_Cone::gp_Cone () : -radius (RealLast()), -semiAngle (M_PI * 0.25) -{ } - -inline gp_Cone::gp_Cone (const gp_Ax3& A3, - const Standard_Real Ang, - const Standard_Real Radius) : - pos(A3), - radius (Radius), - semiAngle (Ang) -{ - Standard_Real val = Ang; - if (val < 0) val = - val; - Standard_ConstructionError_Raise_if - (radius < 0. || - val <= gp::Resolution() || - M_PI * 0.5 - val <= gp::Resolution(), "gp_Cone() - invalid construction parameters"); -} - -inline void gp_Cone::SetAxis (const gp_Ax1& A1) -{ pos.SetAxis (A1); } - -inline void gp_Cone::SetLocation (const gp_Pnt& Loc) -{ pos.SetLocation (Loc); } - -inline void gp_Cone::SetPosition (const gp_Ax3& A3) -{ pos = A3; } - -inline void gp_Cone::SetRadius (const Standard_Real R) -{ - Standard_ConstructionError_Raise_if (R < 0.0, "gp_Cone::SetRadius() - radius should be positive number"); - radius = R; -} - -inline void gp_Cone::SetSemiAngle (const Standard_Real Ang) -{ - Standard_Real val = Ang; - if (val < 0) val = - val; - Standard_ConstructionError_Raise_if - (val <= gp::Resolution() || - M_PI * 0.5 - val <= gp::Resolution(), "gp_Cone::SetSemiAngle() - invalid angle range"); - semiAngle = Ang; -} - -inline gp_Pnt gp_Cone::Apex () const -{ - gp_XYZ Coord = pos.Direction ().XYZ (); - Coord.Multiply (-radius / Tan (semiAngle)); - Coord.Add (pos.Location ().XYZ()); - return gp_Pnt (Coord); -} - -inline void gp_Cone::UReverse() -{ pos.YReverse(); } - -inline void gp_Cone::VReverse() -{ pos.ZReverse(); semiAngle = -semiAngle; } - -inline Standard_Boolean gp_Cone::Direct() const -{ return pos.Direct(); } - -inline const gp_Ax1& gp_Cone::Axis () const -{ return pos.Axis(); } - -inline const gp_Pnt& gp_Cone::Location () const -{ return pos.Location(); } - -inline const gp_Ax3& gp_Cone::Position () const -{ return pos; } - -inline Standard_Real gp_Cone::RefRadius () const -{ return radius; } - -inline Standard_Real gp_Cone::SemiAngle () const -{ return semiAngle; } - -inline gp_Ax1 gp_Cone::XAxis () const -{ return gp_Ax1 (pos.Location(), pos.XDirection()); } - -inline gp_Ax1 gp_Cone::YAxis () const -{ return gp_Ax1 (pos.Location(), pos.YDirection()); } - -inline void gp_Cone::Rotate (const gp_Ax1& A1, - const Standard_Real Ang) -{pos.Rotate (A1, Ang);} - -inline gp_Cone gp_Cone::Rotated (const gp_Ax1& A1, - const Standard_Real Ang) const -{ - gp_Cone C = *this; - C.pos.Rotate (A1, Ang); - return C; -} - -inline void gp_Cone::Scale (const gp_Pnt& P, - const Standard_Real S) -{ - pos.Scale (P, S); - radius *= S; - if (radius < 0) radius = - radius; -} - -inline gp_Cone gp_Cone::Scaled (const gp_Pnt& P, - const Standard_Real S) const -{ - gp_Cone C = *this; - C.pos.Scale (P, S); - C.radius *= S; - if (C.radius < 0) C.radius = - C.radius; - return C; -} - -inline void gp_Cone::Transform (const gp_Trsf& T) -{ - pos.Transform (T); - radius *= T.ScaleFactor(); - if (radius < 0) radius = - radius; -} - -inline gp_Cone gp_Cone::Transformed (const gp_Trsf& T) const -{ - gp_Cone C = *this; - C.pos.Transform (T); - C.radius *= T.ScaleFactor(); - if (C.radius < 0) C.radius = - C.radius; - return C; -} - -inline void gp_Cone::Translate (const gp_Vec& V) -{ pos.Translate (V); } - -inline gp_Cone gp_Cone::Translated (const gp_Vec& V) const -{ - gp_Cone C = *this; - C.pos.Translate (V); - return C; -} - -inline void gp_Cone::Translate (const gp_Pnt& P1, - const gp_Pnt& P2) -{ pos.Translate (P1, P2); } - -inline gp_Cone gp_Cone::Translated (const gp_Pnt& P1, - const gp_Pnt& P2) const -{ - gp_Cone C = *this; - C.pos.Translate (P1, P2); - return C; -} - diff --git a/src/gp/gp_Cylinder.cxx b/src/gp/gp_Cylinder.cxx index ac15a57a75..2511c7f209 100644 --- a/src/gp/gp_Cylinder.cxx +++ b/src/gp/gp_Cylinder.cxx @@ -16,10 +16,11 @@ // JCV 07/92 Introduction de la method Dump // LBO 08/93 passage aux Ax3 +#include + #include #include #include -#include #include #include #include diff --git a/src/gp/gp_Cylinder.hxx b/src/gp/gp_Cylinder.hxx index fb5aaedb8c..3cf992bf38 100644 --- a/src/gp/gp_Cylinder.hxx +++ b/src/gp/gp_Cylinder.hxx @@ -15,23 +15,8 @@ #ifndef _gp_Cylinder_HeaderFile #define _gp_Cylinder_HeaderFile -#include -#include -#include - -#include -#include -#include #include -class Standard_ConstructionError; -class gp_Ax3; -class gp_Ax1; -class gp_Pnt; -class gp_Ax2; -class gp_Trsf; -class gp_Vec; - - +#include //! Describes an infinite cylindrical surface. //! A cylinder is defined by its radius and positioned in space @@ -59,147 +44,203 @@ public: DEFINE_STANDARD_ALLOC - //! Creates a indefinite cylinder. - gp_Cylinder(); - + gp_Cylinder() { radius = RealLast(); } + //! Creates a cylinder of radius Radius, whose axis is the "main - //! Axis" of A3. A3 is the local coordinate system of the cylinder. Raises ConstructionErrord if R < 0.0 - gp_Cylinder(const gp_Ax3& A3, const Standard_Real Radius); - - //! Changes the symmetry axis of the cylinder. Raises ConstructionError if the direction of A1 is parallel to the "XDirection" + //! Axis" of theA3. theA3 is the local coordinate system of the cylinder. Raises ConstructionErrord if theRadius < 0.0 + gp_Cylinder (const gp_Ax3& theA3, const Standard_Real theRadius) + : pos (theA3), + radius (theRadius) + { + Standard_ConstructionError_Raise_if (theRadius < 0.0, "gp_Cylinder() - radius should be positive number"); + } + + //! Changes the symmetry axis of the cylinder. Raises ConstructionError if the direction of theA1 is parallel to the "XDirection" //! of the coordinate system of the cylinder. - void SetAxis (const gp_Ax1& A1); - + void SetAxis (const gp_Ax1& theA1) { pos.SetAxis (theA1); } + //! Changes the location of the surface. - void SetLocation (const gp_Pnt& Loc); - + void SetLocation (const gp_Pnt& theLoc) { pos.SetLocation (theLoc); } + //! Change the local coordinate system of the surface. - void SetPosition (const gp_Ax3& A3); - + void SetPosition (const gp_Ax3& theA3) { pos = theA3; } + //! Modifies the radius of this cylinder. //! Exceptions - //! Standard_ConstructionError if R is negative. - void SetRadius (const Standard_Real R); - + //! Standard_ConstructionError if theR is negative. + void SetRadius (const Standard_Real theR) + { + Standard_ConstructionError_Raise_if (theR < 0.0, "gp_Cylinder::SetRadius() - radius should be positive number"); + radius = theR; + } + //! Reverses the U parametrization of the cylinder //! reversing the YAxis. - void UReverse(); - + void UReverse() { pos.YReverse(); } + //! Reverses the V parametrization of the plane //! reversing the Axis. - void VReverse(); - + void VReverse() { pos.ZReverse(); } + //! Returns true if the local coordinate system of this cylinder is right-handed. - Standard_Boolean Direct() const; - + Standard_Boolean Direct() const { return pos.Direct(); } + //! Returns the symmetry axis of the cylinder. - const gp_Ax1& Axis() const; - + const gp_Ax1& Axis() const { return pos.Axis(); } //! Computes the coefficients of the implicit equation of the quadric //! in the absolute cartesian coordinate system : - //! A1.X**2 + A2.Y**2 + A3.Z**2 + 2.(B1.X.Y + B2.X.Z + B3.Y.Z) + - //! 2.(C1.X + C2.Y + C3.Z) + D = 0.0 - Standard_EXPORT void Coefficients (Standard_Real& A1, Standard_Real& A2, Standard_Real& A3, Standard_Real& B1, Standard_Real& B2, Standard_Real& B3, Standard_Real& C1, Standard_Real& C2, Standard_Real& C3, Standard_Real& D) const; - + //! theA1.X**2 + theA2.Y**2 + theA3.Z**2 + 2.(theB1.X.Y + theB2.X.Z + theB3.Y.Z) + + //! 2.(theC1.X + theC2.Y + theC3.Z) + theD = 0.0 + Standard_EXPORT void Coefficients (Standard_Real& theA1, Standard_Real& theA2, Standard_Real& theA3, + Standard_Real& theB1, Standard_Real& theB2, Standard_Real& theB3, + Standard_Real& theC1, Standard_Real& theC2, Standard_Real& theC3, Standard_Real& theD) const; + //! Returns the "Location" point of the cylinder. - const gp_Pnt& Location() const; - + const gp_Pnt& Location() const { return pos.Location(); } //! Returns the local coordinate system of the cylinder. - const gp_Ax3& Position() const; - + const gp_Ax3& Position() const { return pos; } + //! Returns the radius of the cylinder. - Standard_Real Radius() const; - + Standard_Real Radius() const { return radius; } + //! Returns the axis X of the cylinder. - gp_Ax1 XAxis() const; - + gp_Ax1 XAxis() const { return gp_Ax1 (pos.Location(), pos.XDirection()); } + //! Returns the axis Y of the cylinder. - gp_Ax1 YAxis() const; - - Standard_EXPORT void Mirror (const gp_Pnt& P); - + gp_Ax1 YAxis() const { return gp_Ax1 (pos.Location(), pos.YDirection()); } + + Standard_EXPORT void Mirror (const gp_Pnt& theP); //! Performs the symmetrical transformation of a cylinder - //! with respect to the point P which is the center of the + //! with respect to the point theP which is the center of the //! symmetry. - Standard_NODISCARD Standard_EXPORT gp_Cylinder Mirrored (const gp_Pnt& P) const; - - Standard_EXPORT void Mirror (const gp_Ax1& A1); - + Standard_NODISCARD Standard_EXPORT gp_Cylinder Mirrored (const gp_Pnt& theP) const; + + Standard_EXPORT void Mirror (const gp_Ax1& theA1); //! Performs the symmetrical transformation of a cylinder with //! respect to an axis placement which is the axis of the //! symmetry. - Standard_NODISCARD Standard_EXPORT gp_Cylinder Mirrored (const gp_Ax1& A1) const; - - Standard_EXPORT void Mirror (const gp_Ax2& A2); - + Standard_NODISCARD Standard_EXPORT gp_Cylinder Mirrored (const gp_Ax1& theA1) const; + + Standard_EXPORT void Mirror (const gp_Ax2& theA2); //! Performs the symmetrical transformation of a cylinder with respect - //! to a plane. The axis placement A2 locates the plane of the + //! to a plane. The axis placement theA2 locates the plane of the //! of the symmetry : (Location, XDirection, YDirection). - Standard_NODISCARD Standard_EXPORT gp_Cylinder Mirrored (const gp_Ax2& A2) const; - - void Rotate (const gp_Ax1& A1, const Standard_Real Ang); - + Standard_NODISCARD Standard_EXPORT gp_Cylinder Mirrored (const gp_Ax2& theA2) const; - //! Rotates a cylinder. A1 is the axis of the rotation. - //! Ang is the angular value of the rotation in radians. - Standard_NODISCARD gp_Cylinder Rotated (const gp_Ax1& A1, const Standard_Real Ang) const; - - void Scale (const gp_Pnt& P, const Standard_Real S); - + void Rotate (const gp_Ax1& theA1, const Standard_Real theAng) { pos.Rotate (theA1, theAng); } - //! Scales a cylinder. S is the scaling value. - //! The absolute value of S is used to scale the cylinder - Standard_NODISCARD gp_Cylinder Scaled (const gp_Pnt& P, const Standard_Real S) const; - - void Transform (const gp_Trsf& T); - + //! Rotates a cylinder. theA1 is the axis of the rotation. + //! theAng is the angular value of the rotation in radians. + Standard_NODISCARD gp_Cylinder Rotated (const gp_Ax1& theA1, const Standard_Real theAng) const + { + gp_Cylinder aCyl = *this; + aCyl.pos.Rotate (theA1, theAng); + return aCyl; + } - //! Transforms a cylinder with the transformation T from class Trsf. - Standard_NODISCARD gp_Cylinder Transformed (const gp_Trsf& T) const; - - void Translate (const gp_Vec& V); - + void Scale (const gp_Pnt& theP, const Standard_Real theS); - //! Translates a cylinder in the direction of the vector V. + //! Scales a cylinder. theS is the scaling value. + //! The absolute value of theS is used to scale the cylinder + Standard_NODISCARD gp_Cylinder Scaled (const gp_Pnt& theP, const Standard_Real theS) const; + + void Transform (const gp_Trsf& theT); + + //! Transforms a cylinder with the transformation theT from class Trsf. + Standard_NODISCARD gp_Cylinder Transformed (const gp_Trsf& theT) const; + + void Translate (const gp_Vec& theV) { pos.Translate (theV); } + + //! Translates a cylinder in the direction of the vector theV. //! The magnitude of the translation is the vector's magnitude. - Standard_NODISCARD gp_Cylinder Translated (const gp_Vec& V) const; - - void Translate (const gp_Pnt& P1, const gp_Pnt& P2); - - - //! Translates a cylinder from the point P1 to the point P2. - Standard_NODISCARD gp_Cylinder Translated (const gp_Pnt& P1, const gp_Pnt& P2) const; - - - - -protected: - - + Standard_NODISCARD gp_Cylinder Translated (const gp_Vec& theV) const + { + gp_Cylinder aCyl = *this; + aCyl.pos.Translate (theV); + return aCyl; + } + void Translate (const gp_Pnt& theP1, const gp_Pnt& theP2) { pos.Translate (theP1, theP2); } + //! Translates a cylinder from the point theP1 to the point theP2. + Standard_NODISCARD gp_Cylinder Translated (const gp_Pnt& theP1, const gp_Pnt& theP2) const + { + gp_Cylinder aCyl = *this; + aCyl.pos.Translate (theP1, theP2); + return aCyl; + } private: - - gp_Ax3 pos; Standard_Real radius; - }; +// ======================================================================= +// function : Scale +// purpose : +// ======================================================================= +inline void gp_Cylinder::Scale (const gp_Pnt& theP, const Standard_Real theS) +{ + pos.Scale (theP, theS); + radius *= theS; + if (radius < 0) + { + radius = -radius; + } +} -#include - - +// ======================================================================= +// function : Scaled +// purpose : +// ======================================================================= +inline gp_Cylinder gp_Cylinder::Scaled (const gp_Pnt& theP, const Standard_Real theS) const +{ + gp_Cylinder aCyl = *this; + aCyl.pos.Scale (theP, theS); + aCyl.radius *= theS; + if (aCyl.radius < 0) + { + aCyl.radius = -aCyl.radius; + } + return aCyl; +} +// ======================================================================= +// function : Transform +// purpose : +// ======================================================================= +inline void gp_Cylinder::Transform (const gp_Trsf& theT) +{ + pos.Transform (theT); + radius *= theT.ScaleFactor(); + if (radius < 0) + { + radius = -radius; + } +} +// ======================================================================= +// function : Transformed +// purpose : +// ======================================================================= +inline gp_Cylinder gp_Cylinder::Transformed (const gp_Trsf& theT) const +{ + gp_Cylinder aCyl = *this; + aCyl.pos.Transform (theT); + aCyl.radius *= theT.ScaleFactor(); + if (aCyl.radius < 0) + { + aCyl.radius = -aCyl.radius; + } + return aCyl; +} #endif // _gp_Cylinder_HeaderFile diff --git a/src/gp/gp_Cylinder.lxx b/src/gp/gp_Cylinder.lxx deleted file mode 100644 index 6201bbf362..0000000000 --- a/src/gp/gp_Cylinder.lxx +++ /dev/null @@ -1,136 +0,0 @@ -// Copyright (c) 1995-1999 Matra Datavision -// Copyright (c) 1999-2014 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -#include - -inline gp_Cylinder::gp_Cylinder () -{ radius = RealLast(); } - -inline gp_Cylinder::gp_Cylinder (const gp_Ax3& A3, - const Standard_Real Radius) : - pos(A3), - radius (Radius) -{ - Standard_ConstructionError_Raise_if (Radius < 0.0, "gp_Cylinder() - radius should be positive number"); -} - -inline void gp_Cylinder::SetAxis (const gp_Ax1& A1) -{ pos.SetAxis (A1); } - -inline void gp_Cylinder::SetLocation (const gp_Pnt& Loc) -{ pos.SetLocation (Loc); } - -inline void gp_Cylinder::SetPosition (const gp_Ax3& A3) -{ pos = A3; } - -inline void gp_Cylinder::SetRadius (const Standard_Real R) -{ - Standard_ConstructionError_Raise_if (R < 0.0, "gp_Cylinder::SetRadius() - radius should be positive number"); - radius = R; -} - -inline void gp_Cylinder::UReverse() -{ pos.YReverse(); } - -inline void gp_Cylinder::VReverse() -{ pos.ZReverse(); } - -inline Standard_Boolean gp_Cylinder::Direct() const -{ return pos.Direct(); } - -inline const gp_Ax1& gp_Cylinder::Axis () const -{ return pos.Axis(); } - -inline const gp_Pnt& gp_Cylinder::Location () const -{ return pos.Location(); } - -inline const gp_Ax3& gp_Cylinder::Position () const -{ return pos; } - -inline Standard_Real gp_Cylinder::Radius () const -{ return radius; } - -inline gp_Ax1 gp_Cylinder::XAxis () const -{return gp_Ax1(pos.Location(), pos.XDirection());} - -inline gp_Ax1 gp_Cylinder::YAxis () const -{return gp_Ax1(pos.Location(), pos.YDirection());} - -inline void gp_Cylinder::Rotate (const gp_Ax1& A1, - const Standard_Real Ang) -{pos.Rotate(A1,Ang);} - -inline gp_Cylinder gp_Cylinder::Rotated (const gp_Ax1& A1, - const Standard_Real Ang) const -{ - gp_Cylinder C = *this; - C.pos.Rotate (A1, Ang); - return C; -} - -inline void gp_Cylinder::Scale (const gp_Pnt& P, const Standard_Real S) -{ - pos.Scale (P, S); - radius *= S; - if (radius < 0) radius = - radius; -} - -inline gp_Cylinder gp_Cylinder::Scaled (const gp_Pnt& P, - const Standard_Real S) const -{ - gp_Cylinder C = *this; - C.pos.Scale (P, S); - C.radius *= S; - if (C.radius < 0) C.radius = - C.radius; - return C; -} - -inline void gp_Cylinder::Transform (const gp_Trsf& T) -{ - pos.Transform (T); - radius *= T.ScaleFactor(); - if (radius < 0) radius = - radius; -} - -inline gp_Cylinder gp_Cylinder::Transformed (const gp_Trsf& T) const -{ - gp_Cylinder C = *this; - C.pos.Transform (T); - C.radius *= T.ScaleFactor(); - if (C.radius < 0) C.radius = - C.radius; - return C; -} - -inline void gp_Cylinder::Translate (const gp_Vec& V) -{ pos.Translate (V); } - -inline gp_Cylinder gp_Cylinder::Translated (const gp_Vec& V) const -{ - gp_Cylinder C = *this; - C.pos.Translate (V); - return C; -} - -inline void gp_Cylinder::Translate (const gp_Pnt& P1, - const gp_Pnt& P2) -{ pos.Translate (P1, P2); } - -inline gp_Cylinder gp_Cylinder::Translated (const gp_Pnt& P1, - const gp_Pnt& P2) const -{ - gp_Cylinder C = *this; - C.pos.Translate (P1, P2); - return C; -} - diff --git a/src/gp/gp_Dir.cxx b/src/gp/gp_Dir.cxx index 3dfb999b2d..1f18618551 100644 --- a/src/gp/gp_Dir.cxx +++ b/src/gp/gp_Dir.cxx @@ -14,9 +14,10 @@ // JCV 07/12/90 Modifs suite a l'introduction des classes XYZ et Mat dans gp +#include + #include #include -#include #include #include #include diff --git a/src/gp/gp_Dir.hxx b/src/gp/gp_Dir.hxx index a6215b29e3..37b6e7b231 100644 --- a/src/gp/gp_Dir.hxx +++ b/src/gp/gp_Dir.hxx @@ -15,25 +15,16 @@ #ifndef _gp_Dir_HeaderFile #define _gp_Dir_HeaderFile -#include -#include -#include - #include -#include -#include -#include -class Standard_ConstructionError; -class Standard_DomainError; -class Standard_OutOfRange; +#include +#include +#include + class gp_Vec; -class gp_XYZ; class gp_Ax1; class gp_Ax2; class gp_Trsf; - - //! Describes a unit vector in 3D space. This unit vector is also called "Direction". //! See Also //! gce_MakeDir which provides functions for more complex @@ -47,221 +38,235 @@ public: DEFINE_STANDARD_ALLOC - //! Creates a direction corresponding to X axis. - gp_Dir(); - - //! Normalizes the vector V and creates a direction. Raises ConstructionError if V.Magnitude() <= Resolution. - gp_Dir(const gp_Vec& V); - - //! Creates a direction from a triplet of coordinates. Raises ConstructionError if Coord.Modulus() <= Resolution from gp. - gp_Dir(const gp_XYZ& Coord); - - //! Creates a direction with its 3 cartesian coordinates. Raises ConstructionError if Sqrt(Xv*Xv + Yv*Yv + Zv*Zv) <= Resolution + gp_Dir() + : coord (1., 0., 0.) + {} + + //! Normalizes the vector theV and creates a direction. Raises ConstructionError if theV.Magnitude() <= Resolution. + gp_Dir (const gp_Vec& theV); + + //! Creates a direction from a triplet of coordinates. Raises ConstructionError if theCoord.Modulus() <= Resolution from gp. + gp_Dir (const gp_XYZ& theCoord); + + //! Creates a direction with its 3 cartesian coordinates. Raises ConstructionError if Sqrt(theXv*theXv + theYv*theYv + theZv*theZv) <= Resolution //! Modification of the direction's coordinates - //! If Sqrt (X*X + Y*Y + Z*Z) <= Resolution from gp where - //! X, Y ,Z are the new coordinates it is not possible to + //! If Sqrt (theXv*theXv + theYv*theYv + theZv*theZv) <= Resolution from gp where + //! theXv, theYv ,theZv are the new coordinates it is not possible to //! construct the direction and the method raises the //! exception ConstructionError. - gp_Dir(const Standard_Real Xv, const Standard_Real Yv, const Standard_Real Zv); - + gp_Dir (const Standard_Real theXv, const Standard_Real theYv, const Standard_Real theZv); //! For this unit vector, assigns the value Xi to: - //! - the X coordinate if Index is 1, or - //! - the Y coordinate if Index is 2, or - //! - the Z coordinate if Index is 3, + //! - the X coordinate if theIndex is 1, or + //! - the Y coordinate if theIndex is 2, or + //! - the Z coordinate if theIndex is 3, //! and then normalizes it. //! Warning //! Remember that all the coordinates of a unit vector are //! implicitly modified when any single one is changed directly. //! Exceptions - //! Standard_OutOfRange if Index is not 1, 2, or 3. + //! Standard_OutOfRange if theIndex is not 1, 2, or 3. //! Standard_ConstructionError if either of the following //! is less than or equal to gp::Resolution(): //! - Sqrt(Xv*Xv + Yv*Yv + Zv*Zv), or //! - the modulus of the number triple formed by the new - //! value Xi and the two other coordinates of this vector + //! value theXi and the two other coordinates of this vector //! that were not directly modified. - void SetCoord (const Standard_Integer Index, const Standard_Real Xi); - - //! For this unit vector, assigns the values Xv, Yv and Zv to its three coordinates. + void SetCoord (const Standard_Integer theIndex, const Standard_Real theXi); + + //! For this unit vector, assigns the values theXv, theYv and theZv to its three coordinates. //! Remember that all the coordinates of a unit vector are //! implicitly modified when any single one is changed directly. - void SetCoord (const Standard_Real Xv, const Standard_Real Yv, const Standard_Real Zv); - - //! Assigns the given value to the X coordinate of this unit vector. - void SetX (const Standard_Real X); - - //! Assigns the given value to the Y coordinate of this unit vector. - void SetY (const Standard_Real Y); - - //! Assigns the given value to the Z coordinate of this unit vector. - void SetZ (const Standard_Real Z); - - //! Assigns the three coordinates of Coord to this unit vector. - void SetXYZ (const gp_XYZ& Coord); - + void SetCoord (const Standard_Real theXv, const Standard_Real theYv, const Standard_Real theZv); - //! Returns the coordinate of range Index : - //! Index = 1 => X is returned - //! Index = 2 => Y is returned - //! Index = 3 => Z is returned + //! Assigns the given value to the X coordinate of this unit vector. + void SetX (const Standard_Real theX); + + //! Assigns the given value to the Y coordinate of this unit vector. + void SetY (const Standard_Real theY); + + //! Assigns the given value to the Z coordinate of this unit vector. + void SetZ (const Standard_Real theZ); + + //! Assigns the three coordinates of theCoord to this unit vector. + void SetXYZ (const gp_XYZ& theCoord); + + //! Returns the coordinate of range theIndex : + //! theIndex = 1 => X is returned + //! Ithendex = 2 => Y is returned + //! theIndex = 3 => Z is returned //! Exceptions - //! Standard_OutOfRange if Index is not 1, 2, or 3. - Standard_Real Coord (const Standard_Integer Index) const; - - //! Returns for the unit vector its three coordinates Xv, Yv, and Zv. - void Coord (Standard_Real& Xv, Standard_Real& Yv, Standard_Real& Zv) const; - + //! Standard_OutOfRange if theIndex is not 1, 2, or 3. + Standard_Real Coord (const Standard_Integer theIndex) const { return coord.Coord (theIndex); } + + //! Returns for the unit vector its three coordinates theXv, theYv, and theZv. + void Coord (Standard_Real& theXv, Standard_Real& theYv, Standard_Real& theZv) const { coord.Coord (theXv, theYv, theZv); } + //! Returns the X coordinate for a unit vector. - Standard_Real X() const; - + Standard_Real X() const { return coord.X(); } + //! Returns the Y coordinate for a unit vector. - Standard_Real Y() const; - + Standard_Real Y() const { return coord.Y(); } + //! Returns the Z coordinate for a unit vector. - Standard_Real Z() const; - + Standard_Real Z() const { return coord.Z(); } + //! for this unit vector, returns its three coordinates as a number triplea. - const gp_XYZ& XYZ() const; - + const gp_XYZ& XYZ() const { return coord; } //! Returns True if the angle between the two directions is - //! lower or equal to AngularTolerance. - Standard_Boolean IsEqual (const gp_Dir& Other, const Standard_Real AngularTolerance) const; - + //! lower or equal to theAngularTolerance. + Standard_Boolean IsEqual (const gp_Dir& theOther, const Standard_Real theAngularTolerance) const + { + return Angle (theOther) <= theAngularTolerance; + } - //! Returns True if the angle between this unit vector and the unit vector Other is equal to Pi/2 (normal). - Standard_Boolean IsNormal (const gp_Dir& Other, const Standard_Real AngularTolerance) const; - + //! Returns True if the angle between this unit vector and the unit vector theOther is equal to Pi/2 (normal). + Standard_Boolean IsNormal (const gp_Dir& theOther, const Standard_Real theAngularTolerance) const + { + Standard_Real anAng = M_PI / 2.0 - Angle (theOther); + if (anAng < 0) + { + anAng = -anAng; + } + return anAng <= theAngularTolerance; + } - //! Returns True if the angle between this unit vector and the unit vector Other is equal to Pi (opposite). - Standard_Boolean IsOpposite (const gp_Dir& Other, const Standard_Real AngularTolerance) const; - + //! Returns True if the angle between this unit vector and the unit vector theOther is equal to Pi (opposite). + Standard_Boolean IsOpposite (const gp_Dir& theOther, const Standard_Real theAngularTolerance) const + { + return M_PI - Angle (theOther) <= theAngularTolerance; + } //! Returns true if the angle between this unit vector and the - //! unit vector Other is equal to 0 or to Pi. - //! Note: the tolerance criterion is given by AngularTolerance. - Standard_Boolean IsParallel (const gp_Dir& Other, const Standard_Real AngularTolerance) const; - + //! unit vector theOther is equal to 0 or to Pi. + //! Note: the tolerance criterion is given by theAngularTolerance. + Standard_Boolean IsParallel (const gp_Dir& theOther, const Standard_Real theAngularTolerance) const + { + Standard_Real anAng = Angle (theOther); + return anAng <= theAngularTolerance || M_PI - anAng <= theAngularTolerance; + } //! Computes the angular value in radians between and - //! . This value is always positive in 3D space. + //! . This value is always positive in 3D space. //! Returns the angle in the range [0, PI] - Standard_EXPORT Standard_Real Angle (const gp_Dir& Other) const; - + Standard_EXPORT Standard_Real Angle (const gp_Dir& theOther) const; - //! Computes the angular value between and . - //! is the direction of reference normal to and + //! Computes the angular value between and . + //! is the direction of reference normal to and //! and its orientation gives the positive sense of rotation. - //! If the cross product ^ has the same orientation - //! as the angular value is positive else negative. - //! Returns the angular value in the range -PI and PI (in radians). Raises DomainError if and are not parallel this exception is raised - //! when is in the same plane as and + //! If the cross product ^ has the same orientation + //! as the angular value is positive else negative. + //! Returns the angular value in the range -PI and PI (in radians). Raises DomainError if and are not parallel this exception is raised + //! when is in the same plane as and //! The tolerance criterion is Resolution from package gp. - Standard_EXPORT Standard_Real AngleWithRef (const gp_Dir& Other, const gp_Dir& VRef) const; - + Standard_EXPORT Standard_Real AngleWithRef (const gp_Dir& theOther, const gp_Dir& theVRef) const; + //! Computes the cross product between two directions //! Raises the exception ConstructionError if the two directions //! are parallel because the computed vector cannot be normalized //! to create a direction. - void Cross (const gp_Dir& Right); - void operator ^= (const gp_Dir& Right) -{ - Cross(Right); -} - + void Cross (const gp_Dir& theRight); + + void operator ^= (const gp_Dir& theRight) { Cross (theRight); } + //! Computes the triple vector product. //! ^ (V1 ^ V2) //! Raises the exception ConstructionError if V1 and V2 are parallel //! or and (V1^V2) are parallel because the computed vector //! can't be normalized to create a direction. - Standard_NODISCARD gp_Dir Crossed (const gp_Dir& Right) const; - Standard_NODISCARD gp_Dir operator ^ (const gp_Dir& Right) const -{ - return Crossed(Right); -} - - void CrossCross (const gp_Dir& V1, const gp_Dir& V2); - - //! Computes the double vector product this ^ (V1 ^ V2). + Standard_NODISCARD gp_Dir Crossed (const gp_Dir& theRight) const; + + Standard_NODISCARD gp_Dir operator ^ (const gp_Dir& theRight) const { return Crossed (theRight); } + + void CrossCross (const gp_Dir& theV1, const gp_Dir& theV2); + + //! Computes the double vector product this ^ (theV1 ^ theV2). //! - CrossCrossed creates a new unit vector. //! Exceptions //! Standard_ConstructionError if: - //! - V1 and V2 are parallel, or - //! - this unit vector and (V1 ^ V2) are parallel. + //! - theV1 and theV2 are parallel, or + //! - this unit vector and (theV1 ^ theV2) are parallel. //! This is because, in these conditions, the computed vector //! is null and cannot be normalized. - Standard_NODISCARD gp_Dir CrossCrossed (const gp_Dir& V1, const gp_Dir& V2) const; - - //! Computes the scalar product - Standard_Real Dot (const gp_Dir& Other) const; - Standard_Real operator * (const gp_Dir& Other) const -{ - return Dot(Other); -} - + Standard_NODISCARD gp_Dir CrossCrossed (const gp_Dir& theV1, const gp_Dir& theV2) const; - //! Computes the triple scalar product * (V1 ^ V2). + //! Computes the scalar product + Standard_Real Dot (const gp_Dir& theOther) const { return coord.Dot (theOther.coord); } + + Standard_Real operator * (const gp_Dir& theOther) const { return Dot (theOther); } + + //! Computes the triple scalar product * (theV1 ^ theV2). //! Warnings : - //! The computed vector V1' = V1 ^ V2 is not normalized + //! The computed vector theV1' = theV1 ^ theV2 is not normalized //! to create a unitary vector. So this method never - //! raises an exception even if V1 and V2 are parallel. - Standard_Real DotCross (const gp_Dir& V1, const gp_Dir& V2) const; - - void Reverse(); - + //! raises an exception even if theV1 and theV2 are parallel. + Standard_Real DotCross (const gp_Dir& theV1, const gp_Dir& theV2) const + { + return coord.Dot (theV1.coord.Crossed (theV2.coord)); + } + + void Reverse() { coord.Reverse(); } + //! Reverses the orientation of a direction //! geometric transformations //! Performs the symmetrical transformation of a direction //! with respect to the direction V which is the center of //! the symmetry.] - Standard_NODISCARD gp_Dir Reversed() const; - Standard_NODISCARD gp_Dir operator -() const -{ - return Reversed(); -} - - Standard_EXPORT void Mirror (const gp_Dir& V); - + Standard_NODISCARD gp_Dir Reversed() const + { + gp_Dir aV = *this; + aV.coord.Reverse(); + return aV; + } + + Standard_NODISCARD gp_Dir operator -() const { return Reversed(); } + + Standard_EXPORT void Mirror (const gp_Dir& theV); //! Performs the symmetrical transformation of a direction - //! with respect to the direction V which is the center of + //! with respect to the direction theV which is the center of //! the symmetry. - Standard_NODISCARD Standard_EXPORT gp_Dir Mirrored (const gp_Dir& V) const; - - Standard_EXPORT void Mirror (const gp_Ax1& A1); - + Standard_NODISCARD Standard_EXPORT gp_Dir Mirrored (const gp_Dir& theV) const; + + Standard_EXPORT void Mirror (const gp_Ax1& theA1); //! Performs the symmetrical transformation of a direction //! with respect to an axis placement which is the axis //! of the symmetry. - Standard_NODISCARD Standard_EXPORT gp_Dir Mirrored (const gp_Ax1& A1) const; - - Standard_EXPORT void Mirror (const gp_Ax2& A2); - + Standard_NODISCARD Standard_EXPORT gp_Dir Mirrored (const gp_Ax1& theA1) const; + + Standard_EXPORT void Mirror (const gp_Ax2& theA2); //! Performs the symmetrical transformation of a direction - //! with respect to a plane. The axis placement A2 locates + //! with respect to a plane. The axis placement theA2 locates //! the plane of the symmetry : (Location, XDirection, YDirection). - Standard_NODISCARD Standard_EXPORT gp_Dir Mirrored (const gp_Ax2& A2) const; - - void Rotate (const gp_Ax1& A1, const Standard_Real Ang); - + Standard_NODISCARD Standard_EXPORT gp_Dir Mirrored (const gp_Ax2& theA2) const; - //! Rotates a direction. A1 is the axis of the rotation. - //! Ang is the angular value of the rotation in radians. - Standard_NODISCARD gp_Dir Rotated (const gp_Ax1& A1, const Standard_Real Ang) const; - - Standard_EXPORT void Transform (const gp_Trsf& T); - + void Rotate(const gp_Ax1& theA1, const Standard_Real theAng); + + //! Rotates a direction. theA1 is the axis of the rotation. + //! theAng is the angular value of the rotation in radians. + Standard_NODISCARD gp_Dir Rotated (const gp_Ax1& theA1, const Standard_Real theAng) const + { + gp_Dir aV = *this; + aV.Rotate (theA1, theAng); + return aV; + } + + Standard_EXPORT void Transform (const gp_Trsf& theT); //! Transforms a direction with a "Trsf" from gp. //! Warnings : - //! If the scale factor of the "Trsf" T is negative then the + //! If the scale factor of the "Trsf" theT is negative then the //! direction is reversed. - Standard_NODISCARD gp_Dir Transformed (const gp_Trsf& T) const; - + Standard_NODISCARD gp_Dir Transformed (const gp_Trsf& theT) const + { + gp_Dir aV = *this; + aV.Transform (theT); + return aV; + } //! Dumps the content of me into the stream Standard_EXPORT void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const; @@ -269,27 +274,228 @@ public: //! Inits the content of me from the stream Standard_EXPORT Standard_Boolean InitFromJson (const Standard_SStream& theSStream, Standard_Integer& theStreamPos); - -protected: - - - - - private: - - gp_XYZ coord; - }; +#include -#include +// ======================================================================= +// function : gp_Dir +// purpose : +// ======================================================================= +inline gp_Dir::gp_Dir (const gp_Vec& theV) +{ + const gp_XYZ& aXYZ = theV.XYZ(); + Standard_Real aX = aXYZ.X(); + Standard_Real aY = aXYZ.Y(); + Standard_Real aZ = aXYZ.Z(); + Standard_Real aD = sqrt (aX * aX + aY * aY + aZ * aZ); + Standard_ConstructionError_Raise_if (aD <= gp::Resolution(), "gp_Dir() - input vector has zero norm"); + coord.SetX (aX / aD); + coord.SetY (aY / aD); + coord.SetZ (aZ / aD); +} +// ======================================================================= +// function : gp_Dir +// purpose : +// ======================================================================= +inline gp_Dir::gp_Dir (const gp_XYZ& theXYZ) +{ + Standard_Real aX = theXYZ.X(); + Standard_Real aY = theXYZ.Y(); + Standard_Real aZ = theXYZ.Z(); + Standard_Real aD = sqrt (aX * aX + aY * aY + aZ * aZ); + Standard_ConstructionError_Raise_if (aD <= gp::Resolution(), "gp_Dir() - input vector has zero norm"); + coord.SetX (aX / aD); + coord.SetY (aY / aD); + coord.SetZ (aZ / aD); +} +// ======================================================================= +// function : gp_Dir +// purpose : +// ======================================================================= +inline gp_Dir::gp_Dir (const Standard_Real theXv, + const Standard_Real theYv, + const Standard_Real theZv) +{ + Standard_Real aD = sqrt (theXv * theXv + theYv * theYv + theZv * theZv); + Standard_ConstructionError_Raise_if (aD <= gp::Resolution(), "gp_Dir() - input vector has zero norm"); + coord.SetX (theXv / aD); + coord.SetY (theYv / aD); + coord.SetZ (theZv / aD); +} +// ======================================================================= +// function : SetCoord +// purpose : +// ======================================================================= +inline void gp_Dir::SetCoord (const Standard_Integer theIndex, + const Standard_Real theXi) +{ + Standard_Real aX = coord.X(); + Standard_Real aY = coord.Y(); + Standard_Real aZ = coord.Z(); + Standard_OutOfRange_Raise_if (theIndex < 1 || theIndex > 3, "gp_Dir::SetCoord() - index is out of range [1, 3]"); + if (theIndex == 1) + { + aX = theXi; + } + else if (theIndex == 2) + { + aY = theXi; + } + else + { + aZ = theXi; + } + Standard_Real aD = sqrt (aX * aX + aY * aY + aZ * aZ); + Standard_ConstructionError_Raise_if (aD <= gp::Resolution(), "gp_Dir::SetCoord() - result vector has zero norm"); + coord.SetX (aX / aD); + coord.SetY (aY / aD); + coord.SetZ (aZ / aD); +} +// ======================================================================= +// function : SetCoord +// purpose : +// ======================================================================= +inline void gp_Dir::SetCoord (const Standard_Real theXv, + const Standard_Real theYv, + const Standard_Real theZv) { + Standard_Real aD = sqrt (theXv * theXv + theYv * theYv + theZv * theZv); + Standard_ConstructionError_Raise_if (aD <= gp::Resolution(), "gp_Dir::SetCoord() - input vector has zero norm"); + coord.SetX (theXv / aD); + coord.SetY (theYv / aD); + coord.SetZ (theZv / aD); +} + +// ======================================================================= +// function : SetX +// purpose : +// ======================================================================= +inline void gp_Dir::SetX (const Standard_Real theX) +{ + Standard_Real anY = coord.Y(); + Standard_Real aZ = coord.Z(); + Standard_Real aD = sqrt (theX * theX + anY * anY + aZ * aZ); + Standard_ConstructionError_Raise_if (aD <= gp::Resolution(), "gp_Dir::SetX() - result vector has zero norm"); + coord.SetX (theX / aD); + coord.SetY (anY / aD); + coord.SetZ (aZ / aD); +} + +// ======================================================================= +// function : SetY +// purpose : +// ======================================================================= +inline void gp_Dir::SetY (const Standard_Real theY) +{ + Standard_Real aZ = coord.Z(); + Standard_Real aX = coord.X(); + Standard_Real aD = sqrt (aX * aX + theY * theY + aZ * aZ); + Standard_ConstructionError_Raise_if (aD <= gp::Resolution(), "gp_Dir::SetY() - result vector has zero norm"); + coord.SetX (aX / aD); + coord.SetY (theY / aD); + coord.SetZ (aZ / aD); +} + +// ======================================================================= +// function : SetZ +// purpose : +// ======================================================================= +inline void gp_Dir::SetZ (const Standard_Real theZ) +{ + Standard_Real aX = coord.X(); + Standard_Real anY = coord.Y(); + Standard_Real aD = sqrt (aX * aX + anY * anY + theZ * theZ); + Standard_ConstructionError_Raise_if (aD <= gp::Resolution(), "gp_Dir::SetZ() - result vector has zero norm"); + coord.SetX (aX / aD); + coord.SetY (anY / aD); + coord.SetZ (theZ / aD); +} + +// ======================================================================= +// function : SetXYZ +// purpose : +// ======================================================================= +inline void gp_Dir::SetXYZ (const gp_XYZ& theXYZ) +{ + Standard_Real aX = theXYZ.X(); + Standard_Real anY = theXYZ.Y(); + Standard_Real aZ = theXYZ.Z(); + Standard_Real aD = sqrt(aX * aX + anY * anY + aZ * aZ); + Standard_ConstructionError_Raise_if (aD <= gp::Resolution(), "gp_Dir::SetX() - input vector has zero norm"); + coord.SetX (aX / aD); + coord.SetY (anY / aD); + coord.SetZ (aZ / aD); +} + +// ======================================================================= +// function : Cross +// purpose : +// ======================================================================= +inline void gp_Dir::Cross(const gp_Dir& theRight) +{ + coord.Cross (theRight.coord); + Standard_Real aD = coord.Modulus(); + Standard_ConstructionError_Raise_if (aD <= gp::Resolution(), "gp_Dir::Cross() - result vector has zero norm"); + coord.Divide (aD); +} + +// ======================================================================= +// function : Crossed +// purpose : +// ======================================================================= +inline gp_Dir gp_Dir::Crossed (const gp_Dir& theRight) const +{ + gp_Dir aV = *this; + aV.coord.Cross (theRight.coord); + Standard_Real aD = aV.coord.Modulus(); + Standard_ConstructionError_Raise_if (aD <= gp::Resolution(), "gp_Dir::Crossed() - result vector has zero norm"); + aV.coord.Divide (aD); + return aV; +} + +// ======================================================================= +// function : CrossCross +// purpose : +// ======================================================================= +inline void gp_Dir::CrossCross (const gp_Dir& theV1, const gp_Dir& theV2) +{ + coord.CrossCross (theV1.coord, theV2.coord); + Standard_Real aD = coord.Modulus(); + Standard_ConstructionError_Raise_if (aD <= gp::Resolution(), "gp_Dir::CrossCross() - result vector has zero norm"); + coord.Divide (aD); +} + +// ======================================================================= +// function : CrossCrossed +// purpose : +// ======================================================================= +inline gp_Dir gp_Dir::CrossCrossed (const gp_Dir& theV1, const gp_Dir& theV2) const +{ + gp_Dir aV = *this; + (aV.coord).CrossCross (theV1.coord, theV2.coord); + Standard_Real aD = aV.coord.Modulus(); + Standard_ConstructionError_Raise_if (aD <= gp::Resolution(), "gp_Dir::CrossCrossed() - result vector has zero norm"); + aV.coord.Divide (aD); + return aV; +} + +// ======================================================================= +// function : Rotate +// purpose : +// ======================================================================= +inline void gp_Dir::Rotate(const gp_Ax1& theA1, const Standard_Real theAng) +{ + gp_Trsf aT; + aT.SetRotation (theA1, theAng); + coord.Multiply (aT.HVectorialPart()); +} #endif // _gp_Dir_HeaderFile diff --git a/src/gp/gp_Dir.lxx b/src/gp/gp_Dir.lxx deleted file mode 100644 index 98a5f8ad6b..0000000000 --- a/src/gp/gp_Dir.lxx +++ /dev/null @@ -1,254 +0,0 @@ -// Copyright (c) 1995-1999 Matra Datavision -// Copyright (c) 1999-2014 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -#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(), "gp_Dir() - input vector has zero norm"); - 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(), "gp_Dir() - input vector has zero norm"); - 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(), "gp_Dir() - input vector has zero norm"); - 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, "gp_Dir::SetCoord() - index is out of range [1, 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(), "gp_Dir::SetCoord() - result vector has zero norm"); - 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(), "gp_Dir::SetCoord() - input vector has zero norm"); - 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(), "gp_Dir::SetX() - result vector has zero norm"); - 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(), "gp_Dir::SetY() - result vector has zero norm"); - 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(), "gp_Dir::SetZ() - result vector has zero norm"); - 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(), "gp_Dir::SetX() - input vector has zero norm"); - 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 = M_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 M_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 || M_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(), "gp_Dir::Cross() - result vector has zero norm"); - 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(), "gp_Dir::Crossed() - result vector has zero norm"); - 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(), "gp_Dir::CrossCross() - result vector has zero norm"); - 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(), "gp_Dir::CrossCrossed() - result vector has zero norm"); - 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; -} - diff --git a/src/gp/gp_Dir2d.cxx b/src/gp/gp_Dir2d.cxx index 57e7b4664c..6c3b481502 100644 --- a/src/gp/gp_Dir2d.cxx +++ b/src/gp/gp_Dir2d.cxx @@ -14,8 +14,9 @@ // JCV 08/01/90 Modifs suite a l'introduction des classes XY et Mat2d dans gp -#include #include + +#include #include #include #include diff --git a/src/gp/gp_Dir2d.hxx b/src/gp/gp_Dir2d.hxx index 17fbde6832..c14cff294f 100644 --- a/src/gp/gp_Dir2d.hxx +++ b/src/gp/gp_Dir2d.hxx @@ -15,23 +15,16 @@ #ifndef _gp_Dir2d_HeaderFile #define _gp_Dir2d_HeaderFile -#include -#include -#include - #include -#include -#include -#include -class Standard_ConstructionError; -class Standard_DomainError; -class Standard_OutOfRange; +#include +#include +#include + class gp_Vec2d; class gp_XY; class gp_Ax2d; class gp_Trsf2d; - //! Describes a unit vector in the plane (2D space). This unit //! vector is also called "Direction". //! See Also @@ -46,55 +39,53 @@ public: DEFINE_STANDARD_ALLOC - //! Creates a direction corresponding to X axis. - gp_Dir2d(); - - //! Normalizes the vector V and creates a Direction. Raises ConstructionError if V.Magnitude() <= Resolution from gp. - gp_Dir2d(const gp_Vec2d& V); - - //! Creates a Direction from a doublet of coordinates. Raises ConstructionError if Coord.Modulus() <= Resolution from gp. - gp_Dir2d(const gp_XY& Coord); - - //! Creates a Direction with its 2 cartesian coordinates. Raises ConstructionError if Sqrt(Xv*Xv + Yv*Yv) <= Resolution from gp. - gp_Dir2d(const Standard_Real Xv, const Standard_Real Yv); - + gp_Dir2d() + : coord (1., 0.) + {} + + //! Normalizes the vector theV and creates a Direction. Raises ConstructionError if theV.Magnitude() <= Resolution from gp. + gp_Dir2d (const gp_Vec2d& theV); + + //! Creates a Direction from a doublet of coordinates. Raises ConstructionError if theCoord.Modulus() <= Resolution from gp. + gp_Dir2d (const gp_XY& theCoord); + + //! Creates a Direction with its 2 cartesian coordinates. Raises ConstructionError if Sqrt(theXv*theXv + theYv*theYv) <= Resolution from gp. + gp_Dir2d (const Standard_Real theXv, const Standard_Real theYv); //! For this unit vector, assigns: - //! the value Xi to: - //! - the X coordinate if Index is 1, or - //! - the Y coordinate if Index is 2, and then normalizes it. + //! the value theXi to: + //! - the X coordinate if theIndex is 1, or + //! - the Y coordinate if theIndex is 2, and then normalizes it. //! Warning //! Remember that all the coordinates of a unit vector are //! implicitly modified when any single one is changed directly. //! Exceptions - //! Standard_OutOfRange if Index is not 1 or 2. + //! Standard_OutOfRange if theIndex is not 1 or 2. //! Standard_ConstructionError if either of the following //! is less than or equal to gp::Resolution(): - //! - Sqrt(Xv*Xv + Yv*Yv), or + //! - Sqrt(theXv*theXv + theYv*theYv), or //! - the modulus of the number pair formed by the new - //! value Xi and the other coordinate of this vector that + //! value theXi and the other coordinate of this vector that //! was not directly modified. - //! Raises OutOfRange if Index != {1, 2}. - void SetCoord (const Standard_Integer Index, const Standard_Real Xi); - + //! Raises OutOfRange if theIndex != {1, 2}. + void SetCoord (const Standard_Integer theIndex, const Standard_Real theXi); //! For this unit vector, assigns: - //! - the values Xv and Yv to its two coordinates, + //! - the values theXv and theYv to its two coordinates, //! Warning //! Remember that all the coordinates of a unit vector are //! implicitly modified when any single one is changed directly. //! Exceptions - //! Standard_OutOfRange if Index is not 1 or 2. + //! Standard_OutOfRange if theIndex is not 1 or 2. //! Standard_ConstructionError if either of the following //! is less than or equal to gp::Resolution(): - //! - Sqrt(Xv*Xv + Yv*Yv), or + //! - Sqrt(theXv*theXv + theYv*theYv), or //! - the modulus of the number pair formed by the new //! value Xi and the other coordinate of this vector that //! was not directly modified. - //! Raises OutOfRange if Index != {1, 2}. - void SetCoord (const Standard_Real Xv, const Standard_Real Yv); - + //! Raises OutOfRange if theIndex != {1, 2}. + void SetCoord (const Standard_Real theXv, const Standard_Real theYv); //! Assigns the given value to the X coordinate of this unit vector, //! and then normalizes it. @@ -108,8 +99,7 @@ public: //! - the modulus of the number pair formed from the new //! X or Y coordinate and the other coordinate of this //! vector that was not directly modified. - void SetX (const Standard_Real X); - + void SetX (const Standard_Real theX); //! Assigns the given value to the Y coordinate of this unit vector, //! and then normalizes it. @@ -123,11 +113,10 @@ public: //! - the modulus of the number pair formed from the new //! X or Y coordinate and the other coordinate of this //! vector that was not directly modified. - void SetY (const Standard_Real Y); - + void SetY (const Standard_Real theY); //! Assigns: - //! - the two coordinates of Coord to this unit vector, + //! - the two coordinates of theCoord to this unit vector, //! and then normalizes it. //! Warning //! Remember that all the coordinates of a unit vector are @@ -135,146 +124,323 @@ public: //! Exceptions //! Standard_ConstructionError if either of the following //! is less than or equal to gp::Resolution(): - //! - the modulus of Coord, or + //! - the modulus of theCoord, or //! - the modulus of the number pair formed from the new //! X or Y coordinate and the other coordinate of this //! vector that was not directly modified. - void SetXY (const gp_XY& Coord); - + void SetXY (const gp_XY& theCoord); + + //! For this unit vector returns the coordinate of range theIndex : + //! theIndex = 1 => X is returned + //! theIndex = 2 => Y is returned + //! Raises OutOfRange if theIndex != {1, 2}. + Standard_Real Coord (const Standard_Integer theIndex) const { return coord.Coord (theIndex); } + + //! For this unit vector returns its two coordinates theXv and theYv. + //! Raises OutOfRange if theIndex != {1, 2}. + void Coord (Standard_Real& theXv, Standard_Real& theYv) const { coord.Coord (theXv, theYv); } - //! For this unit vector returns the coordinate of range Index : - //! Index = 1 => X is returned - //! Index = 2 => Y is returned - //! Raises OutOfRange if Index != {1, 2}. - Standard_Real Coord (const Standard_Integer Index) const; - - //! For this unit vector returns its two coordinates Xv and Yv. - //! Raises OutOfRange if Index != {1, 2}. - void Coord (Standard_Real& Xv, Standard_Real& Yv) const; - //! For this unit vector, returns its X coordinate. - Standard_Real X() const; - + Standard_Real X() const { return coord.X(); } + //! For this unit vector, returns its Y coordinate. - Standard_Real Y() const; - + Standard_Real Y() const { return coord.Y(); } + //! For this unit vector, returns its two coordinates as a number pair. //! Comparison between Directions //! The precision value is an input data. - const gp_XY& XY() const; - + const gp_XY& XY() const { return coord; } //! Returns True if the two vectors have the same direction //! i.e. the angle between this unit vector and the - //! unit vector Other is less than or equal to AngularTolerance. - Standard_Boolean IsEqual (const gp_Dir2d& Other, const Standard_Real AngularTolerance) const; - + //! unit vector theOther is less than or equal to theAngularTolerance. + Standard_Boolean IsEqual (const gp_Dir2d& theOther, const Standard_Real theAngularTolerance) const; //! Returns True if the angle between this unit vector and the - //! unit vector Other is equal to Pi/2 or -Pi/2 (normal) - //! i.e. Abs(Abs(.Angle(Other)) - PI/2.) <= AngularTolerance - Standard_Boolean IsNormal (const gp_Dir2d& Other, const Standard_Real AngularTolerance) const; - + //! unit vector theOther is equal to Pi/2 or -Pi/2 (normal) + //! i.e. Abs(Abs(.Angle(theOther)) - PI/2.) <= theAngularTolerance + Standard_Boolean IsNormal (const gp_Dir2d& theOther, const Standard_Real theAngularTolerance) const; //! Returns True if the angle between this unit vector and the - //! unit vector Other is equal to Pi or -Pi (opposite). - //! i.e. PI - Abs(.Angle(Other)) <= AngularTolerance - Standard_Boolean IsOpposite (const gp_Dir2d& Other, const Standard_Real AngularTolerance) const; - + //! unit vector theOther is equal to Pi or -Pi (opposite). + //! i.e. PI - Abs(.Angle(theOther)) <= theAngularTolerance + Standard_Boolean IsOpposite (const gp_Dir2d& theOther, const Standard_Real theAngularTolerance) const; //! returns true if the angle between this unit vector and unit - //! vector Other is equal to 0, Pi or -Pi. - //! i.e. Abs(Angle(, Other)) <= AngularTolerance or - //! PI - Abs(Angle(, Other)) <= AngularTolerance - Standard_Boolean IsParallel (const gp_Dir2d& Other, const Standard_Real AngularTolerance) const; - + //! vector theOther is equal to 0, Pi or -Pi. + //! i.e. Abs(Angle(, theOther)) <= theAngularTolerance or + //! PI - Abs(Angle(, theOther)) <= theAngularTolerance + Standard_Boolean IsParallel (const gp_Dir2d& theOther, const Standard_Real theAngularTolerance) const; //! Computes the angular value in radians between and - //! . Returns the angle in the range [-PI, PI]. - Standard_EXPORT Standard_Real Angle (const gp_Dir2d& Other) const; - + //! . Returns the angle in the range [-PI, PI]. + Standard_EXPORT Standard_Real Angle (const gp_Dir2d& theOther) const; //! Computes the cross product between two directions. - Standard_NODISCARD Standard_Real Crossed (const gp_Dir2d& Right) const; - Standard_NODISCARD Standard_Real operator ^ (const gp_Dir2d& Right) const -{ - return Crossed(Right); -} - + Standard_NODISCARD Standard_Real Crossed (const gp_Dir2d& theRight) const { return coord.Crossed (theRight.coord); } + + Standard_NODISCARD Standard_Real operator ^ (const gp_Dir2d& theRight) const { return Crossed (theRight); } + //! Computes the scalar product - Standard_Real Dot (const gp_Dir2d& Other) const; - Standard_Real operator * (const gp_Dir2d& Other) const -{ - return Dot(Other); -} - - void Reverse(); - + Standard_Real Dot (const gp_Dir2d& theOther) const { return coord.Dot (theOther.coord); } + + Standard_Real operator * (const gp_Dir2d& theOther) const { return Dot (theOther); } + + void Reverse() { coord.Reverse(); } + //! Reverses the orientation of a direction - Standard_NODISCARD gp_Dir2d Reversed() const; - Standard_NODISCARD gp_Dir2d operator -() const -{ - return Reversed(); -} - - Standard_EXPORT void Mirror (const gp_Dir2d& V); - + Standard_NODISCARD gp_Dir2d Reversed() const + { + gp_Dir2d aV = *this; + aV.coord.Reverse(); + return aV; + } + + Standard_NODISCARD gp_Dir2d operator -() const { return Reversed(); } + + Standard_EXPORT void Mirror (const gp_Dir2d& theV); //! Performs the symmetrical transformation of a direction - //! with respect to the direction V which is the center of + //! with respect to the direction theV which is the center of //! the symmetry. - Standard_NODISCARD Standard_EXPORT gp_Dir2d Mirrored (const gp_Dir2d& V) const; - - Standard_EXPORT void Mirror (const gp_Ax2d& A); - + Standard_NODISCARD Standard_EXPORT gp_Dir2d Mirrored (const gp_Dir2d& theV) const; + + Standard_EXPORT void Mirror (const gp_Ax2d& theA); //! Performs the symmetrical transformation of a direction //! with respect to an axis placement which is the axis //! of the symmetry. - Standard_NODISCARD Standard_EXPORT gp_Dir2d Mirrored (const gp_Ax2d& A) const; - - void Rotate (const Standard_Real Ang); - + Standard_NODISCARD Standard_EXPORT gp_Dir2d Mirrored (const gp_Ax2d& theA) const; - //! Rotates a direction. Ang is the angular value of + void Rotate (const Standard_Real Ang); + + //! Rotates a direction. theAng is the angular value of //! the rotation in radians. - Standard_NODISCARD gp_Dir2d Rotated (const Standard_Real Ang) const; - - Standard_EXPORT void Transform (const gp_Trsf2d& T); - + Standard_NODISCARD gp_Dir2d Rotated (const Standard_Real theAng) const + { + gp_Dir2d aV = *this; + aV.Rotate (theAng); + return aV; + } - //! Transforms a direction with the "Trsf" T. + Standard_EXPORT void Transform (const gp_Trsf2d& theT); + + //! Transforms a direction with the "Trsf" theT. //! Warnings : - //! If the scale factor of the "Trsf" T is negative then the + //! If the scale factor of the "Trsf" theT is negative then the //! direction is reversed. - Standard_NODISCARD gp_Dir2d Transformed (const gp_Trsf2d& T) const; + Standard_NODISCARD gp_Dir2d Transformed (const gp_Trsf2d& theT) const + { + gp_Dir2d aV = *this; + aV.Transform (theT); + return aV; + } //! Dumps the content of me into the stream Standard_EXPORT void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const; - - - -protected: - - - - - private: - - gp_XY coord; - }; +#include +#include -#include +// ======================================================================= +// function : gp_Dir2d +// purpose : +// ======================================================================= +inline gp_Dir2d::gp_Dir2d (const gp_Vec2d& theV) +{ + const gp_XY& aXY = theV.XY(); + Standard_Real aX = aXY.X(); + Standard_Real anY = aXY.Y(); + Standard_Real aD = sqrt (aX * aX + anY * anY); + Standard_ConstructionError_Raise_if (aD <= gp::Resolution(), "gp_Dir2d() - input vector has zero norm"); + coord.SetX (aX / aD); + coord.SetY (anY / aD); +} +// ======================================================================= +// function : gp_Dir2d +// purpose : +// ======================================================================= +inline gp_Dir2d::gp_Dir2d (const gp_XY& theXY) +{ + Standard_Real aX = theXY.X(); + Standard_Real anY = theXY.Y(); + Standard_Real aD = sqrt (aX * aX + anY * anY); + Standard_ConstructionError_Raise_if (aD <= gp::Resolution(), "gp_Dir2d() - input vector has zero norm"); + coord.SetX (aX / aD); + coord.SetY (anY / aD); +} +// ======================================================================= +// function : gp_Dir2d +// purpose : +// ======================================================================= +inline gp_Dir2d::gp_Dir2d (const Standard_Real theXv, + const Standard_Real theYv) +{ + Standard_Real aD = sqrt (theXv * theXv + theYv * theYv); + Standard_ConstructionError_Raise_if (aD <= gp::Resolution(), "gp_Dir2d() - input vector has zero norm"); + coord.SetX (theXv / aD); + coord.SetY (theYv / aD); +} +// ======================================================================= +// function : SetCoord +// purpose : +// ======================================================================= +inline void gp_Dir2d::SetCoord (const Standard_Integer theIndex, + const Standard_Real theXi) +{ + Standard_Real aX = coord.X(); + Standard_Real anY = coord.Y(); + Standard_OutOfRange_Raise_if (theIndex < 1 || theIndex > 2, "gp_Dir2d::SetCoord() - index is out of range [1, 2]"); + if (theIndex == 1) + { + aX = theXi; + } + else + { + anY = theXi; + } + Standard_Real aD = sqrt (aX * aX + anY * anY); + Standard_ConstructionError_Raise_if (aD <= gp::Resolution(), "gp_Dir2d::SetCoord() - result vector has zero norm"); + coord.SetX (aX / aD); + coord.SetY (anY / aD); +} +// ======================================================================= +// function : SetCoord +// purpose : +// ======================================================================= +inline void gp_Dir2d::SetCoord (const Standard_Real theXv, + const Standard_Real theYv) +{ + Standard_Real aD = sqrt (theXv * theXv + theYv * theYv); + Standard_ConstructionError_Raise_if (aD <= gp::Resolution(), "gp_Dir2d::SetCoord() - result vector has zero norm"); + coord.SetX (theXv / aD); + coord.SetY (theYv / aD); +} + +// ======================================================================= +// function : SetX +// purpose : +// ======================================================================= +inline void gp_Dir2d::SetX (const Standard_Real theX) +{ + Standard_Real anY = coord.Y(); + Standard_Real aD = sqrt (theX * theX + anY * anY); + Standard_ConstructionError_Raise_if (aD <= gp::Resolution(), "gp_Dir2d::SetX() - result vector has zero norm"); + coord.SetX (theX / aD); + coord.SetY (anY / aD); +} + +// ======================================================================= +// function : SetY +// purpose : +// ======================================================================= +inline void gp_Dir2d::SetY (const Standard_Real theY) +{ + Standard_Real aX = coord.X(); + Standard_Real aD = sqrt (aX * aX + theY * theY); + Standard_ConstructionError_Raise_if (aD <= gp::Resolution(), "gp_Dir2d::SetY() - result vector has zero norm"); + coord.SetX (aX / aD); + coord.SetY (theY / aD); +} + +// ======================================================================= +// function : SetXY +// purpose : +// ======================================================================= +inline void gp_Dir2d::SetXY (const gp_XY& theXY) +{ + Standard_Real aX = theXY.X(); + Standard_Real anY = theXY.Y(); + Standard_Real aD = sqrt (aX * aX + anY * anY); + Standard_ConstructionError_Raise_if (aD <= gp::Resolution(), "gp_Dir2d::SetZ() - result vector has zero norm"); + coord.SetX (aX / aD); + coord.SetY (anY / aD); +} + +// ======================================================================= +// function : IsEqual +// purpose : +// ======================================================================= +inline Standard_Boolean gp_Dir2d::IsEqual (const gp_Dir2d& theOther, + const Standard_Real theAngularTolerance) const +{ + Standard_Real anAng = Angle (theOther); + if (anAng < 0) + { + anAng = -anAng; + } + return anAng <= theAngularTolerance; +} + +// ======================================================================= +// function : IsNormal +// purpose : +// ======================================================================= +inline Standard_Boolean gp_Dir2d::IsNormal (const gp_Dir2d& theOther, + const Standard_Real theAngularTolerance) const +{ + Standard_Real anAng = Angle (theOther); + if (anAng < 0) + { + anAng = -anAng; + } + anAng = M_PI / 2.0 - anAng; + if (anAng < 0) + { + anAng = -anAng; + } + return anAng <= theAngularTolerance; +} + +// ======================================================================= +// function : IsOpposite +// purpose : +// ======================================================================= +inline Standard_Boolean gp_Dir2d::IsOpposite (const gp_Dir2d& theOther, + const Standard_Real theAngularTolerance) const +{ + Standard_Real anAng = Angle (theOther); + if (anAng < 0) + { + anAng = -anAng; + } + return M_PI - anAng <= theAngularTolerance; +} + +// ======================================================================= +// function : IsParallel +// purpose : +// ======================================================================= +inline Standard_Boolean gp_Dir2d::IsParallel (const gp_Dir2d& theOther, + const Standard_Real theAngularTolerance) const +{ + Standard_Real anAng = Angle (theOther); + if (anAng < 0) + { + anAng = -anAng; + } + return anAng <= theAngularTolerance || M_PI - anAng <= theAngularTolerance; +} + +// ======================================================================= +// function : Rotate +// purpose : +// ======================================================================= +inline void gp_Dir2d::Rotate (const Standard_Real theAng) +{ + gp_Trsf2d aT; + aT.SetRotation (gp_Pnt2d (0.0, 0.0), theAng); + coord.Multiply (aT.HVectorialPart()); +} #endif // _gp_Dir2d_HeaderFile diff --git a/src/gp/gp_Dir2d.lxx b/src/gp/gp_Dir2d.lxx deleted file mode 100644 index a60eb599d4..0000000000 --- a/src/gp/gp_Dir2d.lxx +++ /dev/null @@ -1,197 +0,0 @@ -// Copyright (c) 1995-1999 Matra Datavision -// Copyright (c) 1999-2014 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -// Modif JCV 08/01/91 introduction classe XY dans le package gp - -#include -#include -#include -#include -#include - -inline gp_Dir2d::gp_Dir2d() : coord (1.,0.) -{ -} - -inline gp_Dir2d::gp_Dir2d (const gp_Vec2d& V) -{ - const gp_XY& XY = V.XY(); - Standard_Real X = XY.X(); - Standard_Real Y = XY.Y(); - Standard_Real D = sqrt(X * X + Y * Y); - Standard_ConstructionError_Raise_if (D <= gp::Resolution(), "gp_Dir2d() - input vector has zero norm"); - coord.SetX(X / D); - coord.SetY(Y / D); -} - -inline gp_Dir2d::gp_Dir2d (const gp_XY& XY) -{ - Standard_Real X = XY.X(); - Standard_Real Y = XY.Y(); - Standard_Real D = sqrt(X * X + Y * Y); - Standard_ConstructionError_Raise_if (D <= gp::Resolution(), "gp_Dir2d() - input vector has zero norm"); - coord.SetX(X / D); - coord.SetY(Y / D); -} - -inline gp_Dir2d::gp_Dir2d (const Standard_Real Xv, - const Standard_Real Yv) -{ - Standard_Real D = sqrt (Xv * Xv + Yv * Yv); - Standard_ConstructionError_Raise_if (D <= gp::Resolution(), "gp_Dir2d() - input vector has zero norm"); - coord.SetX(Xv / D); - coord.SetY(Yv / D); -} - -inline void gp_Dir2d::SetCoord (const Standard_Integer Index, - const Standard_Real Xi) -{ - Standard_Real X = coord.X(); - Standard_Real Y = coord.Y(); - Standard_OutOfRange_Raise_if (Index < 1 || Index > 2, "gp_Dir2d::SetCoord() - index is out of range [1, 2]"); - if (Index == 1) X = Xi; - else Y = Xi; - Standard_Real D = sqrt (X * X + Y * Y); - Standard_ConstructionError_Raise_if (D <= gp::Resolution(), "gp_Dir2d::SetCoord() - result vector has zero norm"); - coord.SetX(X / D); - coord.SetY(Y / D); -} - -inline void gp_Dir2d::SetCoord (const Standard_Real Xv, - const Standard_Real Yv) -{ - Standard_Real D = sqrt (Xv * Xv + Yv * Yv); - Standard_ConstructionError_Raise_if (D <= gp::Resolution(), "gp_Dir2d::SetCoord() - result vector has zero norm"); - coord.SetX(Xv / D); - coord.SetY(Yv / D); -} - -inline void gp_Dir2d::SetX (const Standard_Real X) -{ - Standard_Real Y = coord.Y(); - Standard_Real D = sqrt (X * X + Y * Y); - Standard_ConstructionError_Raise_if (D <= gp::Resolution(), "gp_Dir2d::SetX() - result vector has zero norm"); - coord.SetX(X / D); - coord.SetY(Y / D); -} - -inline void gp_Dir2d::SetY (const Standard_Real Y) -{ - Standard_Real X = coord.X(); - Standard_Real D = sqrt (X * X + Y * Y); - Standard_ConstructionError_Raise_if (D <= gp::Resolution(), "gp_Dir2d::SetY() - result vector has zero norm"); - coord.SetX(X / D); - coord.SetY(Y / D); -} - -inline void gp_Dir2d::SetXY (const gp_XY& XY) -{ - Standard_Real X = XY.X(); - Standard_Real Y = XY.Y(); - Standard_Real D = sqrt(X * X + Y * Y); - Standard_ConstructionError_Raise_if (D <= gp::Resolution(), "gp_Dir2d::SetZ() - result vector has zero norm"); - coord.SetX(X / D); - coord.SetY(Y / D); -} - -inline Standard_Real gp_Dir2d::Coord (const Standard_Integer Index) const -{ return coord.Coord(Index); } - -inline void gp_Dir2d::Coord(Standard_Real& Xv, Standard_Real& Yv) const -{ coord.Coord (Xv, Yv); } - -inline Standard_Real gp_Dir2d::X() const -{ return coord.X() ; } - -inline Standard_Real gp_Dir2d::Y() const -{ return coord.Y() ; } - -inline const gp_XY& gp_Dir2d::XY () const -{ return coord; } - -inline Standard_Boolean gp_Dir2d::IsEqual -(const gp_Dir2d& Other, - const Standard_Real AngularTolerance) const -{ - Standard_Real Ang = Angle(Other); - if (Ang < 0) Ang = - Ang; - return Ang <= AngularTolerance; -} - -inline Standard_Boolean gp_Dir2d::IsNormal -(const gp_Dir2d& Other, - const Standard_Real AngularTolerance) const -{ - Standard_Real Ang = Angle(Other); - if (Ang < 0) Ang = - Ang; - Ang = M_PI / 2.0 - Ang; - if (Ang < 0) Ang = - Ang; - return Ang <= AngularTolerance; -} - -inline Standard_Boolean gp_Dir2d::IsOpposite -(const gp_Dir2d& Other, - const Standard_Real AngularTolerance) const -{ - Standard_Real Ang = Angle(Other); - if (Ang < 0) Ang = - Ang; - return M_PI - Ang <= AngularTolerance; -} - -inline Standard_Boolean gp_Dir2d::IsParallel -(const gp_Dir2d& Other, - const Standard_Real AngularTolerance) const -{ - Standard_Real Ang = Angle(Other); - if (Ang < 0) Ang = - Ang; - return Ang <= AngularTolerance || M_PI - Ang <= AngularTolerance; -} - -inline Standard_Real gp_Dir2d::Crossed (const gp_Dir2d& Right) const -{ return coord.Crossed (Right.coord); } - -inline Standard_Real gp_Dir2d::Dot (const gp_Dir2d& Other) const -{ return coord.Dot (Other.coord); } - -inline void gp_Dir2d::Reverse() -{ coord.Reverse(); } - -inline gp_Dir2d gp_Dir2d::Reversed() const -{ - gp_Dir2d V = *this; - V.coord.Reverse (); - return V; -} - -inline void gp_Dir2d::Rotate (const Standard_Real Ang) -{ - gp_Trsf2d T; - T.SetRotation (gp_Pnt2d (0.0, 0.0), Ang); - coord.Multiply (T.HVectorialPart()); -} - -inline gp_Dir2d gp_Dir2d::Rotated (const Standard_Real Ang) const -{ - gp_Dir2d V = *this; - V.Rotate (Ang); - return V; -} - -inline gp_Dir2d gp_Dir2d::Transformed (const gp_Trsf2d& T) const -{ - gp_Dir2d V = *this; - V.Transform (T); - return V; -} - diff --git a/src/gp/gp_Elips.cxx b/src/gp/gp_Elips.cxx index d0bc04ebfc..e9b063252d 100644 --- a/src/gp/gp_Elips.cxx +++ b/src/gp/gp_Elips.cxx @@ -14,9 +14,10 @@ //Modif JCV 12/12/90 +#include + #include #include -#include #include #include #include diff --git a/src/gp/gp_Elips.hxx b/src/gp/gp_Elips.hxx index 11e3789b56..b4f24916fb 100644 --- a/src/gp/gp_Elips.hxx +++ b/src/gp/gp_Elips.hxx @@ -15,22 +15,11 @@ #ifndef _gp_Elips_HeaderFile #define _gp_Elips_HeaderFile -#include -#include -#include - -#include -#include +#include #include +#include #include -class Standard_ConstructionError; -class gp_Ax2; -class gp_Ax1; -class gp_Pnt; -class gp_Trsf; -class gp_Vec; - - +#include //! Describes an ellipse in 3D space. //! An ellipse is defined by its major and minor radii and @@ -63,60 +52,74 @@ public: DEFINE_STANDARD_ALLOC - //! Creates an indefinite ellipse. - gp_Elips(); - + gp_Elips() + : majorRadius (RealLast()), + minorRadius (RealSmall()) + {} //! The major radius of the ellipse is on the "XAxis" and the //! minor radius is on the "YAxis" of the ellipse. The "XAxis" - //! is defined with the "XDirection" of A2 and the "YAxis" is - //! defined with the "YDirection" of A2. + //! is defined with the "XDirection" of theA2 and the "YAxis" is + //! defined with the "YDirection" of theA2. //! Warnings : - //! It is not forbidden to create an ellipse with MajorRadius = - //! MinorRadius. - //! Raises ConstructionError if MajorRadius < MinorRadius or MinorRadius < 0. - gp_Elips(const gp_Ax2& A2, const Standard_Real MajorRadius, const Standard_Real MinorRadius); - + //! It is not forbidden to create an ellipse with theMajorRadius = + //! theMinorRadius. + //! Raises ConstructionError if theMajorRadius < theMinorRadius or theMinorRadius < 0. + gp_Elips (const gp_Ax2& theA2, const Standard_Real theMajorRadius, const Standard_Real theMinorRadius) + : pos (theA2), + majorRadius (theMajorRadius), + minorRadius (theMinorRadius) + { + Standard_ConstructionError_Raise_if (theMinorRadius < 0.0 || theMajorRadius < theMinorRadius, + "gp_Elips() - invalid construction parameters"); + } //! Changes the axis normal to the plane of the ellipse. //! It modifies the definition of this plane. //! The "XAxis" and the "YAxis" are recomputed. //! The local coordinate system is redefined so that: //! - its origin and "main Direction" become those of the - //! axis A1 (the "X Direction" and "Y Direction" are then + //! axis theA1 (the "X Direction" and "Y Direction" are then //! recomputed in the same way as for any gp_Ax2), or - //! Raises ConstructionError if the direction of A1 + //! Raises ConstructionError if the direction of theA1 //! is parallel to the direction of the "XAxis" of the ellipse. - void SetAxis (const gp_Ax1& A1); - + void SetAxis (const gp_Ax1& theA1) { pos.SetAxis (theA1); } + //! Modifies this ellipse, by redefining its local coordinate - //! so that its origin becomes P. - void SetLocation (const gp_Pnt& P); - + //! so that its origin becomes theP. + void SetLocation (const gp_Pnt& theP) { pos.SetLocation (theP); } //! The major radius of the ellipse is on the "XAxis" (major axis) //! of the ellipse. - //! Raises ConstructionError if MajorRadius < MinorRadius. - void SetMajorRadius (const Standard_Real MajorRadius); - + //! Raises ConstructionError if theMajorRadius < MinorRadius. + void SetMajorRadius (const Standard_Real theMajorRadius) + { + Standard_ConstructionError_Raise_if (theMajorRadius < minorRadius, + "gp_Elips::SetMajorRadius() - major radius should be greater or equal to minor radius"); + majorRadius = theMajorRadius; + } //! The minor radius of the ellipse is on the "YAxis" (minor axis) //! of the ellipse. - //! Raises ConstructionError if MinorRadius > MajorRadius or MinorRadius < 0. - void SetMinorRadius (const Standard_Real MinorRadius); - + //! Raises ConstructionError if theMinorRadius > MajorRadius or MinorRadius < 0. + void SetMinorRadius (const Standard_Real theMinorRadius) + { + Standard_ConstructionError_Raise_if (theMinorRadius < 0.0 || majorRadius < theMinorRadius, + "gp_Elips::SetMinorRadius() - minor radius should be a positive number lesser or equal to major radius"); + minorRadius = theMinorRadius; + } + //! Modifies this ellipse, by redefining its local coordinate - //! so that it becomes A2e. - void SetPosition (const gp_Ax2& A2); - + //! so that it becomes theA2. + void SetPosition (const gp_Ax2& theA2) { pos = theA2; } + //! Computes the area of the Ellipse. - Standard_Real Area() const; - + Standard_Real Area() const { return M_PI * majorRadius * minorRadius; } //! Computes the axis normal to the plane of the ellipse. - const gp_Ax1& Axis() const; - + const gp_Ax1& Axis() const { return pos.Axis(); } + //! Computes the first or second directrix of this ellipse. //! These are the lines, in the plane of the ellipse, normal to //! the major axis, at a distance equal to @@ -131,149 +134,304 @@ public: //! Exceptions //! Standard_ConstructionError if the eccentricity is null //! (the ellipse has degenerated into a circle). - gp_Ax1 Directrix1() const; - + gp_Ax1 Directrix1() const; //! This line is obtained by the symmetrical transformation //! of "Directrix1" with respect to the "YAxis" of the ellipse. //! Exceptions //! Standard_ConstructionError if the eccentricity is null //! (the ellipse has degenerated into a circle). - gp_Ax1 Directrix2() const; - + gp_Ax1 Directrix2() const; //! Returns the eccentricity of the ellipse between 0.0 and 1.0 //! If f is the distance between the center of the ellipse and //! the Focus1 then the eccentricity e = f / MajorRadius. //! Raises ConstructionError if MajorRadius = 0.0 - Standard_Real Eccentricity() const; - + Standard_Real Eccentricity() const; //! Computes the focal distance. It is the distance between the //! two focus focus1 and focus2 of the ellipse. - Standard_Real Focal() const; - + Standard_Real Focal() const + { + return 2.0 * sqrt (majorRadius * majorRadius - minorRadius * minorRadius); + } //! Returns the first focus of the ellipse. This focus is on the //! positive side of the "XAxis" of the ellipse. - gp_Pnt Focus1() const; - + gp_Pnt Focus1() const; //! Returns the second focus of the ellipse. This focus is on the //! negative side of the "XAxis" of the ellipse. - gp_Pnt Focus2() const; - + gp_Pnt Focus2() const; //! Returns the center of the ellipse. It is the "Location" //! point of the coordinate system of the ellipse. - const gp_Pnt& Location() const; - + const gp_Pnt& Location() const { return pos.Location(); } + //! Returns the major radius of the ellipse. - Standard_Real MajorRadius() const; - + Standard_Real MajorRadius() const { return majorRadius; } + //! Returns the minor radius of the ellipse. - Standard_Real MinorRadius() const; - + Standard_Real MinorRadius() const { return minorRadius; } //! Returns p = (1 - e * e) * MajorRadius where e is the eccentricity //! of the ellipse. //! Returns 0 if MajorRadius = 0 - Standard_Real Parameter() const; - + Standard_Real Parameter() const; + //! Returns the coordinate system of the ellipse. - const gp_Ax2& Position() const; - + const gp_Ax2& Position() const { return pos; } //! Returns the "XAxis" of the ellipse whose origin //! is the center of this ellipse. It is the major axis of the //! ellipse. - gp_Ax1 XAxis() const; - + gp_Ax1 XAxis() const { return gp_Ax1 (pos.Location(), pos.XDirection()); } //! Returns the "YAxis" of the ellipse whose unit vector is the "X Direction" or the "Y Direction" //! of the local coordinate system of this ellipse. //! This is the minor axis of the ellipse. - gp_Ax1 YAxis() const; - - Standard_EXPORT void Mirror (const gp_Pnt& P); - + gp_Ax1 YAxis() const { return gp_Ax1 (pos.Location(), pos.YDirection()); } + + Standard_EXPORT void Mirror (const gp_Pnt& theP); //! Performs the symmetrical transformation of an ellipse with - //! respect to the point P which is the center of the symmetry. - Standard_NODISCARD Standard_EXPORT gp_Elips Mirrored (const gp_Pnt& P) const; - - Standard_EXPORT void Mirror (const gp_Ax1& A1); - + //! respect to the point theP which is the center of the symmetry. + Standard_NODISCARD Standard_EXPORT gp_Elips Mirrored (const gp_Pnt& theP) const; + + Standard_EXPORT void Mirror (const gp_Ax1& theA1); //! Performs the symmetrical transformation of an ellipse with //! respect to an axis placement which is the axis of the symmetry. - Standard_NODISCARD Standard_EXPORT gp_Elips Mirrored (const gp_Ax1& A1) const; - - Standard_EXPORT void Mirror (const gp_Ax2& A2); - + Standard_NODISCARD Standard_EXPORT gp_Elips Mirrored (const gp_Ax1& theA1) const; + + Standard_EXPORT void Mirror (const gp_Ax2& theA2); //! Performs the symmetrical transformation of an ellipse with - //! respect to a plane. The axis placement A2 locates the plane + //! respect to a plane. The axis placement theA2 locates the plane //! of the symmetry (Location, XDirection, YDirection). - Standard_NODISCARD Standard_EXPORT gp_Elips Mirrored (const gp_Ax2& A2) const; - - void Rotate (const gp_Ax1& A1, const Standard_Real Ang); - + Standard_NODISCARD Standard_EXPORT gp_Elips Mirrored (const gp_Ax2& theA2) const; - //! Rotates an ellipse. A1 is the axis of the rotation. - //! Ang is the angular value of the rotation in radians. - Standard_NODISCARD gp_Elips Rotated (const gp_Ax1& A1, const Standard_Real Ang) const; - - void Scale (const gp_Pnt& P, const Standard_Real S); - + void Rotate (const gp_Ax1& theA1, const Standard_Real theAng) { pos.Rotate (theA1, theAng); } - //! Scales an ellipse. S is the scaling value. - Standard_NODISCARD gp_Elips Scaled (const gp_Pnt& P, const Standard_Real S) const; - - void Transform (const gp_Trsf& T); - + //! Rotates an ellipse. theA1 is the axis of the rotation. + //! theAng is the angular value of the rotation in radians. + Standard_NODISCARD gp_Elips Rotated (const gp_Ax1& theA1, const Standard_Real theAng) const + { + gp_Elips anE = *this; + anE.pos.Rotate (theA1, theAng); + return anE; + } - //! Transforms an ellipse with the transformation T from class Trsf. - Standard_NODISCARD gp_Elips Transformed (const gp_Trsf& T) const; - - void Translate (const gp_Vec& V); - + void Scale (const gp_Pnt& theP, const Standard_Real theS); - //! Translates an ellipse in the direction of the vector V. + //! Scales an ellipse. theS is the scaling value. + Standard_NODISCARD gp_Elips Scaled (const gp_Pnt& theP, const Standard_Real theS) const; + + void Transform (const gp_Trsf& theT); + + //! Transforms an ellipse with the transformation theT from class Trsf. + Standard_NODISCARD gp_Elips Transformed (const gp_Trsf& theT) const; + + void Translate (const gp_Vec& theV) { pos.Translate (theV); } + + //! Translates an ellipse in the direction of the vector theV. //! The magnitude of the translation is the vector's magnitude. - Standard_NODISCARD gp_Elips Translated (const gp_Vec& V) const; - - void Translate (const gp_Pnt& P1, const gp_Pnt& P2); - - - //! Translates an ellipse from the point P1 to the point P2. - Standard_NODISCARD gp_Elips Translated (const gp_Pnt& P1, const gp_Pnt& P2) const; - - - - -protected: - - + Standard_NODISCARD gp_Elips Translated (const gp_Vec& theV) const + { + gp_Elips anE = *this; + anE.pos.Translate (theV); + return anE; + } + void Translate (const gp_Pnt& theP1, const gp_Pnt& theP2) { pos.Translate (theP1, theP2); } + //! Translates an ellipse from the point theP1 to the point theP2. + Standard_NODISCARD gp_Elips Translated (const gp_Pnt& theP1, const gp_Pnt& theP2) const + { + gp_Elips anE = *this; + anE.pos.Translate (theP1, theP2); + return anE; + } private: - - gp_Ax2 pos; Standard_Real majorRadius; Standard_Real minorRadius; - }; +// ======================================================================= +// function : Directrix1 +// purpose : +// ======================================================================= +inline gp_Ax1 gp_Elips::Directrix1() const +{ + Standard_Real anE = Eccentricity(); + Standard_ConstructionError_Raise_if (anE <= gp::Resolution(), "gp_Elips::Directrix1() - zero eccentricity"); + gp_XYZ anOrig = pos.XDirection().XYZ(); + anOrig.Multiply (majorRadius / anE); + anOrig.Add (pos.Location().XYZ()); + return gp_Ax1 (gp_Pnt (anOrig), pos.YDirection()); +} -#include +// ======================================================================= +// function : Directrix2 +// purpose : +// ======================================================================= +inline gp_Ax1 gp_Elips::Directrix2() const +{ + Standard_Real anE = Eccentricity(); + Standard_ConstructionError_Raise_if (anE <= gp::Resolution(), "gp_Elips::Directrix2() - zero eccentricity"); + gp_XYZ anOrig = pos.XDirection().XYZ(); + anOrig.Multiply (-majorRadius / anE); + anOrig.Add (pos.Location().XYZ()); + return gp_Ax1 (gp_Pnt (anOrig), pos.YDirection()); +} +// ======================================================================= +// function : Eccentricity +// purpose : +// ======================================================================= +inline Standard_Real gp_Elips::Eccentricity() const +{ + if (majorRadius == 0.0) + { + return 0.0; + } + else + { + return sqrt (majorRadius * majorRadius - minorRadius * minorRadius) / majorRadius; + } +} +// ======================================================================= +// function : Focus1 +// purpose : +// ======================================================================= +inline gp_Pnt gp_Elips::Focus1() const +{ + Standard_Real aC = sqrt (majorRadius * majorRadius - minorRadius * minorRadius); + const gp_Pnt& aPP = pos.Location(); + const gp_Dir& aDD = pos.XDirection(); + return gp_Pnt (aPP.X() + aC * aDD.X(), + aPP.Y() + aC * aDD.Y(), + aPP.Z() + aC * aDD.Z()); +} +// ======================================================================= +// function : Focus2 +// purpose : +// ======================================================================= +inline gp_Pnt gp_Elips::Focus2() const +{ + Standard_Real aC = sqrt (majorRadius * majorRadius - minorRadius * minorRadius); + const gp_Pnt& aPP = pos.Location(); + const gp_Dir& aDD = pos.XDirection(); + return gp_Pnt (aPP.X() - aC * aDD.X(), + aPP.Y() - aC * aDD.Y(), + aPP.Z() - aC * aDD.Z()); +} +// ======================================================================= +// function : Parameter +// purpose : +// ======================================================================= +inline Standard_Real gp_Elips::Parameter() const +{ + if (majorRadius == 0.0) + { + return 0.0; + } + else + { + return (minorRadius * minorRadius) / majorRadius; + } +} + +// ======================================================================= +// function : Scale +// purpose : +// ======================================================================= +inline void gp_Elips::Scale (const gp_Pnt& theP, + const Standard_Real theS) + // Modified by skv - Fri Apr 8 10:28:10 2005 OCC8559 Begin + // { pos.Scale(P, S); } +{ + majorRadius *= theS; + if (majorRadius < 0) + { + majorRadius = -majorRadius; + } + minorRadius *= theS; + if (minorRadius < 0) + { + minorRadius = -minorRadius; + } + pos.Scale (theP, theS); +} +// Modified by skv - Fri Apr 8 10:28:10 2005 OCC8559 End + +// ======================================================================= +// function : Scaled +// purpose : +// ======================================================================= +inline gp_Elips gp_Elips::Scaled (const gp_Pnt& theP, + const Standard_Real theS) const +{ + gp_Elips anE = *this; + anE.majorRadius *= theS; + if (anE.majorRadius < 0) + { + anE.majorRadius = -anE.majorRadius; + } + anE.minorRadius *= theS; + if (anE.minorRadius < 0) + { + anE.minorRadius = -anE.minorRadius; + } + anE.pos.Scale (theP, theS); + return anE; +} + +// ======================================================================= +// function : Transform +// purpose : +// ======================================================================= +inline void gp_Elips::Transform (const gp_Trsf& theT) +{ + majorRadius *= theT.ScaleFactor(); + if (majorRadius < 0) + { + majorRadius = -majorRadius; + } + minorRadius *= theT.ScaleFactor(); + if (minorRadius < 0) + { + minorRadius = -minorRadius; + } + pos.Transform (theT); +} + +// ======================================================================= +// function : Transformed +// purpose : +// ======================================================================= +inline gp_Elips gp_Elips::Transformed (const gp_Trsf& theT) const +{ + gp_Elips anE = *this; + anE.majorRadius *= theT.ScaleFactor(); + if (anE.majorRadius < 0) + { + anE.majorRadius = -anE.majorRadius; + } + anE.minorRadius *= theT.ScaleFactor(); + if (anE.minorRadius < 0) + { + anE.minorRadius = -anE.minorRadius; + } + anE.pos.Transform (theT); + return anE; +} #endif // _gp_Elips_HeaderFile diff --git a/src/gp/gp_Elips.lxx b/src/gp/gp_Elips.lxx deleted file mode 100644 index 543cb712ad..0000000000 --- a/src/gp/gp_Elips.lxx +++ /dev/null @@ -1,224 +0,0 @@ -// Copyright (c) 1995-1999 Matra Datavision -// Copyright (c) 1999-2014 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -// Modified by skv - Fri Apr 8 10:28:10 2005 OCC8559 - - -#include -#include - -inline gp_Elips::gp_Elips () : -majorRadius (RealLast()), -minorRadius (RealSmall()) -{ } - -inline gp_Elips::gp_Elips (const gp_Ax2& A2, - const Standard_Real MajorRadius, - const Standard_Real MinorRadius) : - pos(A2), - majorRadius (MajorRadius), - minorRadius (MinorRadius) -{ - Standard_ConstructionError_Raise_if (MinorRadius < 0.0 || MajorRadius < MinorRadius, - "gp_Elips() - invalid construction parameters"); -} - -inline Standard_Real gp_Elips::Area() const -{ return M_PI * majorRadius * minorRadius; } - -inline Standard_Real gp_Elips::MajorRadius() const -{ return majorRadius; } - -inline Standard_Real gp_Elips::MinorRadius() const -{ return minorRadius; } - -inline Standard_Real gp_Elips::Parameter() const -{ - if (majorRadius == 0.0) return 0.0; - else return (minorRadius * minorRadius) / majorRadius; -} - -inline const gp_Ax2& gp_Elips::Position() const -{ return pos; } - -inline const gp_Ax1& gp_Elips::Axis () const -{ return pos.Axis(); } - -inline gp_Ax1 gp_Elips::Directrix1() const -{ - Standard_Real E = Eccentricity(); - Standard_ConstructionError_Raise_if (E <= gp::Resolution(), "gp_Elips::Directrix1() - zero eccentricity"); - gp_XYZ Orig = pos.XDirection().XYZ(); - Orig.Multiply (majorRadius/E); - Orig.Add (pos.Location().XYZ()); - return gp_Ax1 (gp_Pnt(Orig), pos.YDirection()); -} - -inline gp_Ax1 gp_Elips::Directrix2() const -{ - Standard_Real E = Eccentricity(); - Standard_ConstructionError_Raise_if (E <= gp::Resolution(), "gp_Elips::Directrix2() - zero eccentricity"); - gp_XYZ Orig = pos.XDirection().XYZ(); - Orig.Multiply (-majorRadius/E); - Orig.Add (pos.Location().XYZ()); - return gp_Ax1 (gp_Pnt(Orig), pos.YDirection()); -} - -inline Standard_Real gp_Elips::Eccentricity() const -{ - if (majorRadius == 0.0) { return 0.0; } - else { - return sqrt(majorRadius * majorRadius - - minorRadius * minorRadius) / majorRadius; - } -} - -inline Standard_Real gp_Elips::Focal() const -{ - return 2.0 * sqrt(majorRadius * majorRadius - - minorRadius * minorRadius); -} - -inline gp_Pnt gp_Elips::Focus1() const -{ - Standard_Real C = sqrt(majorRadius * majorRadius - - minorRadius * minorRadius); - const gp_Pnt& PP = pos.Location (); - const gp_Dir& DD = pos.XDirection(); - return gp_Pnt (PP.X() + C * DD.X(), - PP.Y() + C * DD.Y(), - PP.Z() + C * DD.Z()); -} - -inline gp_Pnt gp_Elips::Focus2() const -{ - Standard_Real C = sqrt(majorRadius * majorRadius - - minorRadius * minorRadius); - const gp_Pnt& PP = pos.Location (); - const gp_Dir& DD = pos.XDirection(); - return gp_Pnt (PP.X() - C * DD.X(), - PP.Y() - C * DD.Y(), - PP.Z() - C * DD.Z()); -} - -inline const gp_Pnt& gp_Elips::Location () const -{ return pos.Location(); } - -inline gp_Ax1 gp_Elips::XAxis () const -{ return gp_Ax1 (pos.Location(), pos.XDirection()); } - -inline gp_Ax1 gp_Elips::YAxis () const -{ return gp_Ax1 (pos.Location(), pos.YDirection()); } - -inline void gp_Elips::SetAxis (const gp_Ax1& A1) -{ pos.SetAxis(A1); } - -inline void gp_Elips::SetPosition (const gp_Ax2& A2) -{ pos = A2; } - -inline void gp_Elips::SetLocation (const gp_Pnt& P) -{ pos.SetLocation (P); } - -inline void gp_Elips::SetMajorRadius (const Standard_Real R) -{ - Standard_ConstructionError_Raise_if (R < minorRadius, - "gp_Elips::SetMajorRadius() - major radius should be greater or equal to minor radius"); - majorRadius = R; -} - -inline void gp_Elips::SetMinorRadius (const Standard_Real R) -{ - Standard_ConstructionError_Raise_if (R < 0.0 || majorRadius < R, - "gp_Elips::SetMinorRadius() - minor radius should be a positive number lesser or equal to major radius"); - minorRadius = R; -} - -inline void gp_Elips::Rotate (const gp_Ax1& A1, - const Standard_Real Ang) { pos.Rotate(A1, Ang); } - -inline gp_Elips gp_Elips::Rotated (const gp_Ax1& A1, - const Standard_Real Ang) const -{ - gp_Elips E = *this; - E.pos.Rotate(A1, Ang); - return E; -} - -inline void gp_Elips::Scale (const gp_Pnt& P, - const Standard_Real S) -// Modified by skv - Fri Apr 8 10:28:10 2005 OCC8559 Begin -// { pos.Scale(P, S); } -{ - majorRadius *= S; - if (majorRadius < 0) majorRadius = - majorRadius; - minorRadius *= S; - if (minorRadius < 0) minorRadius = - minorRadius; - pos.Scale(P, S); -} -// Modified by skv - Fri Apr 8 10:28:10 2005 OCC8559 End - -inline gp_Elips gp_Elips::Scaled (const gp_Pnt& P, - const Standard_Real S) const -{ - gp_Elips E = *this; - E.majorRadius *= S; - if (E.majorRadius < 0) E.majorRadius = - E.majorRadius; - E.minorRadius *= S; - if (E.minorRadius < 0) E.minorRadius = - E.minorRadius; - E.pos.Scale(P, S); - return E; -} - -inline void gp_Elips::Transform (const gp_Trsf& T) -{ - majorRadius *= T.ScaleFactor(); - if (majorRadius < 0) majorRadius = - majorRadius; - minorRadius *= T.ScaleFactor(); - if (minorRadius < 0) minorRadius = - minorRadius; - pos.Transform(T); -} - -inline gp_Elips gp_Elips::Transformed (const gp_Trsf& T) const -{ - gp_Elips E = *this; - E.majorRadius *= T.ScaleFactor(); - if (E.majorRadius < 0) E.majorRadius = - E.majorRadius; - E.minorRadius *= T.ScaleFactor(); - if (E.minorRadius < 0) E.minorRadius = - E.minorRadius; - E.pos.Transform(T); - return E; -} - -inline void gp_Elips::Translate (const gp_Vec& V) -{ pos.Translate(V); } - -inline gp_Elips gp_Elips::Translated (const gp_Vec& V) const -{ - gp_Elips E = *this; - E.pos.Translate(V); - return E; -} - -inline void gp_Elips::Translate (const gp_Pnt& P1, - const gp_Pnt& P2) -{ pos.Translate(P1, P2); } - -inline gp_Elips gp_Elips::Translated (const gp_Pnt& P1, - const gp_Pnt& P2) const -{ - gp_Elips E = *this; - E.pos.Translate(P1, P2); - return E; -} - diff --git a/src/gp/gp_Elips2d.cxx b/src/gp/gp_Elips2d.cxx index 3be08b94da..97c41946d5 100644 --- a/src/gp/gp_Elips2d.cxx +++ b/src/gp/gp_Elips2d.cxx @@ -14,9 +14,10 @@ //Modif JCV 10/01/91 +#include + #include #include -#include #include #include #include diff --git a/src/gp/gp_Elips2d.hxx b/src/gp/gp_Elips2d.hxx index 0a1dc05660..780539d5e1 100644 --- a/src/gp/gp_Elips2d.hxx +++ b/src/gp/gp_Elips2d.hxx @@ -15,23 +15,11 @@ #ifndef _gp_Elips2d_HeaderFile #define _gp_Elips2d_HeaderFile -#include -#include -#include - +#include #include -#include -#include #include #include -class Standard_ConstructionError; -class gp_Ax2d; -class gp_Ax22d; -class gp_Pnt2d; -class gp_Trsf2d; -class gp_Vec2d; - - +#include //! Describes an ellipse in the plane (2D space). //! An ellipse is defined by its major and minor radii and @@ -59,76 +47,101 @@ public: DEFINE_STANDARD_ALLOC - //! Creates an indefinite ellipse. - gp_Elips2d(); - + gp_Elips2d() + : majorRadius (RealLast()), + minorRadius (RealSmall()) + {} //! Creates an ellipse with the major axis, the major and the - //! minor radius. The location of the MajorAxis is the center + //! minor radius. The location of the theMajorAxis is the center //! of the ellipse. - //! The sense of parametrization is given by Sense. + //! The sense of parametrization is given by theIsSense. //! Warnings : //! It is possible to create an ellipse with - //! MajorRadius = MinorRadius. - //! Raises ConstructionError if MajorRadius < MinorRadius or MinorRadius < 0.0 - gp_Elips2d(const gp_Ax2d& MajorAxis, const Standard_Real MajorRadius, const Standard_Real MinorRadius, const Standard_Boolean Sense = Standard_True); - + //! theMajorRadius = theMinorRadius. + //! Raises ConstructionError if theMajorRadius < theMinorRadius or theMinorRadius < 0.0 + gp_Elips2d (const gp_Ax2d& theMajorAxis, const Standard_Real theMajorRadius, + const Standard_Real theMinorRadius, const Standard_Boolean theIsSense = Standard_True) + : majorRadius (theMajorRadius), + minorRadius (theMinorRadius) + { + pos = gp_Ax22d (theMajorAxis, theIsSense); + Standard_ConstructionError_Raise_if (theMinorRadius < 0.0 || theMajorRadius < theMinorRadius, + "gp_Elips2d() - invalid construction parameters"); + } + //! Creates an ellipse with radii MajorRadius and - //! MinorRadius, positioned in the plane by coordinate system A where: - //! - the origin of A is the center of the ellipse, - //! - the "X Direction" of A defines the major axis of + //! MinorRadius, positioned in the plane by coordinate system theA where: + //! - the origin of theA is the center of the ellipse, + //! - the "X Direction" of theA defines the major axis of //! the ellipse, that is, the major radius MajorRadius //! is measured along this axis, and - //! - the "Y Direction" of A defines the minor axis of - //! the ellipse, that is, the minor radius MinorRadius + //! - the "Y Direction" of theA defines the minor axis of + //! the ellipse, that is, the minor radius theMinorRadius //! is measured along this axis, and - //! - the orientation (direct or indirect sense) of A + //! - the orientation (direct or indirect sense) of theA //! gives the orientation of the ellipse. //! Warnings : //! It is possible to create an ellipse with - //! MajorRadius = MinorRadius. - //! Raises ConstructionError if MajorRadius < MinorRadius or MinorRadius < 0.0 - gp_Elips2d(const gp_Ax22d& A, const Standard_Real MajorRadius, const Standard_Real MinorRadius); - + //! theMajorRadius = theMinorRadius. + //! Raises ConstructionError if theMajorRadius < theMinorRadius or theMinorRadius < 0.0 + gp_Elips2d (const gp_Ax22d& theA, const Standard_Real theMajorRadius, const Standard_Real theMinorRadius) + : pos (theA), + majorRadius (theMajorRadius), + minorRadius (theMinorRadius) + { + Standard_ConstructionError_Raise_if (theMinorRadius < 0.0 || theMajorRadius < theMinorRadius, + "gp_Elips2d() - invalid construction parameters"); + } + //! Modifies this ellipse, by redefining its local coordinate system so that - //! - its origin becomes P. - void SetLocation (const gp_Pnt2d& P); - + //! - its origin becomes theP. + void SetLocation (const gp_Pnt2d& theP) { pos.SetLocation (theP); } + //! Changes the value of the major radius. - //! Raises ConstructionError if MajorRadius < MinorRadius. - void SetMajorRadius (const Standard_Real MajorRadius); + //! Raises ConstructionError if theMajorRadius < MinorRadius. + void SetMajorRadius (const Standard_Real theMajorRadius) + { + Standard_ConstructionError_Raise_if (theMajorRadius < minorRadius, + "gp_Elips2d::SetMajorRadius() - major radius should be greater or equal to minor radius"); + majorRadius = theMajorRadius; + } //! Changes the value of the minor radius. - //! Raises ConstructionError if MajorRadius < MinorRadius or MinorRadius < 0.0 - void SetMinorRadius (const Standard_Real MinorRadius); - + //! Raises ConstructionError if MajorRadius < theMinorRadius or MinorRadius < 0.0 + void SetMinorRadius (const Standard_Real theMinorRadius) + { + Standard_ConstructionError_Raise_if (theMinorRadius < 0.0 || majorRadius < theMinorRadius, + "gp_Elips2d::SetMinorRadius() - minor radius should be a positive number lesser or equal to major radius"); + minorRadius = theMinorRadius; + } + //! Modifies this ellipse, by redefining its local coordinate system so that - //! it becomes A. - void SetAxis (const gp_Ax22d& A); - + //! it becomes theA. + void SetAxis (const gp_Ax22d& theA) { pos.SetAxis (theA); } + //! Modifies this ellipse, by redefining its local coordinate system so that //! its origin and its "X Direction" become those - //! of the axis A. The "Y Direction" is then + //! of the axis theA. The "Y Direction" is then //! recomputed. The orientation of the local coordinate //! system is not modified. - void SetXAxis (const gp_Ax2d& A); - + void SetXAxis (const gp_Ax2d& theA) { pos.SetXAxis (theA); } + //! Modifies this ellipse, by redefining its local coordinate system so that //! its origin and its "Y Direction" become those - //! of the axis A. The "X Direction" is then + //! of the axis theA. The "X Direction" is then //! recomputed. The orientation of the local coordinate //! system is not modified. - void SetYAxis (const gp_Ax2d& A); - + void SetYAxis (const gp_Ax2d& theA) { pos.SetYAxis (theA); } + //! Computes the area of the ellipse. - Standard_Real Area() const; - + Standard_Real Area() const { return M_PI * majorRadius * minorRadius; } //! Returns the coefficients of the implicit equation of the ellipse. - //! A * (X**2) + B * (Y**2) + 2*C*(X*Y) + 2*D*X + 2*E*Y + F = 0. - Standard_EXPORT void Coefficients (Standard_Real& A, Standard_Real& B, Standard_Real& C, Standard_Real& D, Standard_Real& E, Standard_Real& F) const; - + //! theA * (X**2) + theB * (Y**2) + 2*theC*(X*Y) + 2*theD*X + 2*theE*Y + theF = 0. + Standard_EXPORT void Coefficients (Standard_Real& theA, Standard_Real& theB, Standard_Real& theC, + Standard_Real& theD, Standard_Real& theE, Standard_Real& theF) const; //! This directrix is the line normal to the XAxis of the ellipse //! in the local plane (Z = 0) at a distance d = MajorRadius / e @@ -140,139 +153,308 @@ public: //! //! Raised if Eccentricity = 0.0. (The ellipse degenerates into a //! circle) - gp_Ax2d Directrix1() const; - + gp_Ax2d Directrix1() const; //! This line is obtained by the symmetrical transformation //! of "Directrix1" with respect to the minor axis of the ellipse. //! //! Raised if Eccentricity = 0.0. (The ellipse degenerates into a //! circle). - gp_Ax2d Directrix2() const; - + gp_Ax2d Directrix2() const; //! Returns the eccentricity of the ellipse between 0.0 and 1.0 //! If f is the distance between the center of the ellipse and //! the Focus1 then the eccentricity e = f / MajorRadius. //! Returns 0 if MajorRadius = 0. - Standard_Real Eccentricity() const; - + Standard_Real Eccentricity() const; //! Returns the distance between the center of the ellipse //! and focus1 or focus2. - Standard_Real Focal() const; - + Standard_Real Focal() const + { + return 2.0 * sqrt (majorRadius * majorRadius - minorRadius * minorRadius); + } //! Returns the first focus of the ellipse. This focus is on the //! positive side of the major axis of the ellipse. - gp_Pnt2d Focus1() const; - + gp_Pnt2d Focus1() const; //! Returns the second focus of the ellipse. This focus is on the //! negative side of the major axis of the ellipse. - gp_Pnt2d Focus2() const; - + gp_Pnt2d Focus2() const; + //! Returns the center of the ellipse. - const gp_Pnt2d& Location() const; - + const gp_Pnt2d& Location() const { return pos.Location(); } + //! Returns the major radius of the Ellipse. - Standard_Real MajorRadius() const; - + Standard_Real MajorRadius() const { return majorRadius; } + //! Returns the minor radius of the Ellipse. - Standard_Real MinorRadius() const; - + Standard_Real MinorRadius() const { return minorRadius; } //! Returns p = (1 - e * e) * MajorRadius where e is the eccentricity //! of the ellipse. //! Returns 0 if MajorRadius = 0 - Standard_Real Parameter() const; - + Standard_Real Parameter() const; + //! Returns the major axis of the ellipse. - const gp_Ax22d& Axis() const; - + const gp_Ax22d& Axis() const { return pos; } + //! Returns the major axis of the ellipse. - gp_Ax2d XAxis() const; - + gp_Ax2d XAxis() const { return pos.XAxis(); } + //! Returns the minor axis of the ellipse. //! Reverses the direction of the circle. - gp_Ax2d YAxis() const; - - void Reverse(); - - Standard_NODISCARD gp_Elips2d Reversed() const; - + gp_Ax2d YAxis() const { return pos.YAxis(); } + + void Reverse() + { + gp_Dir2d aTemp = pos.YDirection(); + aTemp.Reverse(); + pos.SetAxis (gp_Ax22d (pos.Location(), pos.XDirection(), aTemp)); + } + + Standard_NODISCARD gp_Elips2d Reversed() const; + //! Returns true if the local coordinate system is direct //! and false in the other case. - Standard_Boolean IsDirect() const; - - Standard_EXPORT void Mirror (const gp_Pnt2d& P); - + Standard_Boolean IsDirect() const { return (pos.XDirection().Crossed (pos.YDirection())) >= 0.0; } + + Standard_EXPORT void Mirror (const gp_Pnt2d& theP); //! Performs the symmetrical transformation of a ellipse with respect - //! to the point P which is the center of the symmetry - Standard_NODISCARD Standard_EXPORT gp_Elips2d Mirrored (const gp_Pnt2d& P) const; - - Standard_EXPORT void Mirror (const gp_Ax2d& A); - + //! to the point theP which is the center of the symmetry + Standard_NODISCARD Standard_EXPORT gp_Elips2d Mirrored (const gp_Pnt2d& theP) const; + + Standard_EXPORT void Mirror (const gp_Ax2d& theA); //! Performs the symmetrical transformation of a ellipse with respect //! to an axis placement which is the axis of the symmetry. - Standard_NODISCARD Standard_EXPORT gp_Elips2d Mirrored (const gp_Ax2d& A) const; - - void Rotate (const gp_Pnt2d& P, const Standard_Real Ang); - - Standard_NODISCARD gp_Elips2d Rotated (const gp_Pnt2d& P, const Standard_Real Ang) const; - - void Scale (const gp_Pnt2d& P, const Standard_Real S); - + Standard_NODISCARD Standard_EXPORT gp_Elips2d Mirrored (const gp_Ax2d& theA) const; - //! Scales a ellipse. S is the scaling value. - Standard_NODISCARD gp_Elips2d Scaled (const gp_Pnt2d& P, const Standard_Real S) const; - - void Transform (const gp_Trsf2d& T); - + void Rotate (const gp_Pnt2d& theP, const Standard_Real theAng) { pos.Rotate (theP, theAng); } - //! Transforms an ellipse with the transformation T from class Trsf2d. - Standard_NODISCARD gp_Elips2d Transformed (const gp_Trsf2d& T) const; - - void Translate (const gp_Vec2d& V); - + Standard_NODISCARD gp_Elips2d Rotated (const gp_Pnt2d& theP, const Standard_Real theAng) const + { + gp_Elips2d anE = *this; + anE.pos.Rotate (theP, theAng); + return anE; + } - //! Translates a ellipse in the direction of the vector V. + void Scale (const gp_Pnt2d& theP, const Standard_Real theS); + + //! Scales a ellipse. theS is the scaling value. + Standard_NODISCARD gp_Elips2d Scaled (const gp_Pnt2d& theP, const Standard_Real theS) const; + + void Transform (const gp_Trsf2d& theT); + + //! Transforms an ellipse with the transformation theT from class Trsf2d. + Standard_NODISCARD gp_Elips2d Transformed (const gp_Trsf2d& theT) const; + + void Translate (const gp_Vec2d& theV) { pos.Translate (theV); } + + //! Translates a ellipse in the direction of the vector theV. //! The magnitude of the translation is the vector's magnitude. - Standard_NODISCARD gp_Elips2d Translated (const gp_Vec2d& V) const; - - void Translate (const gp_Pnt2d& P1, const gp_Pnt2d& P2); - - - //! Translates a ellipse from the point P1 to the point P2. - Standard_NODISCARD gp_Elips2d Translated (const gp_Pnt2d& P1, const gp_Pnt2d& P2) const; - - - - -protected: - - + Standard_NODISCARD gp_Elips2d Translated (const gp_Vec2d& theV) const + { + gp_Elips2d anE = *this; + anE.pos.Translate (theV); + return anE; + } + void Translate (const gp_Pnt2d& theP1, const gp_Pnt2d& theP2) { pos.Translate (theP1, theP2); } + //! Translates a ellipse from the point theP1 to the point theP2. + Standard_NODISCARD gp_Elips2d Translated (const gp_Pnt2d& theP1, const gp_Pnt2d& theP2) const + { + gp_Elips2d anE = *this; + anE.pos.Translate (theP1, theP2); + return anE; + } private: - - gp_Ax22d pos; Standard_Real majorRadius; Standard_Real minorRadius; - }; -#include +// ======================================================================= +// function : Directrix1 +// purpose : +// ======================================================================= +inline gp_Ax2d gp_Elips2d::Directrix1() const +{ + Standard_Real anE = Eccentricity(); + Standard_ConstructionError_Raise_if (anE <= gp::Resolution(), "gp_Elips2d::Directrix1() - zero eccentricity"); + gp_XY anOrig = pos.XDirection().XY(); + anOrig.Multiply (majorRadius / anE); + anOrig.Add (pos.Location().XY()); + return gp_Ax2d (gp_Pnt2d (anOrig), gp_Dir2d (pos.YDirection())); +} +// ======================================================================= +// function : Directrix2 +// purpose : +// ======================================================================= +inline gp_Ax2d gp_Elips2d::Directrix2() const +{ + Standard_Real anE = Eccentricity(); + Standard_ConstructionError_Raise_if (anE <= gp::Resolution(), "gp_Elips2d::Directrix2() - zero eccentricity"); + gp_XY anOrig = pos.XDirection().XY(); + anOrig.Multiply (-majorRadius / anE); + anOrig.Add (pos.Location().XY()); + return gp_Ax2d (gp_Pnt2d (anOrig), gp_Dir2d (pos.YDirection())); +} +// ======================================================================= +// function : Eccentricity +// purpose : +// ======================================================================= +inline Standard_Real gp_Elips2d::Eccentricity() const +{ + if (majorRadius == 0.0) + { + return 0.0; + } + else + { + return sqrt (majorRadius * majorRadius - minorRadius * minorRadius) / majorRadius; + } +} +// ======================================================================= +// function : Focus1 +// purpose : +// ======================================================================= +inline gp_Pnt2d gp_Elips2d::Focus1() const +{ + Standard_Real aC = sqrt (majorRadius * majorRadius - minorRadius * minorRadius); + const gp_Pnt2d& aPP = pos.Location(); + const gp_Dir2d& aDD = pos.XDirection(); + return gp_Pnt2d (aPP.X() + aC * aDD.X(), + aPP.Y() + aC * aDD.Y()); +} +// ======================================================================= +// function : Focus2 +// purpose : +// ======================================================================= +inline gp_Pnt2d gp_Elips2d::Focus2() const +{ + Standard_Real aC = sqrt (majorRadius * majorRadius - minorRadius * minorRadius); + const gp_Pnt2d& aPP = pos.Location(); + const gp_Dir2d& aDD = pos.XDirection(); + return gp_Pnt2d (aPP.X() - aC * aDD.X(), + aPP.Y() - aC * aDD.Y()); +} + +// ======================================================================= +// function : Scale +// purpose : +// ======================================================================= +inline void gp_Elips2d::Scale (const gp_Pnt2d& theP, const Standard_Real theS) +{ + majorRadius *= theS; + if (majorRadius < 0) + { + majorRadius = -majorRadius; + } + minorRadius *= theS; + if (minorRadius < 0) + { + minorRadius = -minorRadius; + } + pos.Scale (theP, theS); +} + +// ======================================================================= +// function : Scaled +// purpose : +// ======================================================================= +inline gp_Elips2d gp_Elips2d::Scaled (const gp_Pnt2d& theP, const Standard_Real theS) const +{ + gp_Elips2d anE = *this; + anE.majorRadius *= theS; + if (anE.majorRadius < 0) + { + anE.majorRadius = -anE.majorRadius; + } + anE.minorRadius *= theS; + if (anE.minorRadius < 0) + { + anE.minorRadius = -anE.minorRadius; + } + anE.pos.Scale (theP, theS); + return anE; +} + +// ======================================================================= +// function : Parameter +// purpose : +// ======================================================================= +inline Standard_Real gp_Elips2d::Parameter() const +{ + if (majorRadius == 0.0) + { + return 0.0; + } + else + { + return (minorRadius * minorRadius) / majorRadius; + } +} + +// ======================================================================= +// function : Reversed +// purpose : +// ======================================================================= +inline gp_Elips2d gp_Elips2d::Reversed() const +{ + gp_Elips2d anE = *this; + gp_Dir2d aTemp = pos.YDirection (); + aTemp.Reverse (); + anE.pos.SetAxis (gp_Ax22d (pos.Location(),pos.XDirection(), aTemp)); + return anE; +} + +// ======================================================================= +// function : Transform +// purpose : +// ======================================================================= +inline void gp_Elips2d::Transform (const gp_Trsf2d& theT) +{ + Standard_Real aTSca = theT.ScaleFactor(); + if (aTSca < 0.0) + { + aTSca = -aTSca; + } + majorRadius *= aTSca; + minorRadius *= aTSca; + pos.Transform (theT); +} + +// ======================================================================= +// function : Transformed +// purpose : +// ======================================================================= +inline gp_Elips2d gp_Elips2d::Transformed (const gp_Trsf2d& theT) const +{ + gp_Elips2d anE = *this; + anE.majorRadius *= theT.ScaleFactor(); + if (anE.majorRadius < 0) + { + anE.majorRadius = -anE.majorRadius; + } + anE.minorRadius *= theT.ScaleFactor(); + if (anE.minorRadius < 0) + { + anE.minorRadius = -anE.minorRadius; + } + anE.pos.Transform (theT); + return anE; +} #endif // _gp_Elips2d_HeaderFile diff --git a/src/gp/gp_Elips2d.lxx b/src/gp/gp_Elips2d.lxx deleted file mode 100644 index fb689fc5eb..0000000000 --- a/src/gp/gp_Elips2d.lxx +++ /dev/null @@ -1,249 +0,0 @@ -// Copyright (c) 1995-1999 Matra Datavision -// Copyright (c) 1999-2014 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -#include -#include -#include - -inline gp_Elips2d::gp_Elips2d() : -majorRadius(RealLast()), -minorRadius(RealSmall()) -{ } - -inline gp_Elips2d::gp_Elips2d (const gp_Ax2d& MajorAxis, - const Standard_Real MajorRadius, - const Standard_Real MinorRadius, - const Standard_Boolean Sense) : - majorRadius(MajorRadius), - minorRadius(MinorRadius) -{ - pos = gp_Ax22d(MajorAxis,Sense); - Standard_ConstructionError_Raise_if (MinorRadius < 0.0 || MajorRadius < MinorRadius, - "gp_Elips2d() - invalid construction parameters"); -} - -inline gp_Elips2d::gp_Elips2d (const gp_Ax22d& A, - const Standard_Real MajorRadius, - const Standard_Real MinorRadius) : - pos(A), - majorRadius(MajorRadius), - minorRadius(MinorRadius) -{ - Standard_ConstructionError_Raise_if (MinorRadius < 0.0 || MajorRadius < MinorRadius, - "gp_Elips2d() - invalid construction parameters"); -} - -inline void gp_Elips2d::SetLocation (const gp_Pnt2d& P) -{ pos.SetLocation(P);} - -inline void gp_Elips2d::SetMajorRadius (const Standard_Real MajorRadius) -{ - Standard_ConstructionError_Raise_if (MajorRadius < minorRadius, - "gp_Elips2d::SetMajorRadius() - major radius should be greater or equal to minor radius"); - majorRadius = MajorRadius; -} - -inline void gp_Elips2d::SetMinorRadius (const Standard_Real MinorRadius) -{ - Standard_ConstructionError_Raise_if (MinorRadius < 0.0 || majorRadius < MinorRadius, - "gp_Elips2d::SetMinorRadius() - minor radius should be a positive number lesser or equal to major radius"); - minorRadius = MinorRadius; -} - -inline void gp_Elips2d::SetXAxis (const gp_Ax2d& A) -{ pos.SetXAxis(A); } - -inline void gp_Elips2d::SetAxis (const gp_Ax22d& A) -{ pos.SetAxis(A); } - -inline void gp_Elips2d::SetYAxis (const gp_Ax2d& A) -{ pos.SetYAxis(A); } - -inline Standard_Real gp_Elips2d::Area() const -{ return M_PI * majorRadius * minorRadius; } - -inline gp_Ax2d gp_Elips2d::Directrix1() const -{ - Standard_Real E = Eccentricity(); - Standard_ConstructionError_Raise_if (E <= gp::Resolution(), "gp_Elips2d::Directrix1() - zero eccentricity"); - gp_XY Orig = pos.XDirection().XY(); - Orig.Multiply (majorRadius/E); - Orig.Add (pos.Location().XY()); - return gp_Ax2d (gp_Pnt2d(Orig),gp_Dir2d (pos.YDirection())); -} - -inline gp_Ax2d gp_Elips2d::Directrix2() const -{ - Standard_Real E = Eccentricity(); - Standard_ConstructionError_Raise_if (E <= gp::Resolution(), "gp_Elips2d::Directrix2() - zero eccentricity"); - gp_XY Orig = pos.XDirection().XY(); - Orig.Multiply (-majorRadius/E); - Orig.Add (pos.Location().XY()); - return gp_Ax2d (gp_Pnt2d(Orig),gp_Dir2d (pos.YDirection())); -} - -inline Standard_Real gp_Elips2d::Eccentricity() const -{ - if (majorRadius == 0.0) { return 0.0; } - else { - return sqrt(majorRadius * majorRadius - - minorRadius * minorRadius) / majorRadius; - } -} - -inline Standard_Real gp_Elips2d::Focal() const -{ - return 2.0 * sqrt(majorRadius * majorRadius - - minorRadius * minorRadius); -} - -inline gp_Pnt2d gp_Elips2d::Focus1() const -{ - Standard_Real C = sqrt(majorRadius * majorRadius - - minorRadius * minorRadius); - const gp_Pnt2d& PP = pos.Location (); - const gp_Dir2d& DD = pos.XDirection(); - return gp_Pnt2d (PP.X() + C * DD.X(), - PP.Y() + C * DD.Y()); -} - -inline gp_Pnt2d gp_Elips2d::Focus2() const -{ - Standard_Real C = sqrt (majorRadius * majorRadius - - minorRadius * minorRadius); - const gp_Pnt2d& PP = pos.Location (); - const gp_Dir2d& DD = pos.XDirection(); - return gp_Pnt2d (PP.X() - C * DD.X(), - PP.Y() - C * DD.Y()); -} - -inline const gp_Pnt2d& gp_Elips2d::Location () const -{ return pos.Location(); } - -inline Standard_Real gp_Elips2d::MajorRadius() const -{ return majorRadius; } - -inline Standard_Real gp_Elips2d::MinorRadius() const -{ return minorRadius; } - -inline Standard_Real gp_Elips2d::Parameter () const -{ - if (majorRadius == 0.0) return 0.0; - else return (minorRadius * minorRadius) / majorRadius; -} - -inline const gp_Ax22d& gp_Elips2d::Axis () const -{ return pos; } - -inline gp_Ax2d gp_Elips2d::YAxis () const -{ return pos.YAxis(); } - -inline gp_Ax2d gp_Elips2d::XAxis () const -{ return pos.XAxis(); } - -inline void gp_Elips2d::Reverse() -{ - gp_Dir2d Temp = pos.YDirection (); - Temp.Reverse (); - pos.SetAxis(gp_Ax22d(pos.Location(),pos.XDirection(),Temp)); -} - -inline gp_Elips2d gp_Elips2d::Reversed() const -{ - gp_Elips2d E = *this; - gp_Dir2d Temp = pos.YDirection (); - Temp.Reverse (); - E.pos.SetAxis(gp_Ax22d(pos.Location(),pos.XDirection(),Temp)); - return E; -} - -inline Standard_Boolean gp_Elips2d::IsDirect() const -{ return (pos.XDirection().Crossed(pos.YDirection())) >= 0.0; } - -inline void gp_Elips2d::Rotate (const gp_Pnt2d& P, - const Standard_Real Ang) -{ pos.Rotate (P, Ang); } - -inline gp_Elips2d gp_Elips2d::Rotated (const gp_Pnt2d& P, - const Standard_Real Ang) const -{ - gp_Elips2d E = *this; - E.pos.Rotate (P, Ang); - return E; -} - -inline void gp_Elips2d::Scale (const gp_Pnt2d& P, - const Standard_Real S) -{ - majorRadius *= S; - if (majorRadius < 0) majorRadius = - majorRadius; - minorRadius *= S; - if (minorRadius < 0) minorRadius = - minorRadius; - pos.Scale(P, S); -} - -inline gp_Elips2d gp_Elips2d::Scaled (const gp_Pnt2d& P, - const Standard_Real S) const -{ - gp_Elips2d E = *this; - E.majorRadius *= S; - if (E.majorRadius < 0) E.majorRadius = - E.majorRadius; - E.minorRadius *= S; - if (E.minorRadius < 0) E.minorRadius = - E.minorRadius; - E.pos.Scale(P, S); - return E; -} - -inline void gp_Elips2d::Transform(const gp_Trsf2d& T) -{ - Standard_Real TSca = T.ScaleFactor(); - if(TSca<0.0) TSca=-TSca; - majorRadius *= TSca; - minorRadius *= TSca; - pos.Transform(T); -} - -inline gp_Elips2d gp_Elips2d::Transformed (const gp_Trsf2d& T) const -{ - gp_Elips2d E = *this; - E.majorRadius *= T.ScaleFactor(); - if (E.majorRadius < 0) E.majorRadius = - E.majorRadius; - E.minorRadius *= T.ScaleFactor(); - if (E.minorRadius < 0) E.minorRadius = - E.minorRadius; - E.pos.Transform(T); - return E; -} - -inline void gp_Elips2d::Translate (const gp_Vec2d& V) -{ pos.Translate(V); } - -inline gp_Elips2d gp_Elips2d::Translated (const gp_Vec2d& V) const -{ - gp_Elips2d E = *this; - E.pos.Translate(V); - return E; -} - -inline void gp_Elips2d::Translate (const gp_Pnt2d& P1, - const gp_Pnt2d& P2) -{ pos.Translate(P1, P2); } - -inline gp_Elips2d gp_Elips2d::Translated (const gp_Pnt2d& P1, - const gp_Pnt2d& P2) const -{ - gp_Elips2d E = *this; - E.pos.Translate(P1, P2); - return E; -} - diff --git a/src/gp/gp_GTrsf.cxx b/src/gp/gp_GTrsf.cxx index 76b97fd488..c69914fcc6 100644 --- a/src/gp/gp_GTrsf.cxx +++ b/src/gp/gp_GTrsf.cxx @@ -14,10 +14,10 @@ #define No_Standard_OutOfRange +#include #include #include -#include #include #include #include diff --git a/src/gp/gp_GTrsf.hxx b/src/gp/gp_GTrsf.hxx index 7bfde6c8d6..1971143d53 100644 --- a/src/gp/gp_GTrsf.hxx +++ b/src/gp/gp_GTrsf.hxx @@ -15,24 +15,17 @@ #ifndef _gp_GTrsf_HeaderFile #define _gp_GTrsf_HeaderFile -#include -#include -#include - +#include +#include #include -#include -#include -#include -#include -#include #include -class Standard_ConstructionError; -class Standard_OutOfRange; +#include +#include +#include +#include + class gp_Trsf; class gp_Mat; -class gp_XYZ; -class gp_Ax1; -class gp_Ax2; // Avoid possible conflict with SetForm macro defined by windows.h #ifdef SetForm @@ -70,62 +63,85 @@ public: DEFINE_STANDARD_ALLOC - //! Returns the Identity transformation. - gp_GTrsf(); - + gp_GTrsf() + { + shape = gp_Identity; + matrix.SetScale (1.0); + loc.SetCoord (0.0, 0.0, 0.0); + scale = 1.0; + } - //! Converts the gp_Trsf transformation T into a + //! Converts the gp_Trsf transformation theT into a //! general transformation, i.e. Returns a GTrsf with - //! the same matrix of coefficients as the Trsf T. - gp_GTrsf(const gp_Trsf& T); - + //! the same matrix of coefficients as the Trsf theT. + gp_GTrsf (const gp_Trsf& theT) + { + shape = theT.Form(); + matrix = theT.matrix; + loc = theT.TranslationPart(); + scale = theT.ScaleFactor(); + } - //! Creates a transformation based on the matrix M and the - //! vector V where M defines the vectorial part of + //! Creates a transformation based on the matrix theM and the + //! vector theV where theM defines the vectorial part of //! the transformation, and V the translation part, or - gp_GTrsf(const gp_Mat& M, const gp_XYZ& V); - - //! Changes this transformation into an affinity of ratio Ratio - //! with respect to the axis A1. - //! Note: an affinity is a point-by-point transformation that - //! transforms any point P into a point P' such that if H is - //! the orthogonal projection of P on the axis A1 or the - //! plane A2, the vectors HP and HP' satisfy: - //! HP' = Ratio * HP. - void SetAffinity (const gp_Ax1& A1, const Standard_Real Ratio); - - //! Changes this transformation into an affinity of ratio Ratio - //! with respect to the plane defined by the origin, the "X Direction" and - //! the "Y Direction" of coordinate system A2. - //! Note: an affinity is a point-by-point transformation that - //! transforms any point P into a point P' such that if H is - //! the orthogonal projection of P on the axis A1 or the - //! plane A2, the vectors HP and HP' satisfy: - //! HP' = Ratio * HP. - void SetAffinity (const gp_Ax2& A2, const Standard_Real Ratio); - + gp_GTrsf (const gp_Mat& theM, const gp_XYZ& theV) + : matrix (theM), + loc (theV) + { + shape = gp_Other; + scale = 0.0; + } + + //! Changes this transformation into an affinity of ratio theRatio + //! with respect to the axis theA1. + //! Note: an affinity is a point-by-point transformation that + //! transforms any point P into a point P' such that if H is + //! the orthogonal projection of P on the axis theA1 or the + //! plane A2, the vectors HP and HP' satisfy: + //! HP' = theRatio * HP. + void SetAffinity (const gp_Ax1& theA1, const Standard_Real theRatio); + + //! Changes this transformation into an affinity of ratio theRatio + //! with respect to the plane defined by the origin, the "X Direction" and + //! the "Y Direction" of coordinate system theA2. + //! Note: an affinity is a point-by-point transformation that + //! transforms any point P into a point P' such that if H is + //! the orthogonal projection of P on the axis A1 or the + //! plane theA2, the vectors HP and HP' satisfy: + //! HP' = theRatio * HP. + void SetAffinity (const gp_Ax2& theA2, const Standard_Real theRatio); + + //! Replaces the coefficient (theRow, theCol) of the matrix representing + //! this transformation by theValue. Raises OutOfRange + //! if theRow < 1 or theRow > 3 or theCol < 1 or theCol > 4 + void SetValue (const Standard_Integer theRow, const Standard_Integer theCol, const Standard_Real theValue); + + //! Replaces the vectorial part of this transformation by theMatrix. + void SetVectorialPart (const gp_Mat& theMatrix) + { + matrix = theMatrix; + shape = gp_Other; + scale = 0.0; + } - //! Replaces the coefficient (Row, Col) of the matrix representing - //! this transformation by Value. Raises OutOfRange - //! if Row < 1 or Row > 3 or Col < 1 or Col > 4 - void SetValue (const Standard_Integer Row, const Standard_Integer Col, const Standard_Real Value); - - //! Replaces the vectorial part of this transformation by Matrix. - void SetVectorialPart (const gp_Mat& Matrix); - //! Replaces the translation part of - //! this transformation by the coordinates of the number triple Coord. - Standard_EXPORT void SetTranslationPart (const gp_XYZ& Coord); - - //! Assigns the vectorial and translation parts of T to this transformation. - void SetTrsf (const gp_Trsf& T); - + //! this transformation by the coordinates of the number triple theCoord. + Standard_EXPORT void SetTranslationPart (const gp_XYZ& theCoord); + + //! Assigns the vectorial and translation parts of theT to this transformation. + void SetTrsf (const gp_Trsf& theT) + { + shape = theT.shape; + matrix = theT.matrix; + loc = theT.loc; + scale = theT.scale; + } //! Returns true if the determinant of the vectorial part of //! this transformation is negative. - Standard_Boolean IsNegative() const; - + Standard_Boolean IsNegative() const { return matrix.Determinant() < 0.0; } //! Returns true if this transformation is singular (and //! therefore, cannot be inverted). @@ -135,16 +151,14 @@ public: //! than or equal to gp::Resolution(). //! Warning //! If this transformation is singular, it cannot be inverted. - Standard_Boolean IsSingular() const; - + Standard_Boolean IsSingular() const { return matrix.IsSingular(); } //! Returns the nature of the transformation. It can be an //! identity transformation, a rotation, a translation, a mirror //! transformation (relative to a point, an axis or a plane), a //! scaling transformation, a compound transformation or //! some other type of transformation. - gp_TrsfForm Form() const; - + gp_TrsfForm Form() const { return shape; } //! verify and set the shape of the GTrsf Other or CompoundTrsf //! Ex : @@ -155,35 +169,34 @@ public: //! myGTrsf.SetForm(); //! @endcode Standard_EXPORT void SetForm(); - + //! Returns the translation part of the GTrsf. - const gp_XYZ& TranslationPart() const; - + const gp_XYZ& TranslationPart() const { return loc; } //! Computes the vectorial part of the GTrsf. The returned Matrix //! is a 3*3 matrix. - const gp_Mat& VectorialPart() const; - + const gp_Mat& VectorialPart() const { return matrix; } //! Returns the coefficients of the global matrix of transformation. - //! Raises OutOfRange if Row < 1 or Row > 3 or Col < 1 or Col > 4 - Standard_Real Value (const Standard_Integer Row, const Standard_Integer Col) const; - Standard_Real operator() (const Standard_Integer Row, const Standard_Integer Col) const -{ - return Value(Row,Col); -} - + //! Raises OutOfRange if theRow < 1 or theRow > 3 or theCol < 1 or theCol > 4 + Standard_Real Value (const Standard_Integer theRow, const Standard_Integer theCol) const; + + Standard_Real operator() (const Standard_Integer theRow, const Standard_Integer theCol) const { return Value (theRow, theCol); } + Standard_EXPORT void Invert(); - //! Computes the reverse transformation. //! Raises an exception if the matrix of the transformation //! is not inversible. - Standard_NODISCARD gp_GTrsf Inverted() const; - + Standard_NODISCARD gp_GTrsf Inverted() const + { + gp_GTrsf aT = *this; + aT.Invert(); + return aT; + } - //! Computes the transformation composed from T and . - //! In a C++ implementation you can also write Tcomposed = * T. + //! Computes the transformation composed from theT and . + //! In a C++ implementation you can also write Tcomposed = * theT. //! Example : //! @code //! gp_GTrsf T1, T2, Tcomp; ............... @@ -197,51 +210,54 @@ public: //! T1.Transforms(P2); //using T1 then T2 //! T2.Transforms(P2); // P1 = P2 !!! //! @endcode - Standard_NODISCARD gp_GTrsf Multiplied (const gp_GTrsf& T) const; - Standard_NODISCARD gp_GTrsf operator * (const gp_GTrsf& T) const - { - return Multiplied(T); + Standard_NODISCARD gp_GTrsf Multiplied (const gp_GTrsf& theT) const + { + gp_GTrsf aTres = *this; + aTres.Multiply (theT); + return aTres; } - - //! Computes the transformation composed with and T. - //! = * T - Standard_EXPORT void Multiply (const gp_GTrsf& T); - void operator *= (const gp_GTrsf& T) - { - Multiply(T); - } - + Standard_NODISCARD gp_GTrsf operator * (const gp_GTrsf& theT) const { return Multiplied (theT); } - //! Computes the product of the transformation T and this + //! Computes the transformation composed with and theT. + //! = * theT + Standard_EXPORT void Multiply (const gp_GTrsf& theT); + + void operator *= (const gp_GTrsf& theT) { Multiply (theT); } + + //! Computes the product of the transformation theT and this //! transformation and assigns the result to this transformation. - //! this = T * this - Standard_EXPORT void PreMultiply (const gp_GTrsf& T); - - Standard_EXPORT void Power (const Standard_Integer N); - + //! this = theT * this + Standard_EXPORT void PreMultiply (const gp_GTrsf& theT); + + Standard_EXPORT void Power (const Standard_Integer theN); //! Computes: //! - the product of this transformation multiplied by itself - //! N times, if N is positive, or + //! theN times, if theN is positive, or //! - the product of the inverse of this transformation - //! multiplied by itself |N| times, if N is negative. - //! If N equals zero, the result is equal to the Identity + //! multiplied by itself |theN| times, if theN is negative. + //! If theN equals zero, the result is equal to the Identity //! transformation. - //! I.e.: * * .......* , N time. - //! if N =0 = Identity - //! if N < 0 = .Inverse() *...........* .Inverse(). + //! I.e.: * * .......* , theN time. + //! if theN =0 = Identity + //! if theN < 0 = .Inverse() *...........* .Inverse(). //! //! Raises an exception if N < 0 and if the matrix of the //! transformation not inversible. - Standard_NODISCARD gp_GTrsf Powered (const Standard_Integer N) const; - - void Transforms (gp_XYZ& Coord) const; - + Standard_NODISCARD gp_GTrsf Powered (const Standard_Integer theN) const + { + gp_GTrsf aT = *this; + aT.Power (theN); + return aT; + } + + void Transforms (gp_XYZ& theCoord) const; + //! Transforms a triplet XYZ with a GTrsf. - void Transforms (Standard_Real& X, Standard_Real& Y, Standard_Real& Z) const; - - gp_Trsf Trsf() const; + void Transforms (Standard_Real& theX, Standard_Real& theY, Standard_Real& theZ) const; + + gp_Trsf Trsf() const; //! Convert transformation to 4x4 matrix. template @@ -284,10 +300,141 @@ private: }; -#include +//======================================================================= +//function : SetAffinity +// purpose : +//======================================================================= +inline void gp_GTrsf::SetAffinity (const gp_Ax1& theA1, const Standard_Real theRatio) +{ + shape = gp_Other; + scale = 0.0; + matrix.SetDot (theA1.Direction().XYZ()); + matrix.Multiply (1.0 - theRatio); + matrix.SetDiagonal (matrix.Value (1,1) + theRatio, + matrix.Value (2,2) + theRatio, + matrix.Value (3,3) + theRatio); + loc = theA1.Location().XYZ(); + loc.Reverse (); + loc.Multiply (matrix); + loc.Add (theA1.Location().XYZ()); +} +//======================================================================= +//function : SetAffinity +// purpose : +//======================================================================= +inline void gp_GTrsf::SetAffinity (const gp_Ax2& theA2, const Standard_Real theRatio) +{ + shape = gp_Other; + scale = 0.0; + matrix.SetDot (theA2.Direction().XYZ()); + matrix.Multiply (theRatio - 1.); + loc = theA2.Location().XYZ(); + loc.Reverse (); + loc.Multiply (matrix); + matrix.SetDiagonal (matrix.Value (1,1) + 1., + matrix.Value (2,2) + 1., + matrix.Value (3,3) + 1.); +} +//======================================================================= +//function : SetValue +// purpose : +//======================================================================= +inline void gp_GTrsf::SetValue (const Standard_Integer theRow, + const Standard_Integer theCol, + const Standard_Real theValue) +{ + Standard_OutOfRange_Raise_if + (theRow < 1 || theRow > 3 || theCol < 1 || theCol > 4, " "); + if (theCol == 4) + { + loc.SetCoord (theRow, theValue); + if (shape == gp_Identity) + { + shape = gp_Translation; + } + return; + } + else + { + if (!(shape == gp_Other) && !(scale == 1.0)) + { + matrix.Multiply (scale); + } + matrix.SetValue (theRow, theCol, theValue); + shape = gp_Other; + scale = 0.0; + return; + } +} +//======================================================================= +//function : Value +// purpose : +//======================================================================= +inline Standard_Real gp_GTrsf::Value (const Standard_Integer theRow, + const Standard_Integer theCol) const +{ + Standard_OutOfRange_Raise_if + (theRow < 1 || theRow > 3 || theCol < 1 || theCol > 4, " "); + if (theCol == 4) + { + return loc.Coord (theRow); + } + if (shape == gp_Other) + { + return matrix.Value (theRow, theCol); + } + return scale * matrix.Value (theRow, theCol); +} +//======================================================================= +//function : Transforms +// purpose : +//======================================================================= +inline void gp_GTrsf::Transforms (gp_XYZ& theCoord) const +{ + theCoord.Multiply (matrix); + if (!(shape == gp_Other) && !(scale == 1.0)) + { + theCoord.Multiply (scale); + } + theCoord.Add (loc); +} + +//======================================================================= +//function : Transforms +// purpose : +//======================================================================= +inline void gp_GTrsf::Transforms (Standard_Real& theX, Standard_Real& theY, Standard_Real& theZ) const +{ + gp_XYZ aTriplet (theX, theY, theZ); + aTriplet.Multiply (matrix); + if (!(shape == gp_Other) && !(scale == 1.0)) + { + aTriplet.Multiply (scale); + } + aTriplet.Add (loc); + aTriplet.Coord (theX, theY, theZ); +} + +//======================================================================= +//function : Trsf +// purpose : +//======================================================================= +inline gp_Trsf gp_GTrsf::Trsf() const +{ + if (Form() == gp_Other) + { + throw Standard_ConstructionError("gp_GTrsf::Trsf() - non-orthogonal GTrsf"); + } + gp_Trsf aT; + aT.shape = shape; + aT.scale = scale; + aT.matrix = matrix; + aT.loc = loc; + return aT; +} #endif // _gp_GTrsf_HeaderFile diff --git a/src/gp/gp_GTrsf.lxx b/src/gp/gp_GTrsf.lxx deleted file mode 100644 index 0091baf8ca..0000000000 --- a/src/gp/gp_GTrsf.lxx +++ /dev/null @@ -1,189 +0,0 @@ -// Copyright (c) 1995-1999 Matra Datavision -// Copyright (c) 1999-2014 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -#include -#include -#include -#include - -inline gp_GTrsf::gp_GTrsf () -{ - shape = gp_Identity; - matrix.SetScale (1.0); - loc.SetCoord (0.0, 0.0, 0.0); - scale = 1.0; -} - -inline gp_GTrsf::gp_GTrsf (const gp_Trsf& T) -{ - shape = T.Form(); - matrix = T.matrix; - loc = T.TranslationPart(); - scale = T.ScaleFactor(); -} - -inline gp_GTrsf::gp_GTrsf (const gp_Mat& M, - const gp_XYZ& V) : matrix(M), loc(V) -{ - shape = gp_Other; - scale = 0.0; -} - -inline void gp_GTrsf::SetAffinity (const gp_Ax1& A1, - const Standard_Real Ratio) -{ - shape = gp_Other; - scale = 0.0; - matrix.SetDot (A1.Direction().XYZ()); - matrix.Multiply (1.0 - Ratio); - matrix.SetDiagonal (matrix.Value (1,1) + Ratio, - matrix.Value (2,2) + Ratio, - matrix.Value (3,3) + Ratio); - loc = A1.Location().XYZ(); - loc.Reverse (); - loc.Multiply (matrix); - loc.Add (A1.Location().XYZ()); -} - -//======================================================================= -//function : SetAffinity -//history : AGV 2-05-06: Correct the implementation -//======================================================================= -inline void gp_GTrsf::SetAffinity (const gp_Ax2& A2, - const Standard_Real Ratio) -{ - shape = gp_Other; - scale = 0.0; - matrix.SetDot (A2.Direction().XYZ()); - matrix.Multiply (Ratio - 1.); - loc = A2.Location().XYZ(); - loc.Reverse (); - loc.Multiply (matrix); - matrix.SetDiagonal (matrix.Value (1,1) +1., - matrix.Value (2,2) +1., - matrix.Value (3,3) +1.); -} - -inline void gp_GTrsf::SetValue (const Standard_Integer Row, - const Standard_Integer Col, - const Standard_Real Value) -{ - Standard_OutOfRange_Raise_if - (Row < 1 || Row > 3 || Col < 1 || Col > 4, " "); - if (Col == 4) { - loc.SetCoord (Row, Value); - if (shape == gp_Identity) shape = gp_Translation; - return; - } - else { - if (!(shape == gp_Other) && !(scale == 1.0)) matrix.Multiply (scale); - matrix.SetValue (Row, Col, Value); - shape = gp_Other; - scale = 0.0; - return; - } -} - -inline void gp_GTrsf::SetVectorialPart (const gp_Mat& Matrix) -{ - matrix = Matrix; - shape = gp_Other; - scale = 0.0; -} - -inline void gp_GTrsf::SetTrsf (const gp_Trsf& T) -{ - shape = T.shape; - matrix = T.matrix; - loc = T.loc; - scale = T.scale; -} - -inline Standard_Boolean gp_GTrsf::IsNegative () const -{ return matrix.Determinant() < 0.0; } - -inline Standard_Boolean gp_GTrsf::IsSingular () const -{ return matrix.IsSingular(); } - -inline gp_TrsfForm gp_GTrsf::Form () const -{ return shape; } - -inline const gp_XYZ& gp_GTrsf::TranslationPart () const -{ return loc; } - -inline const gp_Mat& gp_GTrsf::VectorialPart () const -{ return matrix; } - -inline Standard_Real gp_GTrsf::Value (const Standard_Integer Row, - const Standard_Integer Col) const -{ - Standard_OutOfRange_Raise_if - (Row < 1 || Row > 3 || Col < 1 || Col > 4, " "); - if (Col == 4) return loc.Coord (Row); - if (shape == gp_Other) return matrix.Value (Row, Col); - return scale * matrix.Value (Row, Col); -} - -inline gp_GTrsf gp_GTrsf::Inverted () const -{ - gp_GTrsf T = *this; - T.Invert (); - return T; -} - -inline gp_GTrsf gp_GTrsf::Multiplied (const gp_GTrsf& T) const -{ - gp_GTrsf Tres = *this; - Tres.Multiply (T); - return Tres; -} - -inline gp_GTrsf gp_GTrsf::Powered (const Standard_Integer N) const -{ - gp_GTrsf T = *this; - T.Power (N); - return T; -} - -inline void gp_GTrsf::Transforms (gp_XYZ& Coord) const -{ - Coord.Multiply (matrix); - if (!(shape == gp_Other) && !(scale == 1.0)) Coord.Multiply (scale); - Coord.Add(loc); -} - -inline void gp_GTrsf::Transforms (Standard_Real& X, - Standard_Real& Y, - Standard_Real& Z) const -{ - gp_XYZ Triplet (X, Y, Z); - Triplet.Multiply (matrix); - if (!(shape == gp_Other) && !(scale == 1.0)) Triplet.Multiply (scale); - Triplet.Add(loc); - Triplet.Coord (X, Y, Z); -} - -inline gp_Trsf gp_GTrsf::Trsf () const -{ - if ( Form() == gp_Other ) - throw Standard_ConstructionError("gp_GTrsf::Trsf() - non-orthogonal GTrsf"); - - gp_Trsf T; - T.shape = shape; - T.scale = scale; - T.matrix = matrix; - T.loc = loc; - return T; -} - diff --git a/src/gp/gp_GTrsf2d.cxx b/src/gp/gp_GTrsf2d.cxx index 87f3b025ae..90270fc8b9 100644 --- a/src/gp/gp_GTrsf2d.cxx +++ b/src/gp/gp_GTrsf2d.cxx @@ -12,9 +12,9 @@ // Alternatively, this file may be used under the terms of Open CASCADE // commercial license or contractual agreement. +#include #include -#include #include #include #include diff --git a/src/gp/gp_GTrsf2d.hxx b/src/gp/gp_GTrsf2d.hxx index 2497f6fbd7..1e64f7ad1d 100644 --- a/src/gp/gp_GTrsf2d.hxx +++ b/src/gp/gp_GTrsf2d.hxx @@ -15,24 +15,15 @@ #ifndef _gp_GTrsf2d_HeaderFile #define _gp_GTrsf2d_HeaderFile -#include -#include -#include - +#include #include -#include #include -#include -#include -#include -class Standard_ConstructionError; -class Standard_OutOfRange; +#include +#include +#include + class gp_Trsf2d; class gp_Mat2d; -class gp_XY; -class gp_Ax2d; - - //! Defines a non persistent transformation in 2D space. //! This transformation is a general transformation. @@ -64,51 +55,62 @@ public: DEFINE_STANDARD_ALLOC - //! returns identity transformation. - gp_GTrsf2d(); - - //! Converts the gp_Trsf2d transformation T into a - //! general transformation. - gp_GTrsf2d(const gp_Trsf2d& T); - - //! Creates a transformation based on the matrix M and the - //! vector V where M defines the vectorial part of the - //! transformation, and V the translation part. - gp_GTrsf2d(const gp_Mat2d& M, const gp_XY& V); - + gp_GTrsf2d() + { + shape = gp_Identity; + matrix.SetScale (1.0); + loc.SetCoord (0.0, 0.0); + scale = 1.0; + } - //! Changes this transformation into an affinity of ratio Ratio - //! with respect to the axis A. + //! Converts the gp_Trsf2d transformation theT into a + //! general transformation. + gp_GTrsf2d (const gp_Trsf2d& theT); + + //! Creates a transformation based on the matrix theM and the + //! vector theV where theM defines the vectorial part of the + //! transformation, and theV the translation part. + gp_GTrsf2d (const gp_Mat2d& theM, const gp_XY& theV) + : matrix (theM), + loc (theV) + { + shape = gp_Other; + scale = 0.0; + } + + //! Changes this transformation into an affinity of ratio theRatio + //! with respect to the axis theA. //! Note: An affinity is a point-by-point transformation that //! transforms any point P into a point P' such that if H is - //! the orthogonal projection of P on the axis A, the vectors - //! HP and HP' satisfy: HP' = Ratio * HP. - Standard_EXPORT void SetAffinity (const gp_Ax2d& A, const Standard_Real Ratio); - + //! the orthogonal projection of P on the axis theA, the vectors + //! HP and HP' satisfy: HP' = theRatio * HP. + Standard_EXPORT void SetAffinity (const gp_Ax2d& theA, const Standard_Real theRatio); + + //! Replaces the coefficient (theRow, theCol) of the matrix representing + //! this transformation by theValue, + //! Raises OutOfRange if theRow < 1 or theRow > 2 or theCol < 1 or theCol > 3 + void SetValue (const Standard_Integer theRow, const Standard_Integer theCol, const Standard_Real theValue); - //! Replaces the coefficient (Row, Col) of the matrix representing - //! this transformation by Value, - //! Raises OutOfRange if Row < 1 or Row > 2 or Col < 1 or Col > 3 - void SetValue (const Standard_Integer Row, const Standard_Integer Col, const Standard_Real Value); - //! Replaces the translation part of this - //! transformation by the coordinates of the number pair Coord. - Standard_EXPORT void SetTranslationPart (const gp_XY& Coord); - + //! transformation by the coordinates of the number pair theCoord. + Standard_EXPORT void SetTranslationPart (const gp_XY& theCoord); - //! Assigns the vectorial and translation parts of T to this transformation. - void SetTrsf2d (const gp_Trsf2d& T); - + //! Assigns the vectorial and translation parts of theT to this transformation. + void SetTrsf2d (const gp_Trsf2d& theT); - //! Replaces the vectorial part of this transformation by Matrix. - void SetVectorialPart (const gp_Mat2d& Matrix); - + //! Replaces the vectorial part of this transformation by theMatrix. + void SetVectorialPart (const gp_Mat2d& theMatrix) + { + matrix = theMatrix; + shape = gp_Other; + scale = 0.0; + } //! Returns true if the determinant of the vectorial part of //! this transformation is negative. - Standard_Boolean IsNegative() const; - + Standard_Boolean IsNegative() const { return matrix.Determinant() < 0.0; } + //! Returns true if this transformation is singular (and //! therefore, cannot be inverted). //! Note: The Gauss LU decomposition is used to invert the @@ -117,44 +119,42 @@ public: //! than or equal to gp::Resolution(). //! Warning //! If this transformation is singular, it cannot be inverted. - Standard_Boolean IsSingular() const; - + Standard_Boolean IsSingular() const { return matrix.IsSingular(); } //! Returns the nature of the transformation. It can be //! an identity transformation, a rotation, a translation, a mirror //! transformation (relative to a point or axis), a scaling //! transformation, a compound transformation or some //! other type of transformation. - gp_TrsfForm Form() const; - + gp_TrsfForm Form() const { return shape; } + //! Returns the translation part of the GTrsf2d. - const gp_XY& TranslationPart() const; - + const gp_XY& TranslationPart() const { return loc; } //! Computes the vectorial part of the GTrsf2d. The returned //! Matrix is a 2*2 matrix. - const gp_Mat2d& VectorialPart() const; - + const gp_Mat2d& VectorialPart() const { return matrix; } //! Returns the coefficients of the global matrix of transformation. - //! Raised OutOfRange if Row < 1 or Row > 2 or Col < 1 or Col > 3 - Standard_Real Value (const Standard_Integer Row, const Standard_Integer Col) const; - Standard_Real operator() (const Standard_Integer Row, const Standard_Integer Col) const -{ - return Value(Row,Col); -} - + //! Raised OutOfRange if theRow < 1 or theRow > 2 or theCol < 1 or theCol > 3 + Standard_Real Value (const Standard_Integer theRow, const Standard_Integer theCol) const; + + Standard_Real operator() (const Standard_Integer theRow, const Standard_Integer theCol) const { return Value (theRow, theCol); } + Standard_EXPORT void Invert(); - //! Computes the reverse transformation. //! Raised an exception if the matrix of the transformation //! is not inversible. - Standard_NODISCARD gp_GTrsf2d Inverted() const; - + Standard_NODISCARD gp_GTrsf2d Inverted() const + { + gp_GTrsf2d aT = *this; + aT.Invert(); + return aT; + } - //! Computes the transformation composed with T and . - //! In a C++ implementation you can also write Tcomposed = * T. + //! Computes the transformation composed with theT and . + //! In a C++ implementation you can also write Tcomposed = * theT. //! Example : //! @code //! gp_GTrsf2d T1, T2, Tcomp; ............... @@ -168,50 +168,57 @@ public: //! T1.Transforms(P2); //using T1 then T2 //! T2.Transforms(P2); // P1 = P2 !!! //! @endcode - Standard_NODISCARD gp_GTrsf2d Multiplied (const gp_GTrsf2d& T) const; - Standard_NODISCARD gp_GTrsf2d operator * (const gp_GTrsf2d& T) const -{ - return Multiplied(T); -} - - Standard_EXPORT void Multiply (const gp_GTrsf2d& T); -void operator *= (const gp_GTrsf2d& T) -{ - Multiply(T); -} - + Standard_NODISCARD gp_GTrsf2d Multiplied (const gp_GTrsf2d& theT) const + { + gp_GTrsf2d aTres = *this; + aTres.Multiply (theT); + return aTres; + } - //! Computes the product of the transformation T and this + Standard_NODISCARD gp_GTrsf2d operator * (const gp_GTrsf2d& theT) const { return Multiplied (theT); } + + Standard_EXPORT void Multiply (const gp_GTrsf2d& theT); + + void operator *= (const gp_GTrsf2d& theT) { Multiply (theT); } + + //! Computes the product of the transformation theT and this //! transformation, and assigns the result to this transformation: - //! this = T * this - Standard_EXPORT void PreMultiply (const gp_GTrsf2d& T); - - Standard_EXPORT void Power (const Standard_Integer N); - + //! this = theT * this + Standard_EXPORT void PreMultiply (const gp_GTrsf2d& theT); + + Standard_EXPORT void Power (const Standard_Integer theN); //! Computes the following composition of transformations - //! * * .......* , N time. - //! if N = 0 = Identity - //! if N < 0 = .Inverse() *...........* .Inverse(). + //! * * .......* , theN time. + //! if theN = 0 = Identity + //! if theN < 0 = .Inverse() *...........* .Inverse(). //! - //! Raises an exception if N < 0 and if the matrix of the + //! Raises an exception if theN < 0 and if the matrix of the //! transformation is not inversible. - Standard_NODISCARD gp_GTrsf2d Powered (const Standard_Integer N) const; - - void Transforms (gp_XY& Coord) const; - - Standard_NODISCARD gp_XY Transformed (const gp_XY& Coord) const; - + Standard_NODISCARD gp_GTrsf2d Powered (const Standard_Integer theN) const + { + gp_GTrsf2d aT = *this; + aT.Power (theN); + return aT; + } + + void Transforms (gp_XY& theCoord) const; + + Standard_NODISCARD gp_XY Transformed (const gp_XY& theCoord) const + { + gp_XY aNewCoord = theCoord; + Transforms (aNewCoord); + return aNewCoord; + } //! Applies this transformation to the coordinates: //! - of the number pair Coord, or //! - X and Y. //! //! Note: - //! - Transforms modifies X, Y, or the coordinate pair Coord, while + //! - Transforms modifies theX, theY, or the coordinate pair Coord, while //! - Transformed creates a new coordinate pair. - void Transforms (Standard_Real& X, Standard_Real& Y) const; - + void Transforms (Standard_Real& theX, Standard_Real& theY) const; //! Converts this transformation into a gp_Trsf2d transformation. //! Exceptions @@ -219,32 +226,111 @@ void operator *= (const gp_GTrsf2d& T) //! cannot be converted, i.e. if its form is gp_Other. Standard_EXPORT gp_Trsf2d Trsf2d() const; - - - -protected: - - - - - private: - - gp_Mat2d matrix; gp_XY loc; gp_TrsfForm shape; Standard_Real scale; - }; +#include -#include +//======================================================================= +//function : SetTrsf2d +// purpose : +//======================================================================= +inline void gp_GTrsf2d::SetTrsf2d (const gp_Trsf2d& theT) +{ + shape = theT.shape; + matrix = theT.matrix; + loc = theT.loc; + scale = theT.scale; +} +//======================================================================= +//function : gp_GTrsf2d +// purpose : +//======================================================================= +inline gp_GTrsf2d::gp_GTrsf2d (const gp_Trsf2d& theT) +{ + shape = theT.shape; + matrix = theT.matrix; + loc = theT.loc; + scale = theT.scale; +} +//======================================================================= +//function : SetValue +// purpose : +//======================================================================= +inline void gp_GTrsf2d::SetValue (const Standard_Integer theRow, + const Standard_Integer theCol, + const Standard_Real theValue) +{ + Standard_OutOfRange_Raise_if + (theRow < 1 || theRow > 2 || theCol < 1 || theCol > 3, " "); + if (theCol == 3) + { + loc.SetCoord (theRow, theValue); + } + else + { + matrix.SetValue (theRow, theCol, theValue); + } + shape = gp_Other; +} +//======================================================================= +//function : Value +// purpose : +//======================================================================= +inline Standard_Real gp_GTrsf2d::Value (const Standard_Integer theRow, + const Standard_Integer theCol) const +{ + Standard_OutOfRange_Raise_if + (theRow < 1 || theRow > 2 || theCol < 1 || theCol > 3, " "); + if (theCol == 3) + { + return loc.Coord (theRow); + } + if (shape == gp_Other) + { + return matrix.Value (theRow, theCol); + } + return scale * matrix.Value (theRow, theCol); +} +//======================================================================= +//function : Transforms +// purpose : +//======================================================================= +inline void gp_GTrsf2d::Transforms (gp_XY& theCoord) const +{ + theCoord.Multiply (matrix); + if (!(shape == gp_Other) && !(scale == 1.0)) + { + theCoord.Multiply (scale); + } + theCoord.Add (loc); +} + +//======================================================================= +//function : Transforms +// purpose : +//======================================================================= +inline void gp_GTrsf2d::Transforms (Standard_Real& theX, + Standard_Real& theY) const +{ + gp_XY aDoublet(theX, theY); + aDoublet.Multiply (matrix); + if (!(shape == gp_Other) && !(scale == 1.0)) + { + aDoublet.Multiply (scale); + } + aDoublet.Add (loc); + aDoublet.Coord (theX, theY); +} #endif // _gp_GTrsf2d_HeaderFile diff --git a/src/gp/gp_GTrsf2d.lxx b/src/gp/gp_GTrsf2d.lxx deleted file mode 100644 index e57344ba68..0000000000 --- a/src/gp/gp_GTrsf2d.lxx +++ /dev/null @@ -1,131 +0,0 @@ -// Copyright (c) 1995-1999 Matra Datavision -// Copyright (c) 1999-2014 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -#include -#include - -inline gp_GTrsf2d::gp_GTrsf2d () -{ - shape = gp_Identity; - matrix.SetScale (1.0); - loc.SetCoord (0.0, 0.0); - scale = 1.0; -} - -inline gp_GTrsf2d::gp_GTrsf2d (const gp_Trsf2d& T) -{ - shape = T.shape; - matrix = T.matrix; - loc = T.loc; - scale = T.scale; -} - -inline gp_GTrsf2d::gp_GTrsf2d (const gp_Mat2d& M, - const gp_XY& V) : - matrix(M), - loc(V) -{ shape = gp_Other; scale = 0.0; } - -inline void gp_GTrsf2d::SetValue (const Standard_Integer Row, - const Standard_Integer Col, - const Standard_Real Value) -{ - Standard_OutOfRange_Raise_if - (Row < 1 || Row > 2 || Col < 1 || Col > 3, " "); - if (Col == 3) loc.SetCoord (Row, Value); - else matrix.SetValue (Row, Col, Value); - shape = gp_Other; -} - -inline void gp_GTrsf2d::SetTrsf2d (const gp_Trsf2d& T) -{ - shape = T.shape; - matrix = T.matrix; - loc = T.loc; - scale = T.scale; -} - -inline void gp_GTrsf2d::SetVectorialPart (const gp_Mat2d& Matrix) -{ matrix = Matrix; shape = gp_Other; scale = 0.0; } - -inline Standard_Boolean gp_GTrsf2d::IsNegative () const -{ return matrix.Determinant() < 0.0; } - -inline Standard_Boolean gp_GTrsf2d::IsSingular () const -{ return matrix.IsSingular(); } - -inline const gp_Mat2d& gp_GTrsf2d::VectorialPart () const -{ return matrix; } - -inline Standard_Real gp_GTrsf2d::Value (const Standard_Integer Row, - const Standard_Integer Col) const -{ - Standard_OutOfRange_Raise_if - (Row < 1 || Row > 2 || Col < 1 || Col > 3, " "); - if (Col == 3) return loc.Coord (Row); - if (shape == gp_Other) return matrix.Value (Row, Col); - return scale * matrix.Value (Row, Col); -} - -inline gp_TrsfForm gp_GTrsf2d::Form () const -{ return shape; } - -inline const gp_XY& gp_GTrsf2d::TranslationPart () const -{ return loc; } - -inline gp_GTrsf2d gp_GTrsf2d::Inverted () const -{ - gp_GTrsf2d T = *this; - T.Invert (); - return T; -} - -inline gp_GTrsf2d gp_GTrsf2d::Multiplied (const gp_GTrsf2d& T) const -{ - gp_GTrsf2d Tres = *this; - Tres.Multiply (T); - return Tres; -} - -inline gp_GTrsf2d gp_GTrsf2d::Powered (const Standard_Integer N) const -{ - gp_GTrsf2d T = *this; - T.Power (N); - return T; -} - -inline void gp_GTrsf2d::Transforms (gp_XY& Coord) const -{ - Coord.Multiply (matrix); - if (!(shape == gp_Other) && !(scale == 1.0)) Coord.Multiply (scale); - Coord.Add(loc); -} - -inline gp_XY gp_GTrsf2d::Transformed(const gp_XY& Coord) const -{ - gp_XY newCoord = Coord; - Transforms(newCoord); - return newCoord; -} - -inline void gp_GTrsf2d::Transforms (Standard_Real& X, - Standard_Real& Y) const -{ - gp_XY Doublet (X, Y); - Doublet.Multiply (matrix); - if (!(shape == gp_Other) && !(scale == 1.0)) Doublet.Multiply (scale); - Doublet.Add(loc); - Doublet.Coord (X, Y); -} - diff --git a/src/gp/gp_Hypr.cxx b/src/gp/gp_Hypr.cxx index c5f6839fec..a1040f91a8 100644 --- a/src/gp/gp_Hypr.cxx +++ b/src/gp/gp_Hypr.cxx @@ -14,9 +14,10 @@ // Modif jcv 14/12/90 suite a la premiere revue de projet +#include + #include #include -#include #include #include #include diff --git a/src/gp/gp_Hypr.hxx b/src/gp/gp_Hypr.hxx index df74b3158a..2f99af1437 100644 --- a/src/gp/gp_Hypr.hxx +++ b/src/gp/gp_Hypr.hxx @@ -15,22 +15,12 @@ #ifndef _gp_Hypr_HeaderFile #define _gp_Hypr_HeaderFile -#include -#include -#include - -#include -#include +#include #include +#include #include -class Standard_ConstructionError; -class Standard_DomainError; -class gp_Ax2; -class gp_Ax1; -class gp_Pnt; -class gp_Trsf; -class gp_Vec; - +#include +#include //! Describes a branch of a hyperbola in 3D space. //! A hyperbola is defined by its major and minor radii and @@ -84,87 +74,107 @@ public: DEFINE_STANDARD_ALLOC - //! Creates of an indefinite hyperbola. - gp_Hypr(); - - //! Creates a hyperbola with radii MajorRadius and - //! MinorRadius, positioned in the space by the - //! coordinate system A2 such that: - //! - the origin of A2 is the center of the hyperbola, - //! - the "X Direction" of A2 defines the major axis of + gp_Hypr() + : majorRadius (RealLast()), + minorRadius (RealFirst()) + {} + + //! Creates a hyperbola with radius theMajorRadius and + //! theMinorRadius, positioned in the space by the + //! coordinate system theA2 such that: + //! - the origin of theA2 is the center of the hyperbola, + //! - the "X Direction" of theA2 defines the major axis of //! the hyperbola, that is, the major radius - //! MajorRadius is measured along this axis, and - //! - the "Y Direction" of A2 defines the minor axis of + //! theMajorRadius is measured along this axis, and + //! - the "Y Direction" of theA2 defines the minor axis of //! the hyperbola, that is, the minor radius - //! MinorRadius is measured along this axis. + //! theMinorRadius is measured along this axis. //! Note: This class does not prevent the creation of a //! hyperbola where: - //! - MajorAxis is equal to MinorAxis, or - //! - MajorAxis is less than MinorAxis. + //! - theMajorAxis is equal to theMinorAxis, or + //! - theMajorAxis is less than theMinorAxis. //! Exceptions - //! Standard_ConstructionError if MajorAxis or MinorAxis is negative. - //! Raises ConstructionError if MajorRadius < 0.0 or MinorRadius < 0.0 - //! Raised if MajorRadius < 0.0 or MinorRadius < 0.0 - gp_Hypr(const gp_Ax2& A2, const Standard_Real MajorRadius, const Standard_Real MinorRadius); - + //! Standard_ConstructionError if theMajorAxis or theMinorAxis is negative. + //! Raises ConstructionError if theMajorRadius < 0.0 or theMinorRadius < 0.0 + //! Raised if theMajorRadius < 0.0 or theMinorRadius < 0.0 + gp_Hypr (const gp_Ax2& theA2, const Standard_Real theMajorRadius, const Standard_Real theMinorRadius) + : pos (theA2), + majorRadius (theMajorRadius), + minorRadius (theMinorRadius) + { + Standard_ConstructionError_Raise_if (theMinorRadius < 0.0 || theMajorRadius < 0.0, + "gp_Hypr() - invalid construction parameters"); + } + //! Modifies this hyperbola, by redefining its local coordinate //! system so that: //! - its origin and "main Direction" become those of the - //! axis A1 (the "X Direction" and "Y Direction" are then + //! axis theA1 (the "X Direction" and "Y Direction" are then //! recomputed in the same way as for any gp_Ax2). - //! Raises ConstructionError if the direction of A1 is parallel to the direction of + //! Raises ConstructionError if the direction of theA1 is parallel to the direction of //! the "XAxis" of the hyperbola. - void SetAxis (const gp_Ax1& A1); - + void SetAxis (const gp_Ax1& theA1) { pos.SetAxis (theA1); } + //! Modifies this hyperbola, by redefining its local coordinate - //! system so that its origin becomes P. - void SetLocation (const gp_Pnt& P); - + //! system so that its origin becomes theP. + void SetLocation (const gp_Pnt& theP) { pos = gp_Ax2 (theP, pos.Direction(), pos.XDirection()); } //! Modifies the major radius of this hyperbola. //! Exceptions - //! Standard_ConstructionError if MajorRadius is negative. - void SetMajorRadius (const Standard_Real MajorRadius); - + //! Standard_ConstructionError if theMajorRadius is negative. + void SetMajorRadius (const Standard_Real theMajorRadius) + { + Standard_ConstructionError_Raise_if (theMajorRadius < 0.0, + "gp_Hypr::SetMajorRadius() - major radius should be greater or equal zero"); + majorRadius = theMajorRadius; + } //! Modifies the minor radius of this hyperbola. //! Exceptions - //! Standard_ConstructionError if MinorRadius is negative. - void SetMinorRadius (const Standard_Real MinorRadius); - + //! Standard_ConstructionError if theMinorRadius is negative. + void SetMinorRadius (const Standard_Real theMinorRadius) + { + Standard_ConstructionError_Raise_if (theMinorRadius < 0.0, + "gp_Hypr::SetMinorRadius() - minor radius should be greater or equal zero"); + minorRadius = theMinorRadius; + } + //! Modifies this hyperbola, by redefining its local coordinate //! system so that it becomes A2. - void SetPosition (const gp_Ax2& A2); - + void SetPosition (const gp_Ax2& theA2) { pos = theA2; } //! In the local coordinate system of the hyperbola the equation of //! the hyperbola is (X*X)/(A*A) - (Y*Y)/(B*B) = 1.0 and the //! equation of the first asymptote is Y = (B/A)*X //! where A is the major radius and B is the minor radius. Raises ConstructionError if MajorRadius = 0.0 - gp_Ax1 Asymptote1() const; - + gp_Ax1 Asymptote1() const; //! In the local coordinate system of the hyperbola the equation of //! the hyperbola is (X*X)/(A*A) - (Y*Y)/(B*B) = 1.0 and the //! equation of the first asymptote is Y = -(B/A)*X. //! where A is the major radius and B is the minor radius. Raises ConstructionError if MajorRadius = 0.0 - gp_Ax1 Asymptote2() const; - + gp_Ax1 Asymptote2() const; + //! Returns the axis passing through the center, //! and normal to the plane of this hyperbola. - const gp_Ax1& Axis() const; - + const gp_Ax1& Axis() const { return pos.Axis(); } //! Computes the branch of hyperbola which is on the positive side of the //! "YAxis" of . - gp_Hypr ConjugateBranch1() const; - + gp_Hypr ConjugateBranch1() const + { + return gp_Hypr (gp_Ax2 (pos.Location(), pos.Direction(), pos.YDirection()), minorRadius, majorRadius); + } //! Computes the branch of hyperbola which is on the negative side of the //! "YAxis" of . - gp_Hypr ConjugateBranch2() const; - + gp_Hypr ConjugateBranch2() const + { + gp_Dir aD = pos.YDirection(); + aD.Reverse(); + return gp_Hypr (gp_Ax2(pos.Location(), pos.Direction(), aD), minorRadius, majorRadius); + } //! This directrix is the line normal to the XAxis of the hyperbola //! in the local plane (Z = 0) at a distance d = MajorRadius / e @@ -174,159 +184,321 @@ public: //! between the directrix1 and the "XAxis" is the "Location" point //! of the directrix1. This point is on the positive side of the //! "XAxis". - gp_Ax1 Directrix1() const; - + gp_Ax1 Directrix1() const; //! This line is obtained by the symmetrical transformation //! of "Directrix1" with respect to the "YAxis" of the hyperbola. - gp_Ax1 Directrix2() const; - + gp_Ax1 Directrix2() const; //! Returns the eccentricity of the hyperbola (e > 1). //! If f is the distance between the location of the hyperbola //! and the Focus1 then the eccentricity e = f / MajorRadius. Raises DomainError if MajorRadius = 0.0 - Standard_Real Eccentricity() const; - + Standard_Real Eccentricity() const + { + Standard_DomainError_Raise_if (majorRadius <= gp::Resolution(), + "gp_Hypr::Eccentricity() - major radius is zero"); + return sqrt (majorRadius * majorRadius + minorRadius * minorRadius) / majorRadius; + } //! Computes the focal distance. It is the distance between the //! the two focus of the hyperbola. - Standard_Real Focal() const; - + Standard_Real Focal() const + { + return 2.0 * sqrt (majorRadius * majorRadius + minorRadius * minorRadius); + } //! Returns the first focus of the hyperbola. This focus is on the //! positive side of the "XAxis" of the hyperbola. - gp_Pnt Focus1() const; - + gp_Pnt Focus1() const; //! Returns the second focus of the hyperbola. This focus is on the //! negative side of the "XAxis" of the hyperbola. - gp_Pnt Focus2() const; - + gp_Pnt Focus2() const; //! Returns the location point of the hyperbola. It is the //! intersection point between the "XAxis" and the "YAxis". - const gp_Pnt& Location() const; - + const gp_Pnt& Location() const { return pos.Location(); } //! Returns the major radius of the hyperbola. It is the radius //! on the "XAxis" of the hyperbola. - Standard_Real MajorRadius() const; - + Standard_Real MajorRadius() const { return majorRadius; } //! Returns the minor radius of the hyperbola. It is the radius //! on the "YAxis" of the hyperbola. - Standard_Real MinorRadius() const; - + Standard_Real MinorRadius() const { return minorRadius; } //! Returns the branch of hyperbola obtained by doing the //! symmetrical transformation of with respect to the //! "YAxis" of . - gp_Hypr OtherBranch() const; - + gp_Hypr OtherBranch() const + { + gp_Dir aD = pos.XDirection(); + aD.Reverse(); + return gp_Hypr (gp_Ax2 (pos.Location(), pos.Direction(), aD), majorRadius, minorRadius); + } //! Returns p = (e * e - 1) * MajorRadius where e is the //! eccentricity of the hyperbola. //! Raises DomainError if MajorRadius = 0.0 - Standard_Real Parameter() const; - + Standard_Real Parameter() const + { + Standard_DomainError_Raise_if (majorRadius <= gp::Resolution(), + "gp_Hypr::Parameter() - major radius is zero"); + return (minorRadius * minorRadius) / majorRadius; + } + //! Returns the coordinate system of the hyperbola. - const gp_Ax2& Position() const; - + const gp_Ax2& Position() const { return pos; } + //! Computes an axis, whose //! - the origin is the center of this hyperbola, and //! - the unit vector is the "X Direction" //! of the local coordinate system of this hyperbola. //! These axes are, the major axis (the "X //! Axis") and of this hyperboReturns the "XAxis" of the hyperbola. - gp_Ax1 XAxis() const; - + gp_Ax1 XAxis() const { return gp_Ax1 (pos.Location(), pos.XDirection()); } + //! Computes an axis, whose //! - the origin is the center of this hyperbola, and //! - the unit vector is the "Y Direction" //! of the local coordinate system of this hyperbola. //! These axes are the minor axis (the "Y Axis") of this hyperbola - gp_Ax1 YAxis() const; - - Standard_EXPORT void Mirror (const gp_Pnt& P); - + gp_Ax1 YAxis() const { return gp_Ax1 (pos.Location(), pos.YDirection()); } + + Standard_EXPORT void Mirror (const gp_Pnt& theP); //! Performs the symmetrical transformation of an hyperbola with - //! respect to the point P which is the center of the symmetry. - Standard_NODISCARD Standard_EXPORT gp_Hypr Mirrored (const gp_Pnt& P) const; - - Standard_EXPORT void Mirror (const gp_Ax1& A1); - + //! respect to the point theP which is the center of the symmetry. + Standard_NODISCARD Standard_EXPORT gp_Hypr Mirrored (const gp_Pnt& theP) const; + + Standard_EXPORT void Mirror (const gp_Ax1& theA1); //! Performs the symmetrical transformation of an hyperbola with //! respect to an axis placement which is the axis of the symmetry. - Standard_NODISCARD Standard_EXPORT gp_Hypr Mirrored (const gp_Ax1& A1) const; - - Standard_EXPORT void Mirror (const gp_Ax2& A2); - + Standard_NODISCARD Standard_EXPORT gp_Hypr Mirrored (const gp_Ax1& theA1) const; + + Standard_EXPORT void Mirror (const gp_Ax2& theA2); //! Performs the symmetrical transformation of an hyperbola with - //! respect to a plane. The axis placement A2 locates the plane + //! respect to a plane. The axis placement theA2 locates the plane //! of the symmetry (Location, XDirection, YDirection). - Standard_NODISCARD Standard_EXPORT gp_Hypr Mirrored (const gp_Ax2& A2) const; - - void Rotate (const gp_Ax1& A1, const Standard_Real Ang); - + Standard_NODISCARD Standard_EXPORT gp_Hypr Mirrored (const gp_Ax2& theA2) const; - //! Rotates an hyperbola. A1 is the axis of the rotation. - //! Ang is the angular value of the rotation in radians. - Standard_NODISCARD gp_Hypr Rotated (const gp_Ax1& A1, const Standard_Real Ang) const; - - void Scale (const gp_Pnt& P, const Standard_Real S); - + void Rotate (const gp_Ax1& theA1, const Standard_Real theAng) { pos.Rotate (theA1, theAng); } - //! Scales an hyperbola. S is the scaling value. - Standard_NODISCARD gp_Hypr Scaled (const gp_Pnt& P, const Standard_Real S) const; - - void Transform (const gp_Trsf& T); - + //! Rotates an hyperbola. theA1 is the axis of the rotation. + //! theAng is the angular value of the rotation in radians. + Standard_NODISCARD gp_Hypr Rotated (const gp_Ax1& theA1, const Standard_Real theAng) const + { + gp_Hypr aH = *this; + aH.pos.Rotate (theA1, theAng); + return aH; + } - //! Transforms an hyperbola with the transformation T from + void Scale (const gp_Pnt& theP, const Standard_Real theS); + + //! Scales an hyperbola. theS is the scaling value. + Standard_NODISCARD gp_Hypr Scaled (const gp_Pnt& theP, const Standard_Real theS) const; + + void Transform (const gp_Trsf& theT); + + //! Transforms an hyperbola with the transformation theT from //! class Trsf. - Standard_NODISCARD gp_Hypr Transformed (const gp_Trsf& T) const; - - void Translate (const gp_Vec& V); - + Standard_NODISCARD gp_Hypr Transformed (const gp_Trsf& theT) const; - //! Translates an hyperbola in the direction of the vector V. + void Translate (const gp_Vec& theV) { pos.Translate (theV); } + + //! Translates an hyperbola in the direction of the vector theV. //! The magnitude of the translation is the vector's magnitude. - Standard_NODISCARD gp_Hypr Translated (const gp_Vec& V) const; - - void Translate (const gp_Pnt& P1, const gp_Pnt& P2); - - - //! Translates an hyperbola from the point P1 to the point P2. - Standard_NODISCARD gp_Hypr Translated (const gp_Pnt& P1, const gp_Pnt& P2) const; - - - - -protected: - - + Standard_NODISCARD gp_Hypr Translated (const gp_Vec& theV) const + { + gp_Hypr aH = *this; + aH.pos.Translate (theV); + return aH; + } + void Translate (const gp_Pnt& theP1, const gp_Pnt& theP2) { pos.Translate (theP1, theP2); } + //! Translates an hyperbola from the point theP1 to the point theP2. + Standard_NODISCARD gp_Hypr Translated (const gp_Pnt& theP1, const gp_Pnt& theP2) const + { + gp_Hypr aH = *this; + aH.pos.Translate (theP1, theP2); + return aH; + } private: - - gp_Ax2 pos; Standard_Real majorRadius; Standard_Real minorRadius; - }; +//======================================================================= +//function : Asymptote1 +// purpose : +//======================================================================= +inline gp_Ax1 gp_Hypr::Asymptote1() const +{ + Standard_ConstructionError_Raise_if (majorRadius <= gp::Resolution(), + "gp_Hypr::Asymptote1() - major radius is zero"); + gp_Vec aV1 = gp_Vec (pos.YDirection()); + aV1.Multiply (minorRadius / majorRadius); + gp_Vec aV = gp_Vec (pos.XDirection()); + aV.Add (aV1); + return gp_Ax1 (pos.Location(), gp_Dir (aV)); +} -#include +//======================================================================= +//function : Asymptote2 +// purpose : +//======================================================================= +inline gp_Ax1 gp_Hypr::Asymptote2() const +{ + Standard_ConstructionError_Raise_if (majorRadius <= gp::Resolution(), + "gp_Hypr::Asymptote1() - major radius is zero"); + gp_Vec aV1 = gp_Vec (pos.YDirection()); + aV1.Multiply (-minorRadius / majorRadius); + gp_Vec aV = gp_Vec (pos.XDirection()); + aV.Add (aV1); + return gp_Ax1 ( pos.Location(), gp_Dir (aV)); +} +//======================================================================= +//function : Focus1 +// purpose : +//======================================================================= +inline gp_Pnt gp_Hypr::Focus1() const +{ + Standard_Real aC = sqrt (majorRadius * majorRadius + minorRadius * minorRadius); + const gp_Pnt& aPP = pos.Location (); + const gp_Dir& aDD = pos.XDirection(); + return gp_Pnt (aPP.X() + aC * aDD.X(), + aPP.Y() + aC * aDD.Y(), + aPP.Z() + aC * aDD.Z()); +} +//======================================================================= +//function : Focus2 +// purpose : +//======================================================================= +inline gp_Pnt gp_Hypr::Focus2 () const +{ + Standard_Real aC = sqrt (majorRadius * majorRadius + minorRadius * minorRadius); + const gp_Pnt& aPP = pos.Location (); + const gp_Dir& aDD = pos.XDirection(); + return gp_Pnt (aPP.X() - aC * aDD.X(), + aPP.Y() - aC * aDD.Y(), + aPP.Z() - aC * aDD.Z()); +} +//======================================================================= +//function : Scale +// purpose : +//======================================================================= +inline void gp_Hypr::Scale (const gp_Pnt& theP, + const Standard_Real theS) +{ + majorRadius *= theS; + if (majorRadius < 0) + { + majorRadius = -majorRadius; + } + minorRadius *= theS; + if (minorRadius < 0) + { + minorRadius = -minorRadius; + } + pos.Scale (theP, theS); +} +//======================================================================= +//function : Scaled +// purpose : +//======================================================================= +inline gp_Hypr gp_Hypr::Scaled (const gp_Pnt& theP, + const Standard_Real theS) const +{ + gp_Hypr aH = *this; + aH.majorRadius *= theS; + if (aH.majorRadius < 0) + { + aH.majorRadius = -aH.majorRadius; + } + aH.minorRadius *= theS; + if (aH.minorRadius < 0) + { + aH.minorRadius = -aH.minorRadius; + } + aH.pos.Scale (theP, theS); + return aH; +} + +//======================================================================= +//function : Transform +// purpose : +//======================================================================= +inline void gp_Hypr::Transform (const gp_Trsf& theT) +{ + majorRadius *= theT.ScaleFactor(); + if (majorRadius < 0) + { + majorRadius = -majorRadius; + } + minorRadius *= theT.ScaleFactor(); + if (minorRadius < 0) + { + minorRadius = -minorRadius; + } + pos.Transform (theT); +} + +//======================================================================= +//function : Transformed +// purpose : +//======================================================================= +inline gp_Hypr gp_Hypr::Transformed (const gp_Trsf& theT) const +{ + gp_Hypr aH = *this; + aH.majorRadius *= theT.ScaleFactor(); + if (aH.majorRadius < 0) + { + aH.majorRadius = -aH.majorRadius; + } + aH.minorRadius *= theT.ScaleFactor(); + if (aH.minorRadius < 0) + { + aH.minorRadius = -aH.minorRadius; + } + aH.pos.Transform (theT); + return aH; +} + +//======================================================================= +//function : Directrix1 +// purpose : +//======================================================================= +inline gp_Ax1 gp_Hypr::Directrix1 () const +{ + Standard_Real anE = Eccentricity(); + gp_XYZ anOrig = pos.XDirection().XYZ(); + anOrig.Multiply (majorRadius / anE); + anOrig.Add (pos.Location().XYZ()); + return gp_Ax1 (gp_Pnt (anOrig), pos.YDirection()); +} + +//======================================================================= +//function : Directrix2 +// purpose : +//======================================================================= +inline gp_Ax1 gp_Hypr::Directrix2 () const +{ + Standard_Real anE = Eccentricity(); + gp_XYZ anOrig = pos.XDirection().XYZ(); + anOrig.Multiply (-majorRadius / anE); + anOrig.Add (pos.Location().XYZ()); + return gp_Ax1 (gp_Pnt (anOrig), pos.YDirection()); +} #endif // _gp_Hypr_HeaderFile diff --git a/src/gp/gp_Hypr.lxx b/src/gp/gp_Hypr.lxx deleted file mode 100644 index 43d5bfb337..0000000000 --- a/src/gp/gp_Hypr.lxx +++ /dev/null @@ -1,261 +0,0 @@ -// Copyright (c) 1995-1999 Matra Datavision -// Copyright (c) 1999-2014 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -#include -#include -#include - -inline gp_Hypr::gp_Hypr () : -majorRadius(RealLast()), -minorRadius(RealFirst()) -{ } - -inline gp_Hypr::gp_Hypr (const gp_Ax2& A2, - const Standard_Real MajorRadius, - const Standard_Real MinorRadius): - pos(A2), - majorRadius(MajorRadius), - minorRadius(MinorRadius) -{ - Standard_ConstructionError_Raise_if (MinorRadius < 0.0 || MajorRadius < 0.0, - "gp_Hypr() - invalid construction parameters"); -} - -inline void gp_Hypr::SetAxis (const gp_Ax1& A1) -{ pos.SetAxis (A1); } - -inline void gp_Hypr::SetLocation (const gp_Pnt& P) -{ pos = gp_Ax2 (P, pos.Direction(), pos.XDirection()); } - -inline void gp_Hypr::SetMajorRadius (const Standard_Real R) -{ - Standard_ConstructionError_Raise_if (R < 0.0, - "gp_Hypr::SetMajorRadius() - major radius should be greater or equal zero"); - majorRadius = R; -} - -inline void gp_Hypr::SetMinorRadius (const Standard_Real R) -{ - Standard_ConstructionError_Raise_if (R < 0.0, - "gp_Hypr::SetMinorRadius() - minor radius should be greater or equal zero"); - minorRadius = R; -} - -inline void gp_Hypr::SetPosition (const gp_Ax2& A2) -{ pos = A2; } - -inline gp_Ax1 gp_Hypr::Asymptote1 () const -{ - Standard_ConstructionError_Raise_if (majorRadius <= gp::Resolution(), - "gp_Hypr::Asymptote1() - major radius is zero"); - gp_Vec V1 = gp_Vec (pos.YDirection()); - V1.Multiply (minorRadius / majorRadius); - gp_Vec V = gp_Vec (pos.XDirection()); - V.Add (V1); - return gp_Ax1(pos.Location(), gp_Dir(V)); -} - -inline gp_Ax1 gp_Hypr::Asymptote2 () const -{ - Standard_ConstructionError_Raise_if (majorRadius <= gp::Resolution(), - "gp_Hypr::Asymptote1() - major radius is zero"); - gp_Vec V1 = gp_Vec (pos.YDirection()); - V1.Multiply (-minorRadius / majorRadius); - gp_Vec V = gp_Vec (pos.XDirection()); - V.Add (V1); - return gp_Ax1( pos.Location(), gp_Dir(V)); -} - -inline const gp_Ax1& gp_Hypr::Axis () const -{ return pos.Axis(); } - -inline gp_Hypr gp_Hypr::ConjugateBranch1 () const -{ - return gp_Hypr (gp_Ax2(pos.Location(), pos.Direction(), pos.YDirection()), - minorRadius, - majorRadius); -} - -inline gp_Hypr gp_Hypr::ConjugateBranch2 () const -{ - gp_Dir D = pos.YDirection(); - D.Reverse (); - return gp_Hypr (gp_Ax2(pos.Location(), pos.Direction(), D), - minorRadius, - majorRadius); -} - -inline gp_Ax1 gp_Hypr::Directrix1 () const -{ - Standard_Real E = Eccentricity(); - gp_XYZ Orig = pos.XDirection().XYZ(); - Orig.Multiply (majorRadius/E); - Orig.Add (pos.Location().XYZ()); - return gp_Ax1 (gp_Pnt(Orig), pos.YDirection()); -} - -inline gp_Ax1 gp_Hypr::Directrix2 () const -{ - Standard_Real E = Eccentricity(); - gp_XYZ Orig = pos.XDirection().XYZ(); - Orig.Multiply (-majorRadius/E); - Orig.Add (pos.Location().XYZ()); - return gp_Ax1 (gp_Pnt(Orig), pos.YDirection()); -} - -inline Standard_Real gp_Hypr::Eccentricity () const -{ - Standard_DomainError_Raise_if (majorRadius <= gp::Resolution(), - "gp_Hypr::Eccentricity() - major radius is zero"); - return sqrt(majorRadius * majorRadius + - minorRadius * minorRadius) / majorRadius; -} - -inline Standard_Real gp_Hypr::Focal () const -{ - return 2.0 * sqrt(majorRadius * majorRadius + - minorRadius * minorRadius); -} - -inline gp_Pnt gp_Hypr::Focus1 () const -{ - Standard_Real C = sqrt(majorRadius * majorRadius + - minorRadius * minorRadius); - const gp_Pnt& PP = pos.Location (); - const gp_Dir& DD = pos.XDirection(); - return gp_Pnt (PP.X() + C * DD.X(), - PP.Y() + C * DD.Y(), - PP.Z() + C * DD.Z()); -} - -inline gp_Pnt gp_Hypr::Focus2 () const -{ - Standard_Real C = sqrt(majorRadius * majorRadius + - minorRadius * minorRadius); - const gp_Pnt& PP = pos.Location (); - const gp_Dir& DD = pos.XDirection(); - return gp_Pnt (PP.X() - C * DD.X(), - PP.Y() - C * DD.Y(), - PP.Z() - C * DD.Z()); -} - -inline const gp_Pnt& gp_Hypr::Location () const -{ return pos.Location(); } - -inline Standard_Real gp_Hypr::MajorRadius() const -{ return majorRadius; } - -inline Standard_Real gp_Hypr::MinorRadius() const -{ return minorRadius; } - -inline gp_Hypr gp_Hypr::OtherBranch () const -{ - gp_Dir D = pos.XDirection (); - D.Reverse (); - return gp_Hypr (gp_Ax2(pos.Location(), pos.Direction(), D), - majorRadius, minorRadius); -} - -inline Standard_Real gp_Hypr::Parameter() const -{ - Standard_DomainError_Raise_if (majorRadius <= gp::Resolution(), - "gp_Hypr::Parameter() - major radius is zero"); - return (minorRadius * minorRadius) / majorRadius; -} - -inline const gp_Ax2& gp_Hypr::Position() const -{ return pos; } - -inline gp_Ax1 gp_Hypr::XAxis () const -{return gp_Ax1 (pos.Location(), pos.XDirection());} - -inline gp_Ax1 gp_Hypr::YAxis () const -{return gp_Ax1 (pos.Location(), pos.YDirection());} - -inline void gp_Hypr::Rotate (const gp_Ax1& A1, - const Standard_Real Ang) -{ pos.Rotate(A1, Ang); } - -inline gp_Hypr gp_Hypr::Rotated (const gp_Ax1& A1, - const Standard_Real Ang) const -{ - gp_Hypr H = *this; - H.pos.Rotate(A1, Ang); - return H; -} - -inline void gp_Hypr::Scale (const gp_Pnt& P, - const Standard_Real S) -{ - majorRadius *= S; - if (majorRadius < 0) majorRadius = - majorRadius; - minorRadius *= S; - if (minorRadius < 0) minorRadius = - minorRadius; - pos.Scale(P, S); -} - -inline gp_Hypr gp_Hypr::Scaled (const gp_Pnt& P, - const Standard_Real S) const -{ - gp_Hypr H = *this; - H.majorRadius *= S; - if (H.majorRadius < 0) H.majorRadius = - H.majorRadius; - H.minorRadius *= S; - if (H.minorRadius < 0) H.minorRadius = - H.minorRadius; - H.pos.Scale(P, S); - return H; -} - -inline void gp_Hypr::Transform (const gp_Trsf& T) -{ - majorRadius *= T.ScaleFactor(); - if (majorRadius < 0) majorRadius = - majorRadius; - minorRadius *= T.ScaleFactor(); - if (minorRadius < 0) minorRadius = - minorRadius; - pos.Transform(T); -} - -inline gp_Hypr gp_Hypr::Transformed (const gp_Trsf& T) const -{ - gp_Hypr H = *this; - H.majorRadius *= T.ScaleFactor(); - if (H.majorRadius < 0) H.majorRadius = - H.majorRadius; - H.minorRadius *= T.ScaleFactor(); - if (H.minorRadius < 0) H.minorRadius = - H.minorRadius; - H.pos.Transform(T); - return H; -} - -inline void gp_Hypr::Translate (const gp_Vec& V) -{ pos.Translate(V); } - -inline gp_Hypr gp_Hypr::Translated (const gp_Vec& V) const -{ - gp_Hypr H = *this; - H.pos.Translate(V); - return H; -} - -inline void gp_Hypr::Translate (const gp_Pnt& P1, - const gp_Pnt& P2) -{pos.Translate(P1,P2);} - -inline gp_Hypr gp_Hypr::Translated (const gp_Pnt& P1, - const gp_Pnt& P2) const -{ - gp_Hypr H = *this; - H.pos.Translate(P1, P2); - return H; -} - diff --git a/src/gp/gp_Hypr2d.cxx b/src/gp/gp_Hypr2d.cxx index 400a00c57e..ad69890040 100644 --- a/src/gp/gp_Hypr2d.cxx +++ b/src/gp/gp_Hypr2d.cxx @@ -14,10 +14,10 @@ #define No_Standard_OutOfRange +#include #include #include -#include #include #include #include diff --git a/src/gp/gp_Hypr2d.hxx b/src/gp/gp_Hypr2d.hxx index b960981b52..4db8e78df0 100644 --- a/src/gp/gp_Hypr2d.hxx +++ b/src/gp/gp_Hypr2d.hxx @@ -15,24 +15,12 @@ #ifndef _gp_Hypr2d_HeaderFile #define _gp_Hypr2d_HeaderFile -#include -#include -#include - +#include #include -#include -#include #include #include -class Standard_ConstructionError; -class Standard_DomainError; -class gp_Ax2d; -class gp_Ax22d; -class gp_Pnt2d; -class gp_Trsf2d; -class gp_Vec2d; - - +#include +#include //! Describes a branch of a hyperbola in the plane (2D space). //! A hyperbola is defined by its major and minor radii, and @@ -80,71 +68,93 @@ public: DEFINE_STANDARD_ALLOC - //! Creates of an indefinite hyperbola. - gp_Hypr2d(); - + gp_Hypr2d() + : majorRadius (RealLast()), + minorRadius (RealLast()) + {} - //! Creates a hyperbola with radii MajorRadius and - //! MinorRadius, centered on the origin of MajorAxis - //! and where the unit vector of MajorAxis is the "X + //! Creates a hyperbola with radii theMajorRadius and + //! theMinorRadius, centered on the origin of theMajorAxis + //! and where the unit vector of theMajorAxis is the "X //! Direction" of the local coordinate system of the - //! hyperbola. This coordinate system is direct if Sense - //! is true (the default value), and indirect if Sense is false. + //! hyperbola. This coordinate system is direct if theIsSense + //! is true (the default value), and indirect if theIsSense is false. //! Warnings : //! It is yet possible to create an Hyperbola with - //! MajorRadius <= MinorRadius. - //! Raises ConstructionError if MajorRadius < 0.0 or MinorRadius < 0.0 - gp_Hypr2d(const gp_Ax2d& MajorAxis, const Standard_Real MajorRadius, const Standard_Real MinorRadius, const Standard_Boolean Sense = Standard_True); - + //! theMajorRadius <= theMinorRadius. + //! Raises ConstructionError if theMajorRadius < 0.0 or theMinorRadius < 0.0 + gp_Hypr2d (const gp_Ax2d& theMajorAxis, const Standard_Real theMajorRadius, + const Standard_Real theMinorRadius, const Standard_Boolean theIsSense = Standard_True) + : majorRadius (theMajorRadius), + minorRadius (theMinorRadius) + { + pos = gp_Ax22d (theMajorAxis, theIsSense); + Standard_ConstructionError_Raise_if (theMinorRadius < 0.0 || theMajorRadius < 0.0, + "gp_Hypr2d() - invalid construction parameters"); + } - //! a hyperbola with radii MajorRadius and - //! MinorRadius, positioned in the plane by coordinate system A where: - //! - the origin of A is the center of the hyperbola, - //! - the "X Direction" of A defines the major axis of + //! a hyperbola with radii theMajorRadius and + //! theMinorRadius, positioned in the plane by coordinate system theA where: + //! - the origin of theA is the center of the hyperbola, + //! - the "X Direction" of theA defines the major axis of //! the hyperbola, that is, the major radius - //! MajorRadius is measured along this axis, and - //! - the "Y Direction" of A defines the minor axis of + //! theMajorRadius is measured along this axis, and + //! - the "Y Direction" of theA defines the minor axis of //! the hyperbola, that is, the minor radius - //! MinorRadius is measured along this axis, and - //! - the orientation (direct or indirect sense) of A + //! theMinorRadius is measured along this axis, and + //! - the orientation (direct or indirect sense) of theA //! gives the implicit orientation of the hyperbola. //! Warnings : //! It is yet possible to create an Hyperbola with - //! MajorRadius <= MinorRadius. - //! Raises ConstructionError if MajorRadius < 0.0 or MinorRadius < 0.0 - gp_Hypr2d(const gp_Ax22d& A, const Standard_Real MajorRadius, const Standard_Real MinorRadius); - + //! theMajorRadius <= theMinorRadius. + //! Raises ConstructionError if theMajorRadius < 0.0 or theMinorRadius < 0.0 + gp_Hypr2d (const gp_Ax22d& theA, const Standard_Real theMajorRadius, const Standard_Real theMinorRadius) + : pos (theA), + majorRadius (theMajorRadius), + minorRadius (theMinorRadius) + { + Standard_ConstructionError_Raise_if (theMinorRadius < 0.0 || theMajorRadius < 0.0, + "gp_Hypr2d() - invalid construction parameters"); + } + //! Modifies this hyperbola, by redefining its local - //! coordinate system so that its origin becomes P. - void SetLocation (const gp_Pnt2d& P); - + //! coordinate system so that its origin becomes theP. + void SetLocation (const gp_Pnt2d& theP) { pos.SetLocation (theP); } + + //! Modifies the major or minor radius of this hyperbola. + //! Exceptions + //! Standard_ConstructionError if theMajorRadius or + //! MinorRadius is negative. + void SetMajorRadius (const Standard_Real theMajorRadius) + { + Standard_ConstructionError_Raise_if (theMajorRadius < 0.0, + "gp_Hypr2d::SetMajorRadius() - major radius should be greater or equal zero"); + majorRadius = theMajorRadius; + } + //! Modifies the major or minor radius of this hyperbola. //! Exceptions //! Standard_ConstructionError if MajorRadius or - //! MinorRadius is negative. - void SetMajorRadius (const Standard_Real MajorRadius); - - //! Modifies the major or minor radius of this hyperbola. - //! Exceptions - //! Standard_ConstructionError if MajorRadius or - //! MinorRadius is negative. - void SetMinorRadius (const Standard_Real MinorRadius); - + //! theMinorRadius is negative. + void SetMinorRadius (const Standard_Real theMinorRadius) + { + Standard_ConstructionError_Raise_if (theMinorRadius < 0.0, + "gp_Hypr2d::SetMinorRadius() - minor radius should be greater or equal zero"); + minorRadius = theMinorRadius; + } + //! Modifies this hyperbola, by redefining its local - //! coordinate system so that it becomes A. - void SetAxis (const gp_Ax22d& A); - + //! coordinate system so that it becomes theA. + void SetAxis (const gp_Ax22d& theA) { pos.SetAxis (theA); } //! Changes the major axis of the hyperbola. The minor axis is //! recomputed and the location of the hyperbola too. - void SetXAxis (const gp_Ax2d& A); - + void SetXAxis (const gp_Ax2d& theA) { pos.SetXAxis (theA); } //! Changes the minor axis of the hyperbola.The minor axis is //! recomputed and the location of the hyperbola too. - void SetYAxis (const gp_Ax2d& A); - + void SetYAxis (const gp_Ax2d& theA) { pos.SetYAxis (theA); } //! In the local coordinate system of the hyperbola the equation of //! the hyperbola is (X*X)/(A*A) - (Y*Y)/(B*B) = 1.0 and the @@ -152,8 +162,7 @@ public: //! where A is the major radius of the hyperbola and B the minor //! radius of the hyperbola. //! Raises ConstructionError if MajorRadius = 0.0 - gp_Ax2d Asymptote1() const; - + gp_Ax2d Asymptote1() const; //! In the local coordinate system of the hyperbola the equation of //! the hyperbola is (X*X)/(A*A) - (Y*Y)/(B*B) = 1.0 and the @@ -161,24 +170,31 @@ public: //! where A is the major radius of the hyperbola and B the minor //! radius of the hyperbola. //! Raises ConstructionError if MajorRadius = 0.0 - gp_Ax2d Asymptote2() const; - + gp_Ax2d Asymptote2() const; //! Computes the coefficients of the implicit equation of //! the hyperbola : - //! A * (X**2) + B * (Y**2) + 2*C*(X*Y) + 2*D*X + 2*E*Y + F = 0. - Standard_EXPORT void Coefficients (Standard_Real& A, Standard_Real& B, Standard_Real& C, Standard_Real& D, Standard_Real& E, Standard_Real& F) const; - + //! theA * (X**2) + theB * (Y**2) + 2*theC*(X*Y) + 2*theD*X + 2*theE*Y + theF = 0. + Standard_EXPORT void Coefficients (Standard_Real& theA, Standard_Real& theB, Standard_Real& theC, + Standard_Real& theD, Standard_Real& theE, Standard_Real& theF) const; //! Computes the branch of hyperbola which is on the positive side of the //! "YAxis" of . - gp_Hypr2d ConjugateBranch1() const; - + gp_Hypr2d ConjugateBranch1() const + { + gp_Dir2d aV (pos.YDirection()); + Standard_Boolean isSign = (pos.XDirection().Crossed (pos.YDirection())) >= 0.0; + return gp_Hypr2d (gp_Ax2d (pos.Location(), aV), minorRadius, majorRadius, isSign); + } //! Computes the branch of hyperbola which is on the negative side of the //! "YAxis" of . - gp_Hypr2d ConjugateBranch2() const; - + gp_Hypr2d ConjugateBranch2() const + { + gp_Dir2d aV (pos.YDirection().Reversed()); + Standard_Boolean isSign = (pos.XDirection().Crossed (pos.YDirection())) >= 0.0; + return gp_Hypr2d (gp_Ax2d (pos.Location(), aV), minorRadius, majorRadius, isSign); + } //! Computes the directrix which is the line normal to the XAxis of the hyperbola //! in the local plane (Z = 0) at a distance d = MajorRadius / e @@ -188,168 +204,331 @@ public: //! between the "Directrix1" and the "XAxis" is the "Location" point //! of the "Directrix1". //! This point is on the positive side of the "XAxis". - gp_Ax2d Directrix1() const; - + gp_Ax2d Directrix1() const; //! This line is obtained by the symmetrical transformation //! of "Directrix1" with respect to the "YAxis" of the hyperbola. - gp_Ax2d Directrix2() const; - + gp_Ax2d Directrix2() const; //! Returns the eccentricity of the hyperbola (e > 1). //! If f is the distance between the location of the hyperbola //! and the Focus1 then the eccentricity e = f / MajorRadius. Raises DomainError if MajorRadius = 0.0. - Standard_Real Eccentricity() const; - + Standard_Real Eccentricity() const + { + Standard_DomainError_Raise_if (majorRadius <= gp::Resolution(), + "gp_Hypr2d::Eccentricity() - major radius is zero"); + return sqrt (majorRadius * majorRadius + minorRadius * minorRadius) / majorRadius; + } //! Computes the focal distance. It is the distance between the //! "Location" of the hyperbola and "Focus1" or "Focus2". - Standard_Real Focal() const; - + Standard_Real Focal() const + { + return 2.0 * sqrt (majorRadius * majorRadius + minorRadius * minorRadius); + } //! Returns the first focus of the hyperbola. This focus is on the //! positive side of the "XAxis" of the hyperbola. - gp_Pnt2d Focus1() const; - + gp_Pnt2d Focus1() const + { + Standard_Real aC = sqrt (majorRadius * majorRadius + minorRadius * minorRadius); + return gp_Pnt2d (pos.Location().X() + aC * pos.XDirection().X(), pos.Location().Y() + aC * pos.XDirection().Y()); + } //! Returns the second focus of the hyperbola. This focus is on the //! negative side of the "XAxis" of the hyperbola. - gp_Pnt2d Focus2() const; - + gp_Pnt2d Focus2() const + { + Standard_Real aC = sqrt(majorRadius * majorRadius + minorRadius * minorRadius); + return gp_Pnt2d(pos.Location().X() - aC * pos.XDirection().X(), pos.Location().Y() - aC * pos.XDirection().Y()); + } //! Returns the location point of the hyperbola. //! It is the intersection point between the "XAxis" and //! the "YAxis". - const gp_Pnt2d& Location() const; - + const gp_Pnt2d& Location() const { return pos.Location(); } //! Returns the major radius of the hyperbola (it is the radius //! corresponding to the "XAxis" of the hyperbola). - Standard_Real MajorRadius() const; - + Standard_Real MajorRadius() const { return majorRadius; } //! Returns the minor radius of the hyperbola (it is the radius //! corresponding to the "YAxis" of the hyperbola). - Standard_Real MinorRadius() const; - + Standard_Real MinorRadius() const { return minorRadius; } //! Returns the branch of hyperbola obtained by doing the //! symmetrical transformation of with respect to the //! "YAxis" of . - gp_Hypr2d OtherBranch() const; - + gp_Hypr2d OtherBranch() const + { + Standard_Boolean isSign = (pos.XDirection().Crossed (pos.YDirection())) >= 0.0; + return gp_Hypr2d (gp_Ax2d (pos.Location(), pos.XDirection().Reversed()), majorRadius, minorRadius, isSign); + } //! Returns p = (e * e - 1) * MajorRadius where e is the //! eccentricity of the hyperbola. //! Raises DomainError if MajorRadius = 0.0 - Standard_Real Parameter() const; - + Standard_Real Parameter() const + { + Standard_DomainError_Raise_if (majorRadius <= gp::Resolution(), + "gp_Hypr2d::Parameter() - major radius is zero"); + return (minorRadius * minorRadius) / majorRadius; + } + //! Returns the axisplacement of the hyperbola. - const gp_Ax22d& Axis() const; - + const gp_Ax22d& Axis() const { return pos; } + //! Computes an axis whose //! - the origin is the center of this hyperbola, and //! - the unit vector is the "X Direction" or "Y Direction" //! respectively of the local coordinate system of this hyperbola //! Returns the major axis of the hyperbola. - gp_Ax2d XAxis() const; - + gp_Ax2d XAxis() const { return pos.XAxis(); } + //! Computes an axis whose //! - the origin is the center of this hyperbola, and //! - the unit vector is the "X Direction" or "Y Direction" //! respectively of the local coordinate system of this hyperbola //! Returns the minor axis of the hyperbola. - gp_Ax2d YAxis() const; - - void Reverse(); - + gp_Ax2d YAxis() const { return pos.YAxis(); } + + void Reverse() + { + gp_Dir2d aTemp = pos.YDirection(); + aTemp.Reverse(); + pos.SetAxis (gp_Ax22d(pos.Location(), pos.XDirection(), aTemp)); + } + //! Reverses the orientation of the local coordinate system //! of this hyperbola (the "Y Axis" is reversed). Therefore, //! the implicit orientation of this hyperbola is reversed. //! Note: //! - Reverse assigns the result to this hyperbola, while //! - Reversed creates a new one. - Standard_NODISCARD gp_Hypr2d Reversed() const; - + Standard_NODISCARD gp_Hypr2d Reversed() const; + //! Returns true if the local coordinate system is direct //! and false in the other case. - Standard_Boolean IsDirect() const; - - Standard_EXPORT void Mirror (const gp_Pnt2d& P); - + Standard_Boolean IsDirect() const + { + return (pos.XDirection().Crossed (pos.YDirection())) >= 0.0; + } + + Standard_EXPORT void Mirror (const gp_Pnt2d& theP); //! Performs the symmetrical transformation of an hyperbola with - //! respect to the point P which is the center of the symmetry. - Standard_NODISCARD Standard_EXPORT gp_Hypr2d Mirrored (const gp_Pnt2d& P) const; - - Standard_EXPORT void Mirror (const gp_Ax2d& A); - + //! respect to the point theP which is the center of the symmetry. + Standard_NODISCARD Standard_EXPORT gp_Hypr2d Mirrored (const gp_Pnt2d& theP) const; + + Standard_EXPORT void Mirror (const gp_Ax2d& theA); //! Performs the symmetrical transformation of an hyperbola with //! respect to an axis placement which is the axis of the symmetry. - Standard_NODISCARD Standard_EXPORT gp_Hypr2d Mirrored (const gp_Ax2d& A) const; - - void Rotate (const gp_Pnt2d& P, const Standard_Real Ang); - + Standard_NODISCARD Standard_EXPORT gp_Hypr2d Mirrored (const gp_Ax2d& theA) const; - //! Rotates an hyperbola. P is the center of the rotation. - //! Ang is the angular value of the rotation in radians. - Standard_NODISCARD gp_Hypr2d Rotated (const gp_Pnt2d& P, const Standard_Real Ang) const; - - void Scale (const gp_Pnt2d& P, const Standard_Real S); - + void Rotate (const gp_Pnt2d& theP, const Standard_Real theAng) { pos.Rotate (theP, theAng); } - //! Scales an hyperbola. is the scaling value. - //! If is positive only the location point is - //! modified. But if is negative the "XAxis" is + //! Rotates an hyperbola. theP is the center of the rotation. + //! theAng is the angular value of the rotation in radians. + Standard_NODISCARD gp_Hypr2d Rotated (const gp_Pnt2d& theP, const Standard_Real theAng) const + { + gp_Hypr2d aH = *this; + aH.pos.Rotate (theP, theAng); + return aH; + } + + void Scale (const gp_Pnt2d& theP, const Standard_Real theS); + + //! Scales an hyperbola. is the scaling value. + //! If is positive only the location point is + //! modified. But if is negative the "XAxis" is //! reversed and the "YAxis" too. - Standard_NODISCARD gp_Hypr2d Scaled (const gp_Pnt2d& P, const Standard_Real S) const; - - void Transform (const gp_Trsf2d& T); - + Standard_NODISCARD gp_Hypr2d Scaled (const gp_Pnt2d& theP, const Standard_Real theS) const; - //! Transforms an hyperbola with the transformation T from + void Transform (const gp_Trsf2d& theT); + + //! Transforms an hyperbola with the transformation theT from //! class Trsf2d. - Standard_NODISCARD gp_Hypr2d Transformed (const gp_Trsf2d& T) const; - - void Translate (const gp_Vec2d& V); - + Standard_NODISCARD gp_Hypr2d Transformed (const gp_Trsf2d& theT) const; - //! Translates an hyperbola in the direction of the vector V. + void Translate (const gp_Vec2d& theV) { pos.Translate (theV); } + + //! Translates an hyperbola in the direction of the vector theV. //! The magnitude of the translation is the vector's magnitude. - Standard_NODISCARD gp_Hypr2d Translated (const gp_Vec2d& V) const; - - void Translate (const gp_Pnt2d& P1, const gp_Pnt2d& P2); - - - //! Translates an hyperbola from the point P1 to the point P2. - Standard_NODISCARD gp_Hypr2d Translated (const gp_Pnt2d& P1, const gp_Pnt2d& P2) const; - - - - -protected: - - + Standard_NODISCARD gp_Hypr2d Translated (const gp_Vec2d& theV) const + { + gp_Hypr2d aH = *this; + aH.pos.Translate (theV); + return aH; + } + void Translate(const gp_Pnt2d& theP1, const gp_Pnt2d& theP2) { pos.Translate (theP1, theP2); } + //! Translates an hyperbola from the point theP1 to the point theP2. + Standard_NODISCARD gp_Hypr2d Translated (const gp_Pnt2d& theP1, const gp_Pnt2d& theP2) const + { + gp_Hypr2d aH = *this; + aH.pos.Translate (theP1, theP2); + return aH; + } private: - - gp_Ax22d pos; Standard_Real majorRadius; Standard_Real minorRadius; - }; +//======================================================================= +//function : Asymptote1 +// purpose : +//======================================================================= +inline gp_Ax2d gp_Hypr2d::Asymptote1() const +{ + Standard_ConstructionError_Raise_if (majorRadius <= gp::Resolution(), + "gp_Hypr2d::Asymptote1() - major radius is zero"); + gp_Dir2d aVdir = pos.XDirection(); + gp_XY aCoord1 (pos.YDirection().XY()); + gp_XY aCoord2 = aCoord1.Multiplied (minorRadius / majorRadius); + aCoord1.Add (aCoord2); + aVdir.SetXY (aCoord1); + return gp_Ax2d (pos.Location(), aVdir); +} -#include +//======================================================================= +//function : Asymptote2 +// purpose : +//======================================================================= +inline gp_Ax2d gp_Hypr2d::Asymptote2() const +{ + Standard_ConstructionError_Raise_if (majorRadius <= gp::Resolution(), + "gp_Hypr2d::Asymptote2() - major radius is zero"); + gp_Vec2d aVdir = pos.XDirection(); + gp_XY aCoord1 (pos.YDirection().XY()); + gp_XY aCoord2 = aCoord1.Multiplied (-minorRadius / majorRadius); + aCoord1.Add (aCoord2); + aVdir.SetXY (aCoord1); + return gp_Ax2d (pos.Location(), aVdir); +} +//======================================================================= +//function : Directrix1 +// purpose : +//======================================================================= +inline gp_Ax2d gp_Hypr2d::Directrix1() const +{ + Standard_Real anE = Eccentricity(); + gp_XY anOrig = pos.XDirection().XY(); + anOrig.Multiply (majorRadius / anE); + anOrig.Add (pos.Location().XY()); + return gp_Ax2d (gp_Pnt2d (anOrig), gp_Dir2d (pos.YDirection())); +} +//======================================================================= +//function : Directrix2 +// purpose : +//======================================================================= +inline gp_Ax2d gp_Hypr2d::Directrix2() const +{ + Standard_Real anE = Eccentricity(); + gp_XY anOrig = pos.XDirection().XY(); + anOrig.Multiply (Parameter() / anE); + anOrig.Add (Focus1().XY()); + return gp_Ax2d (gp_Pnt2d (anOrig), gp_Dir2d (pos.YDirection())); +} +//======================================================================= +//function : Reversed +// purpose : +//======================================================================= +inline gp_Hypr2d gp_Hypr2d::Reversed() const +{ + gp_Hypr2d aH = *this; + gp_Dir2d aTemp = pos.YDirection(); + aTemp.Reverse (); + aH.pos.SetAxis (gp_Ax22d (pos.Location(),pos.XDirection(), aTemp)); + return aH; +} +//======================================================================= +//function : Scale +// purpose : +//======================================================================= +inline void gp_Hypr2d::Scale (const gp_Pnt2d& theP, const Standard_Real theS) +{ + majorRadius *= theS; + if (majorRadius < 0) + { + majorRadius = -majorRadius; + } + minorRadius *= theS; + if (minorRadius < 0) + { + minorRadius = -minorRadius; + } + pos.Scale (theP, theS); +} + +//======================================================================= +//function : Scaled +// purpose : +//======================================================================= +inline gp_Hypr2d gp_Hypr2d::Scaled (const gp_Pnt2d& theP, const Standard_Real theS) const +{ + gp_Hypr2d aH = *this; + aH.majorRadius *= theS; + if (aH.majorRadius < 0) + { + aH.majorRadius = -aH.majorRadius; + } + aH.minorRadius *= theS; + if (aH.minorRadius < 0) + { + aH.minorRadius = -aH.minorRadius; + } + aH.pos.Scale (theP, theS); + return aH; +} + +//======================================================================= +//function : Transform +// purpose : +//======================================================================= +inline void gp_Hypr2d::Transform (const gp_Trsf2d& theT) +{ + majorRadius *= theT.ScaleFactor(); + if (majorRadius < 0) + { + majorRadius = -majorRadius; + } + minorRadius *= theT.ScaleFactor(); + if (minorRadius < 0) + { + minorRadius = -minorRadius; + } + pos.Transform (theT); +} + +//======================================================================= +//function : Transformed +// purpose : +//======================================================================= +inline gp_Hypr2d gp_Hypr2d::Transformed (const gp_Trsf2d& theT) const +{ + gp_Hypr2d aH = *this; + aH.majorRadius *= theT.ScaleFactor(); + if (aH.majorRadius < 0) + { + aH.majorRadius = -aH.majorRadius; + } + aH.minorRadius *= theT.ScaleFactor(); + if (aH.minorRadius < 0) + { + aH.minorRadius = -aH.minorRadius; + } + aH.pos.Transform (theT); + return aH; +} #endif // _gp_Hypr2d_HeaderFile diff --git a/src/gp/gp_Hypr2d.lxx b/src/gp/gp_Hypr2d.lxx deleted file mode 100644 index cdc297d6d3..0000000000 --- a/src/gp/gp_Hypr2d.lxx +++ /dev/null @@ -1,288 +0,0 @@ -// Copyright (c) 1995-1999 Matra Datavision -// Copyright (c) 1999-2014 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -// LPA et JCV 07/92 mise a jour des methodes inline pour passage sur C1 - -#include -#include -#include - -inline gp_Hypr2d::gp_Hypr2d () : -majorRadius(RealLast()), -minorRadius(RealLast()) -{ } - -inline gp_Hypr2d::gp_Hypr2d (const gp_Ax22d& A, - const Standard_Real MajorRadius, - const Standard_Real MinorRadius) : - pos(A), - majorRadius(MajorRadius), - minorRadius(MinorRadius) -{ - Standard_ConstructionError_Raise_if (MinorRadius < 0.0 || MajorRadius < 0.0, - "gp_Hypr2d() - invalid construction parameters"); -} - -inline gp_Hypr2d::gp_Hypr2d (const gp_Ax2d& MajorAxis, - const Standard_Real MajorRadius, - const Standard_Real MinorRadius, - const Standard_Boolean Sense) : - majorRadius(MajorRadius), - minorRadius(MinorRadius) -{ - pos = gp_Ax22d(MajorAxis,Sense); - Standard_ConstructionError_Raise_if (MinorRadius < 0.0 || MajorRadius < 0.0, - "gp_Hypr2d() - invalid construction parameters"); -} - -inline void gp_Hypr2d::SetLocation (const gp_Pnt2d& P) -{ pos.SetLocation (P); } - -inline void gp_Hypr2d::SetMajorRadius (const Standard_Real MajorRadius) -{ - Standard_ConstructionError_Raise_if (MajorRadius < 0.0, - "gp_Hypr2d::SetMajorRadius() - major radius should be greater or equal zero"); - majorRadius = MajorRadius; -} - -inline void gp_Hypr2d::SetMinorRadius (const Standard_Real MinorRadius) -{ - Standard_ConstructionError_Raise_if (MinorRadius < 0.0, - "gp_Hypr2d::SetMinorRadius() - minor radius should be greater or equal zero"); - minorRadius = MinorRadius; -} - -inline void gp_Hypr2d::SetAxis (const gp_Ax22d& A) -{ pos.SetAxis(A); } - -inline void gp_Hypr2d::SetXAxis (const gp_Ax2d& A) -{ pos.SetXAxis(A); } - -inline void gp_Hypr2d::SetYAxis (const gp_Ax2d& A) -{ pos.SetYAxis(A); } - -inline gp_Ax2d gp_Hypr2d::Asymptote1() const -{ - Standard_ConstructionError_Raise_if (majorRadius <= gp::Resolution(), - "gp_Hypr2d::Asymptote1() - major radius is zero"); - gp_Dir2d Vdir = pos.XDirection(); - gp_XY Coord1 (pos.YDirection().XY()); - gp_XY Coord2 = Coord1.Multiplied (minorRadius / majorRadius); - Coord1.Add (Coord2); - Vdir.SetXY (Coord1); - return gp_Ax2d (pos.Location(), Vdir); -} - -inline gp_Ax2d gp_Hypr2d::Asymptote2() const { - Standard_ConstructionError_Raise_if (majorRadius <= gp::Resolution(), - "gp_Hypr2d::Asymptote2() - major radius is zero"); - gp_Vec2d Vdir = pos.XDirection(); - gp_XY Coord1 (pos.YDirection().XY()); - gp_XY Coord2 = Coord1.Multiplied (-minorRadius / majorRadius); - Coord1.Add (Coord2); - Vdir.SetXY (Coord1); - return gp_Ax2d (pos.Location(), Vdir); -} - -inline gp_Hypr2d gp_Hypr2d::ConjugateBranch1() const -{ - gp_Dir2d V (pos.YDirection()); - Standard_Boolean sign = (pos.XDirection().Crossed(pos.YDirection())) >= 0.0; - return gp_Hypr2d (gp_Ax2d (pos.Location(),V), minorRadius, majorRadius,sign); -} - -inline gp_Hypr2d gp_Hypr2d::ConjugateBranch2() const -{ - gp_Dir2d V (pos.YDirection().Reversed()); - Standard_Boolean sign = (pos.XDirection().Crossed(pos.YDirection())) >= 0.0; - return gp_Hypr2d (gp_Ax2d(pos.Location(),V),minorRadius, majorRadius,sign); -} - -inline gp_Ax2d gp_Hypr2d::Directrix1() const -{ - Standard_Real E = Eccentricity(); - gp_XY Orig = pos.XDirection().XY(); - Orig.Multiply (majorRadius/E); - Orig.Add (pos.Location().XY()); - return gp_Ax2d (gp_Pnt2d(Orig),gp_Dir2d (pos.YDirection())); -} - -inline gp_Ax2d gp_Hypr2d::Directrix2() const -{ - Standard_Real E = Eccentricity(); - gp_XY Orig = pos.XDirection().XY(); - Orig.Multiply (Parameter()/E); - Orig.Add (Focus1().XY()); - return gp_Ax2d (gp_Pnt2d(Orig),gp_Dir2d (pos.YDirection())); -} - -inline Standard_Real gp_Hypr2d::Eccentricity() const -{ - Standard_DomainError_Raise_if (majorRadius <= gp::Resolution(), - "gp_Hypr2d::Eccentricity() - major radius is zero"); - return sqrt(majorRadius * majorRadius + - minorRadius * minorRadius) / majorRadius; -} - -inline Standard_Real gp_Hypr2d::Focal() const -{ - return 2.0 * sqrt (majorRadius * majorRadius + - minorRadius * minorRadius); -} - -inline gp_Pnt2d gp_Hypr2d::Focus1() const -{ - Standard_Real C = sqrt (majorRadius * majorRadius + - minorRadius * minorRadius); - return gp_Pnt2d (pos.Location().X() + C * pos.XDirection().X(), - pos.Location().Y() + C * pos.XDirection().Y()); -} - -inline gp_Pnt2d gp_Hypr2d::Focus2() const -{ - Standard_Real C = sqrt (majorRadius * majorRadius + - minorRadius * minorRadius); - return gp_Pnt2d (pos.Location().X() - C * pos.XDirection().X(), - pos.Location().Y() - C * pos.XDirection().Y()); -} - -inline const gp_Pnt2d& gp_Hypr2d::Location () const -{ return pos.Location(); } - -inline Standard_Real gp_Hypr2d::MajorRadius() const - { return majorRadius; } - -inline Standard_Real gp_Hypr2d::MinorRadius() const - { return minorRadius; } - -inline gp_Hypr2d gp_Hypr2d::OtherBranch() const -{ - Standard_Boolean sign = (pos.XDirection().Crossed(pos.YDirection())) >= 0.0; - return gp_Hypr2d (gp_Ax2d (pos.Location(),pos.XDirection().Reversed()), - majorRadius,minorRadius,sign); -} - -inline Standard_Real gp_Hypr2d::Parameter() const -{ - Standard_DomainError_Raise_if (majorRadius <= gp::Resolution(), - "gp_Hypr2d::Parameter() - major radius is zero"); - return (minorRadius * minorRadius) / majorRadius; -} - -inline const gp_Ax22d& gp_Hypr2d::Axis () const - { return pos; } - -inline gp_Ax2d gp_Hypr2d::XAxis () const -{ return pos.XAxis(); } - -inline gp_Ax2d gp_Hypr2d::YAxis () const -{ return pos.YAxis(); } - -inline void gp_Hypr2d::Reverse() -{ - gp_Dir2d Temp = pos.YDirection (); - Temp.Reverse (); - pos.SetAxis(gp_Ax22d(pos.Location(),pos.XDirection(),Temp)); -} - -inline gp_Hypr2d gp_Hypr2d::Reversed() const -{ - gp_Hypr2d H = *this; - gp_Dir2d Temp = pos.YDirection (); - Temp.Reverse (); - H.pos.SetAxis(gp_Ax22d(pos.Location(),pos.XDirection(),Temp)); - return H; -} - -inline Standard_Boolean gp_Hypr2d::IsDirect() const -{ return (pos.XDirection().Crossed(pos.YDirection())) >= 0.0; } - -inline void gp_Hypr2d::Rotate (const gp_Pnt2d& P, - const Standard_Real Ang) -{pos.Rotate (P,Ang);} - -inline gp_Hypr2d gp_Hypr2d::Rotated (const gp_Pnt2d& P, - const Standard_Real Ang) const -{ - gp_Hypr2d H = *this; - H.pos.Rotate (P, Ang); - return H; -} - -inline void gp_Hypr2d::Scale (const gp_Pnt2d& P, - const Standard_Real S) -{ - majorRadius *= S; - if (majorRadius < 0) majorRadius = - majorRadius; - minorRadius *= S; - if (minorRadius < 0) minorRadius = - minorRadius; - pos.Scale(P, S); -} - -inline gp_Hypr2d gp_Hypr2d::Scaled (const gp_Pnt2d& P, - const Standard_Real S) const -{ - gp_Hypr2d H = *this; - H.majorRadius *= S; - if (H.majorRadius < 0) H.majorRadius = - H.majorRadius; - H.minorRadius *= S; - if (H.minorRadius < 0) H.minorRadius = - H.minorRadius; - H.pos.Scale(P, S); - return H; -} - -inline void gp_Hypr2d::Transform (const gp_Trsf2d& T) -{ - majorRadius *= T.ScaleFactor(); - if (majorRadius < 0) majorRadius = - majorRadius; - minorRadius *= T.ScaleFactor(); - if (minorRadius < 0) minorRadius = - minorRadius; - pos.Transform(T); -} - -inline gp_Hypr2d gp_Hypr2d::Transformed (const gp_Trsf2d& T) const -{ -gp_Hypr2d H = *this; -H.majorRadius *= T.ScaleFactor(); -if (H.majorRadius < 0) H.majorRadius = - H.majorRadius; -H.minorRadius *= T.ScaleFactor(); -if (H.minorRadius < 0) H.minorRadius = - H.minorRadius; -H.pos.Transform(T); -return H; -} - -inline void gp_Hypr2d::Translate (const gp_Vec2d& V) -{ pos.Translate(V); } - -inline gp_Hypr2d gp_Hypr2d::Translated (const gp_Vec2d& V) const -{ - gp_Hypr2d H = *this; - H.pos.Translate(V); - return H; -} - -inline void gp_Hypr2d::Translate (const gp_Pnt2d& P1, - const gp_Pnt2d& P2) -{ - pos.Translate(P1, P2); -} - -inline gp_Hypr2d gp_Hypr2d::Translated (const gp_Pnt2d& P1, - const gp_Pnt2d& P2) const -{ - gp_Hypr2d H = *this; - H.pos.Translate(P1, P2); - return H; -} - diff --git a/src/gp/gp_Lin.cxx b/src/gp/gp_Lin.cxx index b91d56cd5b..775fd23c84 100644 --- a/src/gp/gp_Lin.cxx +++ b/src/gp/gp_Lin.cxx @@ -16,10 +16,11 @@ // JCV 1/10/90 Changement de nom du package vgeom -> gp // JCV 12/12/90 modifs suite a la premiere revue de projet +#include + #include #include #include -#include #include #include #include diff --git a/src/gp/gp_Lin.hxx b/src/gp/gp_Lin.hxx index 267d2e3d32..55527b47f4 100644 --- a/src/gp/gp_Lin.hxx +++ b/src/gp/gp_Lin.hxx @@ -15,22 +15,13 @@ #ifndef _gp_Lin_HeaderFile #define _gp_Lin_HeaderFile -#include -#include -#include - #include -#include -#include -class Standard_ConstructionError; -class gp_Ax1; -class gp_Pnt; -class gp_Dir; -class gp_Ax2; -class gp_Trsf; -class gp_Vec; - - +#include +#include +#include +#include +#include +#include //! Describes a line in 3D space. //! A line is positioned in space with an axis (a gp_Ax1 @@ -52,162 +43,216 @@ public: DEFINE_STANDARD_ALLOC - //! Creates a Line corresponding to Z axis of the //! reference coordinate system. - gp_Lin(); - - //! Creates a line defined by axis A1. - gp_Lin(const gp_Ax1& A1); - - //! Creates a line passing through point P and parallel to - //! vector V (P and V are, respectively, the origin and - //! the unit vector of the positioning axis of the line). - gp_Lin(const gp_Pnt& P, const gp_Dir& V); + gp_Lin() {} + + //! Creates a line defined by axis theA1. + gp_Lin (const gp_Ax1& theA1) + : pos (theA1) + {} + + //! Creates a line passing through point theP and parallel to + //! vector theV (theP and theV are, respectively, the origin and + //! the unit vector of the positioning axis of the line). + gp_Lin (const gp_Pnt& theP, const gp_Dir& theV) + : pos (theP, theV) + {} + + void Reverse() + { + pos.Reverse(); + } - void Reverse(); - //! Reverses the direction of the line. //! Note: //! - Reverse assigns the result to this line, while //! - Reversed creates a new one. - Standard_NODISCARD gp_Lin Reversed() const; - + Standard_NODISCARD gp_Lin Reversed() const + { + gp_Lin aL = *this; + aL.pos.Reverse(); + return aL; + } + //! Changes the direction of the line. - void SetDirection (const gp_Dir& V); - + void SetDirection (const gp_Dir& theV) { pos.SetDirection (theV); } + //! Changes the location point (origin) of the line. - void SetLocation (const gp_Pnt& P); - + void SetLocation (const gp_Pnt& theP) { pos.SetLocation (theP); } //! Complete redefinition of the line. - //! The "Location" point of is the origin of the line. - //! The "Direction" of is the direction of the line. - void SetPosition (const gp_Ax1& A1); - + //! The "Location" point of is the origin of the line. + //! The "Direction" of is the direction of the line. + void SetPosition (const gp_Ax1& theA1) { pos = theA1; } + //! Returns the direction of the line. - const gp_Dir& Direction() const; - + const gp_Dir& Direction() const { return pos.Direction(); } //! Returns the location point (origin) of the line. - const gp_Pnt& Location() const; - + const gp_Pnt& Location() const { return pos.Location(); } //! Returns the axis placement one axis with the same //! location and direction as . - const gp_Ax1& Position() const; - - //! Computes the angle between two lines in radians. - Standard_Real Angle (const gp_Lin& Other) const; - - //! Returns true if this line contains the point P, that is, if the - //! distance between point P and this line is less than or - //! equal to LinearTolerance.. - Standard_Boolean Contains (const gp_Pnt& P, const Standard_Real LinearTolerance) const; - - //! Computes the distance between and the point P. - Standard_Real Distance (const gp_Pnt& P) const; - - //! Computes the distance between two lines. - Standard_EXPORT Standard_Real Distance (const gp_Lin& Other) const; - + const gp_Ax1& Position() const { return pos; } + + //! Computes the angle between two lines in radians. + Standard_Real Angle (const gp_Lin& theOther) const + { + return pos.Direction().Angle (theOther.pos.Direction()); + } + + //! Returns true if this line contains the point theP, that is, if the + //! distance between point theP and this line is less than or + //! equal to theLinearTolerance.. + Standard_Boolean Contains (const gp_Pnt& theP, const Standard_Real theLinearTolerance) const + { + return Distance (theP) <= theLinearTolerance; + } + + //! Computes the distance between and the point theP. + Standard_Real Distance (const gp_Pnt& theP) const; + + //! Computes the distance between two lines. + Standard_EXPORT Standard_Real Distance (const gp_Lin& theOther) const; + + //! Computes the square distance between and the point theP. + Standard_Real SquareDistance (const gp_Pnt& theP) const; - //! Computes the square distance between and the point P. - Standard_Real SquareDistance (const gp_Pnt& P) const; - //! Computes the square distance between two lines. - Standard_Real SquareDistance (const gp_Lin& Other) const; - + Standard_Real SquareDistance (const gp_Lin& theOther) const + { + Standard_Real aD = Distance (theOther); + return aD * aD; + } //! Computes the line normal to the direction of , passing - //! through the point P. Raises ConstructionError - //! if the distance between and the point P is lower + //! through the point theP. Raises ConstructionError + //! if the distance between and the point theP is lower //! or equal to Resolution from gp because there is an infinity of //! solutions in 3D space. - gp_Lin Normal (const gp_Pnt& P) const; - - Standard_EXPORT void Mirror (const gp_Pnt& P); - + gp_Lin Normal (const gp_Pnt& theP) const; + + Standard_EXPORT void Mirror (const gp_Pnt& theP); //! Performs the symmetrical transformation of a line - //! with respect to the point P which is the center of + //! with respect to the point theP which is the center of //! the symmetry. - Standard_NODISCARD Standard_EXPORT gp_Lin Mirrored (const gp_Pnt& P) const; - - Standard_EXPORT void Mirror (const gp_Ax1& A1); - + Standard_NODISCARD Standard_EXPORT gp_Lin Mirrored (const gp_Pnt& theP) const; + + Standard_EXPORT void Mirror (const gp_Ax1& theA1); //! Performs the symmetrical transformation of a line //! with respect to an axis placement which is the axis //! of the symmetry. - Standard_NODISCARD Standard_EXPORT gp_Lin Mirrored (const gp_Ax1& A1) const; - - Standard_EXPORT void Mirror (const gp_Ax2& A2); - + Standard_NODISCARD Standard_EXPORT gp_Lin Mirrored (const gp_Ax1& theA1) const; + + Standard_EXPORT void Mirror (const gp_Ax2& theA2); //! Performs the symmetrical transformation of a line - //! with respect to a plane. The axis placement + //! with respect to a plane. The axis placement //! locates the plane of the symmetry : //! (Location, XDirection, YDirection). - Standard_NODISCARD Standard_EXPORT gp_Lin Mirrored (const gp_Ax2& A2) const; - - void Rotate (const gp_Ax1& A1, const Standard_Real Ang); - + Standard_NODISCARD Standard_EXPORT gp_Lin Mirrored (const gp_Ax2& theA2) const; + + void Rotate (const gp_Ax1& theA1, const Standard_Real theAng) { pos.Rotate (theA1, theAng); } //! Rotates a line. A1 is the axis of the rotation. //! Ang is the angular value of the rotation in radians. - Standard_NODISCARD gp_Lin Rotated (const gp_Ax1& A1, const Standard_Real Ang) const; - - void Scale (const gp_Pnt& P, const Standard_Real S); - + Standard_NODISCARD gp_Lin Rotated (const gp_Ax1& theA1, const Standard_Real theAng) const + { + gp_Lin aL = *this; + aL.pos.Rotate (theA1, theAng); + return aL; + } - //! Scales a line. S is the scaling value. + void Scale (const gp_Pnt& theP, const Standard_Real theS) { pos.Scale (theP, theS); } + + //! Scales a line. theS is the scaling value. //! The "Location" point (origin) of the line is modified. //! The "Direction" is reversed if the scale is negative. - Standard_NODISCARD gp_Lin Scaled (const gp_Pnt& P, const Standard_Real S) const; - - void Transform (const gp_Trsf& T); - + Standard_NODISCARD gp_Lin Scaled (const gp_Pnt& theP, const Standard_Real theS) const + { + gp_Lin aL = *this; + aL.pos.Scale (theP, theS); + return aL; + } - //! Transforms a line with the transformation T from class Trsf. - Standard_NODISCARD gp_Lin Transformed (const gp_Trsf& T) const; - - void Translate (const gp_Vec& V); - + void Transform (const gp_Trsf& theT) { pos.Transform (theT); } - //! Translates a line in the direction of the vector V. + //! Transforms a line with the transformation theT from class Trsf. + Standard_NODISCARD gp_Lin Transformed (const gp_Trsf& theT) const + { + gp_Lin aL = *this; + aL.pos.Transform (theT); + return aL; + } + + void Translate (const gp_Vec& theV) { pos.Translate (theV); } + + //! Translates a line in the direction of the vector theV. //! The magnitude of the translation is the vector's magnitude. - Standard_NODISCARD gp_Lin Translated (const gp_Vec& V) const; - - void Translate (const gp_Pnt& P1, const gp_Pnt& P2); - - - //! Translates a line from the point P1 to the point P2. - Standard_NODISCARD gp_Lin Translated (const gp_Pnt& P1, const gp_Pnt& P2) const; - - - - -protected: - - + Standard_NODISCARD gp_Lin Translated (const gp_Vec& theV) const + { + gp_Lin aL = *this; + aL.pos.Translate (theV); + return aL; + } + void Translate (const gp_Pnt& theP1, const gp_Pnt& theP2) { pos.Translate (theP1, theP2); } + //! Translates a line from the point theP1 to the point theP2. + Standard_NODISCARD gp_Lin Translated (const gp_Pnt& theP1, const gp_Pnt& theP2) const + { + gp_Lin aL = *this; + aL.pos.Translate (gp_Vec(theP1, theP2)); + return aL; + } private: - - gp_Ax1 pos; - }; +//======================================================================= +//function : Distance +// purpose : +//======================================================================= +inline Standard_Real gp_Lin::Distance (const gp_Pnt& theP) const +{ + gp_XYZ aCoord = theP.XYZ(); + aCoord.Subtract ((pos.Location()).XYZ()); + aCoord.Cross ((pos.Direction()).XYZ()); + return aCoord.Modulus(); +} -#include - - - +//======================================================================= +//function : SquareDistance +// purpose : +//======================================================================= +inline Standard_Real gp_Lin::SquareDistance(const gp_Pnt& theP) const +{ + const gp_Pnt& aLoc = pos.Location(); + gp_Vec aV (theP.X() - aLoc.X(), + theP.Y() - aLoc.Y(), + theP.Z() - aLoc.Z()); + aV.Cross (pos.Direction()); + return aV.SquareMagnitude(); +} +//======================================================================= +//function : Normal +// purpose : +//======================================================================= +inline gp_Lin gp_Lin::Normal(const gp_Pnt& theP) const +{ + const gp_Pnt& aLoc = pos.Location(); + gp_Dir aV (theP.X() - aLoc.X(), + theP.Y() - aLoc.Y(), + theP.Z() - aLoc.Z()); + aV = pos.Direction().CrossCrossed (aV, pos.Direction()); + return gp_Lin(theP, aV); +} #endif // _gp_Lin_HeaderFile diff --git a/src/gp/gp_Lin.lxx b/src/gp/gp_Lin.lxx deleted file mode 100644 index 2776b01276..0000000000 --- a/src/gp/gp_Lin.lxx +++ /dev/null @@ -1,150 +0,0 @@ -// Copyright (c) 1995-1999 Matra Datavision -// Copyright (c) 1999-2014 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -// JCV 30/08/90 Modif passage version C++ 2.0 sur Sun - -inline gp_Lin::gp_Lin () -{ } - -inline gp_Lin::gp_Lin (const gp_Ax1& A1) : pos (A1) -{ } - -inline gp_Lin::gp_Lin (const gp_Pnt& P, - const gp_Dir& V) : pos (P, V) -{ } - -inline void gp_Lin::Reverse() -{ pos.Reverse(); } - -inline gp_Lin gp_Lin::Reversed() const { - gp_Lin L = *this; - L.pos.Reverse(); - return L; -} - -inline void gp_Lin::SetDirection (const gp_Dir& V) -{ pos.SetDirection(V); } - -inline void gp_Lin::SetLocation (const gp_Pnt& P) -{ pos.SetLocation(P); } - -inline void gp_Lin::SetPosition (const gp_Ax1& A1) -{ pos = A1; } - -inline const gp_Dir& gp_Lin::Direction() const -{ return pos.Direction(); } - -inline const gp_Pnt& gp_Lin::Location() const -{ return pos.Location(); } - -inline const gp_Ax1& gp_Lin::Position() const -{ return pos; } - -inline Standard_Real gp_Lin::Angle (const gp_Lin& Other) const -{ return pos.Direction().Angle (Other.pos.Direction()); } - -inline Standard_Boolean gp_Lin::Contains -(const gp_Pnt& P, - const Standard_Real LinearTolerance) const -{ return Distance(P) <= LinearTolerance; } - -inline Standard_Real gp_Lin::Distance (const gp_Pnt& P) const { - gp_XYZ Coord = P.XYZ(); - Coord.Subtract ((pos.Location()).XYZ()); - Coord.Cross ((pos.Direction()).XYZ()); - return Coord.Modulus(); -} - -inline Standard_Real gp_Lin::SquareDistance (const gp_Pnt& P) const -{ - const gp_Pnt& Loc = pos.Location(); - gp_Vec V (P.X() - Loc.X(), - P.Y() - Loc.Y(), - P.Z() - Loc.Z()); - V.Cross (pos.Direction()); - return V.SquareMagnitude (); -} - -inline Standard_Real gp_Lin::SquareDistance (const gp_Lin& Other) const -{ - Standard_Real D = Distance (Other); - return D * D; -} - -inline gp_Lin gp_Lin::Normal (const gp_Pnt& P) const -{ - const gp_Pnt& Loc = pos.Location(); - gp_Dir V (P.X() - Loc.X(), - P.Y() - Loc.Y(), - P.Z() - Loc.Z()); - V = pos.Direction().CrossCrossed(V, pos.Direction()); - return gp_Lin (P, V); -} - -inline void gp_Lin::Rotate (const gp_Ax1& A1, - const Standard_Real Ang) -{ pos.Rotate(A1, Ang); } - -inline gp_Lin gp_Lin::Rotated (const gp_Ax1& A1, - const Standard_Real Ang) const -{ - gp_Lin L = *this; - L.pos.Rotate (A1, Ang); - return L; -} - -inline void gp_Lin::Scale (const gp_Pnt& P, - const Standard_Real S) -{ pos.Scale(P, S); } - -inline gp_Lin gp_Lin::Scaled (const gp_Pnt& P, - const Standard_Real S) const -{ - gp_Lin L = *this; - L.pos.Scale (P, S); - return L; -} - -inline void gp_Lin::Transform (const gp_Trsf& T) -{ pos.Transform(T); } - -inline gp_Lin gp_Lin::Transformed (const gp_Trsf& T) const -{ - gp_Lin L = *this; - L.pos.Transform (T); - return L; -} - -inline void gp_Lin::Translate (const gp_Vec& V) -{ pos.Translate(V); } - -inline gp_Lin gp_Lin::Translated (const gp_Vec& V) const -{ - gp_Lin L = *this; - L.pos.Translate (V); - return L; -} - -inline void gp_Lin::Translate (const gp_Pnt& P1, - const gp_Pnt& P2) -{pos.Translate (P1, P2);} - -inline gp_Lin gp_Lin::Translated (const gp_Pnt& P1, - const gp_Pnt& P2) const -{ - gp_Lin L = *this; - L.pos.Translate (gp_Vec(P1, P2)); - return L; -} - diff --git a/src/gp/gp_Lin2d.cxx b/src/gp/gp_Lin2d.cxx index 5c06b47255..9fd5cdc227 100644 --- a/src/gp/gp_Lin2d.cxx +++ b/src/gp/gp_Lin2d.cxx @@ -17,11 +17,11 @@ #define No_Standard_OutOfRange +#include #include #include #include -#include #include #include #include diff --git a/src/gp/gp_Lin2d.hxx b/src/gp/gp_Lin2d.hxx index 1e6b239d6e..7dd61716cd 100644 --- a/src/gp/gp_Lin2d.hxx +++ b/src/gp/gp_Lin2d.hxx @@ -15,20 +15,7 @@ #ifndef _gp_Lin2d_HeaderFile #define _gp_Lin2d_HeaderFile -#include -#include -#include - #include -#include -#include -class Standard_ConstructionError; -class gp_Ax2d; -class gp_Pnt2d; -class gp_Dir2d; -class gp_Trsf2d; -class gp_Vec2d; - //! Describes a line in 2D space. //! A line is positioned in the plane with an axis (a gp_Ax2d @@ -54,161 +41,229 @@ public: DEFINE_STANDARD_ALLOC - //! Creates a Line corresponding to X axis of the //! reference coordinate system. - gp_Lin2d(); - - //! Creates a line located with A. - gp_Lin2d(const gp_Ax2d& A); - + gp_Lin2d() {} - //!

is the location point (origin) of the line and - //! is the direction of the line. - gp_Lin2d(const gp_Pnt2d& P, const gp_Dir2d& V); - + //! Creates a line located with theA. + gp_Lin2d (const gp_Ax2d& theA) + : pos (theA) + {} - //! Creates the line from the equation A*X + B*Y + C = 0.0 Raises ConstructionError if Sqrt(A*A + B*B) <= Resolution from gp. - //! Raised if Sqrt(A*A + B*B) <= Resolution from gp. - Standard_EXPORT gp_Lin2d(const Standard_Real A, const Standard_Real B, const Standard_Real C); - - void Reverse(); - + //! is the location point (origin) of the line and + //! is the direction of the line. + gp_Lin2d (const gp_Pnt2d& theP, const gp_Dir2d& theV) + : pos (theP, theV) + {} + + //! Creates the line from the equation theA*X + theB*Y + theC = 0.0 Raises ConstructionError if Sqrt(theA*theA + theB*theB) <= Resolution from gp. + //! Raised if Sqrt(theA*theA + theB*theB) <= Resolution from gp. + Standard_EXPORT gp_Lin2d (const Standard_Real theA, const Standard_Real theB, const Standard_Real theC); + + void Reverse() { pos.Reverse(); } //! Reverses the positioning axis of this line. //! Note: //! - Reverse assigns the result to this line, while //! - Reversed creates a new one. - Standard_NODISCARD gp_Lin2d Reversed() const; - + Standard_NODISCARD gp_Lin2d Reversed() const + { + gp_Lin2d aL = *this; + aL.pos.Reverse(); + return aL; + } + //! Changes the direction of the line. - void SetDirection (const gp_Dir2d& V); - + void SetDirection (const gp_Dir2d& theV) { pos.SetDirection (theV); } + //! Changes the origin of the line. - void SetLocation (const gp_Pnt2d& P); - + void SetLocation (const gp_Pnt2d& theP) { pos.SetLocation (theP); } //! Complete redefinition of the line. - //! The "Location" point of is the origin of the line. - //! The "Direction" of is the direction of the line. - void SetPosition (const gp_Ax2d& A); - + //! The "Location" point of is the origin of the line. + //! The "Direction" of is the direction of the line. + void SetPosition (const gp_Ax2d& theA) { pos = theA; } //! Returns the normalized coefficients of the line : - //! A * X + B * Y + C = 0. - void Coefficients (Standard_Real& A, Standard_Real& B, Standard_Real& C) const; - + //! theA * X + theB * Y + theC = 0. + void Coefficients (Standard_Real& theA, Standard_Real& theB, Standard_Real& theC) const + { + theA = pos.Direction().Y(); + theB = -pos.Direction().X(); + theC = -(theA * pos.Location().X() + theB * pos.Location().Y()); + } + //! Returns the direction of the line. - const gp_Dir2d& Direction() const; - + const gp_Dir2d& Direction() const { return pos.Direction(); } + //! Returns the location point (origin) of the line. - const gp_Pnt2d& Location() const; - + const gp_Pnt2d& Location() const { return pos.Location(); } //! Returns the axis placement one axis with the same //! location and direction as . - const gp_Ax2d& Position() const; - - //! Computes the angle between two lines in radians. - Standard_Real Angle (const gp_Lin2d& Other) const; - - //! Returns true if this line contains the point P, that is, if the - //! distance between point P and this line is less than or - //! equal to LinearTolerance. - Standard_Boolean Contains (const gp_Pnt2d& P, const Standard_Real LinearTolerance) const; - + const gp_Ax2d& Position() const { return pos; } + + //! Computes the angle between two lines in radians. + Standard_Real Angle (const gp_Lin2d& theOther) const + { + return pos.Direction().Angle (theOther.pos.Direction()); + } + + //! Returns true if this line contains the point theP, that is, if the + //! distance between point theP and this line is less than or + //! equal to theLinearTolerance. + Standard_Boolean Contains (const gp_Pnt2d& theP, const Standard_Real theLinearTolerance) const + { + return Distance (theP) <= theLinearTolerance; + } + + //! Computes the distance between and the point . + Standard_Real Distance (const gp_Pnt2d& theP) const; - //! Computes the distance between and the point

. - Standard_Real Distance (const gp_Pnt2d& P) const; - //! Computes the distance between two lines. - Standard_Real Distance (const gp_Lin2d& Other) const; - + Standard_Real Distance (const gp_Lin2d& theOther) const; //! Computes the square distance between and the point - //!

. - Standard_Real SquareDistance (const gp_Pnt2d& P) const; - + //! . + Standard_Real SquareDistance (const gp_Pnt2d& theP) const; + //! Computes the square distance between two lines. - Standard_Real SquareDistance (const gp_Lin2d& Other) const; - + Standard_Real SquareDistance (const gp_Lin2d& theOther) const; //! Computes the line normal to the direction of , - //! passing through the point

. - gp_Lin2d Normal (const gp_Pnt2d& P) const; - - Standard_EXPORT void Mirror (const gp_Pnt2d& P); - + //! passing through the point . + gp_Lin2d Normal (const gp_Pnt2d& theP) const + { + return gp_Lin2d (gp_Ax2d (theP, gp_Dir2d (-(pos.Direction().Y()), pos.Direction().X()))); + } + + Standard_EXPORT void Mirror (const gp_Pnt2d& theP); //! Performs the symmetrical transformation of a line - //! with respect to the point

which is the center + //! with respect to the point which is the center //! of the symmetry - Standard_NODISCARD Standard_EXPORT gp_Lin2d Mirrored (const gp_Pnt2d& P) const; - - Standard_EXPORT void Mirror (const gp_Ax2d& A); - + Standard_NODISCARD Standard_EXPORT gp_Lin2d Mirrored (const gp_Pnt2d& theP) const; + + Standard_EXPORT void Mirror (const gp_Ax2d& theA); //! Performs the symmetrical transformation of a line //! with respect to an axis placement which is the axis //! of the symmetry. - Standard_NODISCARD Standard_EXPORT gp_Lin2d Mirrored (const gp_Ax2d& A) const; - - void Rotate (const gp_Pnt2d& P, const Standard_Real Ang); - + Standard_NODISCARD Standard_EXPORT gp_Lin2d Mirrored (const gp_Ax2d& theA) const; - //! Rotates a line. P is the center of the rotation. - //! Ang is the angular value of the rotation in radians. - Standard_NODISCARD gp_Lin2d Rotated (const gp_Pnt2d& P, const Standard_Real Ang) const; - - void Scale (const gp_Pnt2d& P, const Standard_Real S); - + void Rotate (const gp_Pnt2d& theP, const Standard_Real theAng) { pos.Rotate(theP, theAng); } - //! Scales a line. S is the scaling value. Only the + //! Rotates a line. theP is the center of the rotation. + //! theAng is the angular value of the rotation in radians. + Standard_NODISCARD gp_Lin2d Rotated (const gp_Pnt2d& theP, const Standard_Real theAng) const + { + gp_Lin2d aL = *this; + aL.pos.Rotate (theP, theAng); + return aL; + } + + void Scale (const gp_Pnt2d& theP, const Standard_Real theS) { pos.Scale (theP, theS); } + + //! Scales a line. theS is the scaling value. Only the //! origin of the line is modified. - Standard_NODISCARD gp_Lin2d Scaled (const gp_Pnt2d& P, const Standard_Real S) const; - - void Transform (const gp_Trsf2d& T); - + Standard_NODISCARD gp_Lin2d Scaled (const gp_Pnt2d& theP, const Standard_Real theS) const + { + gp_Lin2d aL = *this; + aL.pos.Scale (theP, theS); + return aL; + } - //! Transforms a line with the transformation T from class Trsf2d. - Standard_NODISCARD gp_Lin2d Transformed (const gp_Trsf2d& T) const; - - void Translate (const gp_Vec2d& V); - + void Transform (const gp_Trsf2d& theT) { pos.Transform (theT); } - //! Translates a line in the direction of the vector V. + //! Transforms a line with the transformation theT from class Trsf2d. + Standard_NODISCARD gp_Lin2d Transformed (const gp_Trsf2d& theT) const + { + gp_Lin2d aL = *this; + aL.pos.Transform (theT); + return aL; + } + + void Translate (const gp_Vec2d& theV) { pos.Translate (theV); } + + //! Translates a line in the direction of the vector theV. //! The magnitude of the translation is the vector's magnitude. - Standard_NODISCARD gp_Lin2d Translated (const gp_Vec2d& V) const; - - void Translate (const gp_Pnt2d& P1, const gp_Pnt2d& P2); - - - //! Translates a line from the point P1 to the point P2. - Standard_NODISCARD gp_Lin2d Translated (const gp_Pnt2d& P1, const gp_Pnt2d& P2) const; - - - - -protected: - - + Standard_NODISCARD gp_Lin2d Translated (const gp_Vec2d& theV) const + { + gp_Lin2d aL = *this; + aL.pos.Translate (theV); + return aL; + } + void Translate (const gp_Pnt2d& theP1, const gp_Pnt2d& theP2) { pos.Translate (theP1, theP2); } + //! Translates a line from the point theP1 to the point theP2. + Standard_NODISCARD gp_Lin2d Translated (const gp_Pnt2d& theP1, const gp_Pnt2d& theP2) const + { + gp_Lin2d aL = *this; + aL.pos.Translate (gp_Vec2d (theP1, theP2)); + return aL; + } private: - - gp_Ax2d pos; - }; +//======================================================================= +//function : Distance +// purpose : +//======================================================================= +inline Standard_Real gp_Lin2d::Distance (const gp_Pnt2d& theP) const +{ + gp_XY aCoord = theP.XY(); + aCoord.Subtract ((pos.Location()).XY()); + Standard_Real aVal = aCoord.Crossed (pos.Direction().XY()); + if (aVal < 0) + { + aVal = -aVal; + } + return aVal; +} -#include - - +//======================================================================= +//function : Distance +// purpose : +//======================================================================= +inline Standard_Real gp_Lin2d::Distance (const gp_Lin2d& theOther) const +{ + Standard_Real aD = 0.0; + if (pos.IsParallel (theOther.pos, gp::Resolution())) + { + aD = theOther.Distance (pos.Location()); + } + return aD; +} +//======================================================================= +//function : SquareDistance +// purpose : +//======================================================================= +inline Standard_Real gp_Lin2d::SquareDistance (const gp_Pnt2d& theP) const +{ + gp_XY aCoord = theP.XY(); + aCoord.Subtract ((pos.Location()).XY()); + Standard_Real aD = aCoord.Crossed (pos.Direction().XY()); + return aD * aD; +} +//======================================================================= +//function : SquareDistance +// purpose : +//======================================================================= +inline Standard_Real gp_Lin2d::SquareDistance (const gp_Lin2d& theOther) const +{ + Standard_Real aD = 0.0; + if (pos.IsParallel (theOther.pos, gp::Resolution())) + { + aD = theOther.SquareDistance (pos.Location()); + } + return aD; +} #endif // _gp_Lin2d_HeaderFile diff --git a/src/gp/gp_Lin2d.lxx b/src/gp/gp_Lin2d.lxx deleted file mode 100644 index df2068ec10..0000000000 --- a/src/gp/gp_Lin2d.lxx +++ /dev/null @@ -1,164 +0,0 @@ -// Copyright (c) 1995-1999 Matra Datavision -// Copyright (c) 1999-2014 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -inline gp_Lin2d::gp_Lin2d () -{ } - -inline gp_Lin2d::gp_Lin2d (const gp_Ax2d& A) : pos(A) -{ } - -inline gp_Lin2d::gp_Lin2d (const gp_Pnt2d& P, - const gp_Dir2d& V) : pos(P, V) -{ } - -inline void gp_Lin2d::Reverse() -{ pos.Reverse(); } - -inline gp_Lin2d gp_Lin2d::Reversed() const -{ - gp_Lin2d L = *this; - L.pos.Reverse (); - return L; -} - -inline void gp_Lin2d::SetDirection (const gp_Dir2d& V) -{ pos.SetDirection (V); } - -inline void gp_Lin2d::SetLocation (const gp_Pnt2d& P) -{ pos.SetLocation (P); } - -inline void gp_Lin2d::SetPosition (const gp_Ax2d& A) -{ pos = A; } - -inline void gp_Lin2d::Coefficients (Standard_Real& A, - Standard_Real& B, - Standard_Real& C) const -{ - A = pos.Direction().Y(); - B = - pos.Direction().X(); - C = -(A * pos.Location().X() + B * pos.Location().Y()); -} - -inline const gp_Dir2d& gp_Lin2d::Direction() const -{ return pos.Direction(); } - -inline const gp_Pnt2d& gp_Lin2d::Location() const -{ return pos.Location(); } - -inline const gp_Ax2d& gp_Lin2d::Position() const -{ return pos; } - -inline Standard_Real gp_Lin2d::Angle (const gp_Lin2d& Other) const -{ return pos.Direction().Angle (Other.pos.Direction()); } - -inline Standard_Boolean gp_Lin2d::Contains -(const gp_Pnt2d& P, - const Standard_Real LinearTolerance) const -{ return Distance(P) <= LinearTolerance; } - -inline Standard_Real gp_Lin2d::Distance (const gp_Pnt2d& P) const -{ - gp_XY Coord = P.XY(); - Coord.Subtract ((pos.Location()).XY()); - Standard_Real val = Coord.Crossed (pos.Direction().XY()); - if (val < 0) val = - val; - return val; -} - -inline Standard_Real gp_Lin2d::Distance (const gp_Lin2d& Other) const -{ - Standard_Real D = 0.0; - if (pos.IsParallel (Other.pos, gp::Resolution())) - D = Other.Distance(pos.Location()); - return D; -} - -inline Standard_Real gp_Lin2d::SquareDistance (const gp_Pnt2d& P) const -{ - gp_XY Coord = P.XY(); - Coord.Subtract ((pos.Location()).XY()); - Standard_Real D = Coord.Crossed (pos.Direction().XY()); - return D * D; -} - -inline Standard_Real gp_Lin2d::SquareDistance (const gp_Lin2d& Other) const -{ - Standard_Real D = 0.0; - if (pos.IsParallel (Other.pos, gp::Resolution())) - D = Other.SquareDistance(pos.Location()); - return D; -} - -inline gp_Lin2d gp_Lin2d::Normal (const gp_Pnt2d& P) const -{ - return gp_Lin2d - (gp_Ax2d - (P,gp_Dir2d - (-(pos.Direction().Y()), pos.Direction().X()))); -} - -inline void gp_Lin2d::Rotate (const gp_Pnt2d& P, const Standard_Real Ang) -{ pos.Rotate (P, Ang); } - -inline gp_Lin2d gp_Lin2d::Rotated (const gp_Pnt2d& P, - const Standard_Real Ang) const -{ - gp_Lin2d L = *this; - L.pos.Rotate (P, Ang); - return L; -} - -inline void gp_Lin2d::Scale (const gp_Pnt2d& P, const Standard_Real S) -{ pos.Scale(P, S); } - -inline gp_Lin2d gp_Lin2d::Scaled (const gp_Pnt2d& P, - const Standard_Real S) const -{ - gp_Lin2d L = *this; - L.pos.Scale(P, S); - return L; -} - -inline void gp_Lin2d::Transform (const gp_Trsf2d& T) -{ pos.Transform(T); } - -inline gp_Lin2d gp_Lin2d::Transformed (const gp_Trsf2d& T) const -{ - gp_Lin2d L = *this; - L.pos.Transform(T); - return L; -} - -inline void gp_Lin2d::Translate (const gp_Vec2d& V) -{ pos.Translate(V); } - -inline gp_Lin2d gp_Lin2d::Translated (const gp_Vec2d& V) const -{ - gp_Lin2d L = *this; - L.pos.Translate(V); - return L; -} - -inline void gp_Lin2d::Translate (const gp_Pnt2d& P1, - const gp_Pnt2d& P2) -{ pos.Translate(P1, P2); } - -inline gp_Lin2d gp_Lin2d::Translated (const gp_Pnt2d& P1, - const gp_Pnt2d& P2) const -{ - gp_Lin2d L = *this; - L.pos.Translate (gp_Vec2d(P1, P2)); - return L; -} - diff --git a/src/gp/gp_Mat.cxx b/src/gp/gp_Mat.cxx index dcf8fe37e8..b14d6b4caf 100644 --- a/src/gp/gp_Mat.cxx +++ b/src/gp/gp_Mat.cxx @@ -19,9 +19,9 @@ #define No_Standard_ConstructionError #endif +#include #include -#include #include #include #include diff --git a/src/gp/gp_Mat.hxx b/src/gp/gp_Mat.hxx index c51c0393c1..2bf880d8b0 100644 --- a/src/gp/gp_Mat.hxx +++ b/src/gp/gp_Mat.hxx @@ -15,22 +15,44 @@ #ifndef _gp_Mat_HeaderFile #define _gp_Mat_HeaderFile -#include -#include -#include - -#include -#include -#include +#include +#include #include +#include -class Standard_ConstructionError; -class Standard_OutOfRange; class gp_XYZ; class gp_Trsf; class gp_GTrsf; +#define Mat00 matrix[0][0] +#define Mat01 matrix[0][1] +#define Mat02 matrix[0][2] +#define Mat10 matrix[1][0] +#define Mat11 matrix[1][1] +#define Mat12 matrix[1][2] +#define Mat20 matrix[2][0] +#define Mat21 matrix[2][1] +#define Mat22 matrix[2][2] +#define Nat00 aNewMat.matrix[0][0] +#define Nat01 aNewMat.matrix[0][1] +#define Nat02 aNewMat.matrix[0][2] +#define Nat10 aNewMat.matrix[1][0] +#define Nat11 aNewMat.matrix[1][1] +#define Nat12 aNewMat.matrix[1][2] +#define Nat20 aNewMat.matrix[2][0] +#define Nat21 aNewMat.matrix[2][1] +#define Nat22 aNewMat.matrix[2][2] + +#define Oat00 theOther.matrix[0][0] +#define Oat01 theOther.matrix[0][1] +#define Oat02 theOther.matrix[0][2] +#define Oat10 theOther.matrix[1][0] +#define Oat11 theOther.matrix[1][1] +#define Oat12 theOther.matrix[1][2] +#define Oat20 theOther.matrix[2][0] +#define Oat21 theOther.matrix[2][1] +#define Oat22 theOther.matrix[2][2] //! Describes a three column, three row matrix. This sort of //! object is used in various vectorial or matrix computations. @@ -40,152 +62,178 @@ public: DEFINE_STANDARD_ALLOC - //! creates a matrix with null coefficients. - gp_Mat(); - - gp_Mat(const Standard_Real a11, const Standard_Real a12, const Standard_Real a13, const Standard_Real a21, const Standard_Real a22, const Standard_Real a23, const Standard_Real a31, const Standard_Real a32, const Standard_Real a33); - + gp_Mat() + { + Mat00 = Mat01 = Mat02 = + Mat10 = Mat11 = Mat12 = + Mat20 = Mat21 = Mat22 = 0.0; + } + + gp_Mat (const Standard_Real theA11, const Standard_Real theA12, const Standard_Real theA13, + const Standard_Real theA21, const Standard_Real theA22, const Standard_Real theA23, + const Standard_Real theA31, const Standard_Real theA32, const Standard_Real theA33); + //! Creates a matrix. - //! Col1, Col2, Col3 are the 3 columns of the matrix. - Standard_EXPORT gp_Mat(const gp_XYZ& Col1, const gp_XYZ& Col2, const gp_XYZ& Col3); - - //! Assigns the three coordinates of Value to the column of index - //! Col of this matrix. - //! Raises OutOfRange if Col < 1 or Col > 3. - Standard_EXPORT void SetCol (const Standard_Integer Col, const gp_XYZ& Value); - - //! Assigns the number triples Col1, Col2, Col3 to the three + //! theCol1, theCol2, theCol3 are the 3 columns of the matrix. + Standard_EXPORT gp_Mat (const gp_XYZ& theCol1, const gp_XYZ& theCol2, const gp_XYZ& theCol3); + + //! Assigns the three coordinates of theValue to the column of index + //! theCol of this matrix. + //! Raises OutOfRange if theCol < 1 or theCol > 3. + Standard_EXPORT void SetCol (const Standard_Integer theCol, const gp_XYZ& theValue); + + //! Assigns the number triples theCol1, theCol2, theCol3 to the three //! columns of this matrix. - Standard_EXPORT void SetCols (const gp_XYZ& Col1, const gp_XYZ& Col2, const gp_XYZ& Col3); - + Standard_EXPORT void SetCols (const gp_XYZ& theCol1, const gp_XYZ& theCol2, const gp_XYZ& theCol3); //! Modifies the matrix M so that applying it to any number //! triple (X, Y, Z) produces the same result as the cross - //! product of Ref and the number triple (X, Y, Z): - //! i.e.: M * {X,Y,Z}t = Ref.Cross({X, Y ,Z}) + //! product of theRef and the number triple (X, Y, Z): + //! i.e.: M * {X,Y,Z}t = theRef.Cross({X, Y ,Z}) //! this matrix is anti symmetric. To apply this matrix to the //! triplet {XYZ} is the same as to do the cross product between the - //! triplet Ref and the triplet {XYZ}. + //! triplet theRef and the triplet {XYZ}. //! Note: this matrix is anti-symmetric. - Standard_EXPORT void SetCross (const gp_XYZ& Ref); - + Standard_EXPORT void SetCross (const gp_XYZ& theRef); //! Modifies the main diagonal of the matrix. //! @code - //! .Value (1, 1) = X1 - //! .Value (2, 2) = X2 - //! .Value (3, 3) = X3 + //! .Value (1, 1) = theX1 + //! .Value (2, 2) = theX2 + //! .Value (3, 3) = theX3 //! @endcode //! The other coefficients of the matrix are not modified. - void SetDiagonal (const Standard_Real X1, const Standard_Real X2, const Standard_Real X3); - + void SetDiagonal (const Standard_Real theX1, const Standard_Real theX2, const Standard_Real theX3) + { + Mat00 = theX1; + Mat11 = theX2; + Mat22 = theX3; + } //! Modifies this matrix so that applying it to any number //! triple (X, Y, Z) produces the same result as the scalar - //! product of Ref and the number triple (X, Y, Z): - //! this * (X,Y,Z) = Ref.(X,Y,Z) + //! product of theRef and the number triple (X, Y, Z): + //! this * (X,Y,Z) = theRef.(X,Y,Z) //! Note: this matrix is symmetric. - Standard_EXPORT void SetDot (const gp_XYZ& Ref); - - //! Modifies this matrix so that it represents the Identity matrix. - void SetIdentity(); - + Standard_EXPORT void SetDot (const gp_XYZ& theRef); - //! Modifies this matrix so that it represents a rotation. Ang is the angular value in + //! Modifies this matrix so that it represents the Identity matrix. + void SetIdentity() + { + Mat00 = Mat11 = Mat22 = 1.0; + Mat01 = Mat02 = Mat10 = Mat12 = Mat20 = Mat21 = 0.0; + } + + //! Modifies this matrix so that it represents a rotation. theAng is the angular value in //! radians and the XYZ axis gives the direction of the //! rotation. //! Raises ConstructionError if XYZ.Modulus() <= Resolution() - Standard_EXPORT void SetRotation (const gp_XYZ& Axis, const Standard_Real Ang); - + Standard_EXPORT void SetRotation (const gp_XYZ& theAxis, const Standard_Real theAng); + //! Assigns the three coordinates of Value to the row of index - //! Row of this matrix. Raises OutOfRange if Row < 1 or Row > 3. - Standard_EXPORT void SetRow (const Standard_Integer Row, const gp_XYZ& Value); - - //! Assigns the number triples Row1, Row2, Row3 to the three + //! theRow of this matrix. Raises OutOfRange if theRow < 1 or theRow > 3. + Standard_EXPORT void SetRow (const Standard_Integer theRow, const gp_XYZ& theValue); + + //! Assigns the number triples theRow1, theRow2, theRow3 to the three //! rows of this matrix. - Standard_EXPORT void SetRows (const gp_XYZ& Row1, const gp_XYZ& Row2, const gp_XYZ& Row3); - + Standard_EXPORT void SetRows (const gp_XYZ& theRow1, const gp_XYZ& theRow2, const gp_XYZ& theRow3); //! Modifies the matrix so that it represents - //! a scaling transformation, where S is the scale factor. : + //! a scaling transformation, where theS is the scale factor. : //! @code - //! | S 0.0 0.0 | - //! = | 0.0 S 0.0 | - //! | 0.0 0.0 S | + //! | theS 0.0 0.0 | + //! = | 0.0 theS 0.0 | + //! | 0.0 0.0 theS | //! @endcode - void SetScale (const Standard_Real S); - - //! Assigns to the coefficient of row Row, column Col of this matrix. - //! Raises OutOfRange if Row < 1 or Row > 3 or Col < 1 or Col > 3 - void SetValue (const Standard_Integer Row, const Standard_Integer Col, const Standard_Real Value); - - //! Returns the column of Col index. - //! Raises OutOfRange if Col < 1 or Col > 3 - Standard_EXPORT gp_XYZ Column (const Standard_Integer Col) const; - + void SetScale (const Standard_Real theS) + { + Mat00 = Mat11 = Mat22 = theS; + Mat01 = Mat02 = Mat10 = Mat12 = Mat20 = Mat21 = 0.0; + } + + //! Assigns to the coefficient of row theRow, column theCol of this matrix. + //! Raises OutOfRange if theRow < 1 or theRow > 3 or theCol < 1 or theCol > 3 + void SetValue (const Standard_Integer theRow, const Standard_Integer theCol, const Standard_Real theValue) + { + Standard_OutOfRange_Raise_if (theRow < 1 || theRow > 3 || theCol < 1 || theCol > 3, " "); + matrix[theRow - 1][theCol - 1] = theValue; + } + + //! Returns the column of theCol index. + //! Raises OutOfRange if theCol < 1 or theCol > 3 + Standard_EXPORT gp_XYZ Column (const Standard_Integer theCol) const; + //! Computes the determinant of the matrix. - Standard_Real Determinant() const; - + Standard_Real Determinant() const + { + return Mat00 * (Mat11 * Mat22 - Mat21 * Mat12) - + Mat01 * (Mat10 * Mat22 - Mat20 * Mat12) + + Mat02 * (Mat10 * Mat21 - Mat20 * Mat11); + } + //! Returns the main diagonal of the matrix. Standard_EXPORT gp_XYZ Diagonal() const; - - //! returns the row of Row index. - //! Raises OutOfRange if Row < 1 or Row > 3 - Standard_EXPORT gp_XYZ Row (const Standard_Integer Row) const; - - //! Returns the coefficient of range (Row, Col) - //! Raises OutOfRange if Row < 1 or Row > 3 or Col < 1 or Col > 3 - const Standard_Real& Value (const Standard_Integer Row, const Standard_Integer Col) const; - const Standard_Real& operator() (const Standard_Integer Row, const Standard_Integer Col) const -{ - return Value(Row,Col); -} - - //! Returns the coefficient of range (Row, Col) - //! Raises OutOfRange if Row < 1 or Row > 3 or Col < 1 or Col > 3 - Standard_Real& ChangeValue (const Standard_Integer Row, const Standard_Integer Col); - Standard_Real& operator() (const Standard_Integer Row, const Standard_Integer Col) -{ - return ChangeValue(Row,Col); -} - + + //! returns the row of theRow index. + //! Raises OutOfRange if theRow < 1 or theRow > 3 + Standard_EXPORT gp_XYZ Row (const Standard_Integer theRow) const; + + //! Returns the coefficient of range (theRow, theCol) + //! Raises OutOfRange if theRow < 1 or theRow > 3 or theCol < 1 or theCol > 3 + const Standard_Real& Value (const Standard_Integer theRow, const Standard_Integer theCol) const + { + Standard_OutOfRange_Raise_if (theRow < 1 || theRow > 3 || theCol < 1 || theCol > 3, " "); + return matrix[theRow - 1][theCol - 1]; + } + + const Standard_Real& operator() (const Standard_Integer theRow, const Standard_Integer theCol) const { return Value (theRow, theCol); } + + //! Returns the coefficient of range (theRow, theCol) + //! Raises OutOfRange if theRow < 1 or theRow > 3 or theCol < 1 or theCol > 3 + Standard_Real& ChangeValue (const Standard_Integer theRow, const Standard_Integer theCol) + { + Standard_OutOfRange_Raise_if (theRow < 1 || theRow > 3 || theCol < 1 || theCol > 3, " "); + return matrix[theRow - 1][theCol - 1]; + } + + Standard_Real& operator() (const Standard_Integer theRow, const Standard_Integer theCol) { return ChangeValue (theRow, theCol); } //! The Gauss LU decomposition is used to invert the matrix //! (see Math package) so the matrix is considered as singular if //! the largest pivot found is lower or equal to Resolution from gp. - Standard_Boolean IsSingular() const; - - void Add (const gp_Mat& Other); - void operator += (const gp_Mat& Other) -{ - Add(Other); -} - + Standard_Boolean IsSingular() const + { + // Pour etre sur que Gauss va fonctionner, il faut faire Gauss ... + Standard_Real aVal = Determinant(); + if (aVal < 0) + { + aVal = -aVal; + } + return aVal <= gp::Resolution(); + } + + void Add (const gp_Mat& theOther); + + void operator += (const gp_Mat& theOther) { Add (theOther); } + //! Computes the sum of this matrix and - //! the matrix Other for each coefficient of the matrix : - //! .Coef(i,j) + .Coef(i,j) - Standard_NODISCARD gp_Mat Added (const gp_Mat& Other) const; - Standard_NODISCARD gp_Mat operator + (const gp_Mat& Other) const -{ - return Added(Other); -} - - void Divide (const Standard_Real Scalar); - void operator /= (const Standard_Real Scalar) -{ - Divide(Scalar); -} - + //! the matrix theOther for each coefficient of the matrix : + //! .Coef(i,j) + .Coef(i,j) + Standard_NODISCARD gp_Mat Added (const gp_Mat& theOther) const; + + Standard_NODISCARD gp_Mat operator + (const gp_Mat& theOther) const { return Added (theOther); } + + void Divide (const Standard_Real theScalar); + + void operator /= (const Standard_Real theScalar) { Divide (theScalar); } + //! Divides all the coefficients of the matrix by Scalar - Standard_NODISCARD gp_Mat Divided (const Standard_Real Scalar) const; - Standard_NODISCARD gp_Mat operator / (const Standard_Real Scalar) const -{ - return Divided(Scalar); -} - + Standard_NODISCARD gp_Mat Divided (const Standard_Real theScalar) const; + + Standard_NODISCARD gp_Mat operator / (const Standard_Real theScalar) const { return Divided (theScalar); } + Standard_EXPORT void Invert(); - //! Inverses the matrix and raises if the matrix is singular. //! - Invert assigns the result to this matrix, while @@ -198,98 +246,345 @@ public: //! Standard_ConstructionError if this matrix is singular, //! and therefore cannot be inverted. Standard_NODISCARD Standard_EXPORT gp_Mat Inverted() const; - //! Computes the product of two matrices * - Standard_NODISCARD gp_Mat Multiplied (const gp_Mat& Other) const; - Standard_NODISCARD gp_Mat operator * (const gp_Mat& Other) const -{ - return Multiplied(Other); -} - + Standard_NODISCARD gp_Mat Multiplied (const gp_Mat& theOther) const + { + gp_Mat aNewMat = *this; + aNewMat.Multiply (theOther); + return aNewMat; + } + + Standard_NODISCARD gp_Mat operator * (const gp_Mat& theOther) const { return Multiplied (theOther); } + //! Computes the product of two matrices = * . - void Multiply (const gp_Mat& Other); - void operator *= (const gp_Mat& Other) -{ - Multiply(Other); -} - - void PreMultiply (const gp_Mat& Other); - - Standard_NODISCARD gp_Mat Multiplied (const Standard_Real Scalar) const; - Standard_NODISCARD gp_Mat operator * (const Standard_Real Scalar) const -{ - return Multiplied(Scalar); -} - + void Multiply (const gp_Mat& theOther); + + void operator *= (const gp_Mat& theOther) { Multiply (theOther); } + + void PreMultiply (const gp_Mat& theOther); + + Standard_NODISCARD gp_Mat Multiplied (const Standard_Real theScalar) const; + + Standard_NODISCARD gp_Mat operator * (const Standard_Real theScalar) const { return Multiplied (theScalar); } //! Multiplies all the coefficients of the matrix by Scalar - void Multiply (const Standard_Real Scalar); - void operator *= (const Standard_Real Scalar) -{ - Multiply(Scalar); -} - - Standard_EXPORT void Power (const Standard_Integer N); - + void Multiply (const Standard_Real theScalar); - //! Computes = * * .......* , N time. - //! if N = 0 = Identity - //! if N < 0 = .Invert() *...........* .Invert(). - //! If N < 0 an exception will be raised if the matrix is not + void operator *= (const Standard_Real theScalar) { Multiply (theScalar); } + + Standard_EXPORT void Power (const Standard_Integer N); + + //! Computes = * * .......* , theN time. + //! if theN = 0 = Identity + //! if theN < 0 = .Invert() *...........* .Invert(). + //! If theN < 0 an exception will be raised if the matrix is not //! inversible - Standard_NODISCARD gp_Mat Powered (const Standard_Integer N) const; - - void Subtract (const gp_Mat& Other); - void operator -= (const gp_Mat& Other) -{ - Subtract(Other); -} - + Standard_NODISCARD gp_Mat Powered (const Standard_Integer theN) const + { + gp_Mat aMatN = *this; + aMatN.Power (theN); + return aMatN; + } + + void Subtract (const gp_Mat& theOther); + + void operator -= (const gp_Mat& theOther) { Subtract (theOther); } //! cOmputes for each coefficient of the matrix : - //! .Coef(i,j) - .Coef(i,j) - Standard_NODISCARD gp_Mat Subtracted (const gp_Mat& Other) const; - Standard_NODISCARD gp_Mat operator - (const gp_Mat& Other) const -{ - return Subtracted(Other); -} - - void Transpose(); - + //! .Coef(i,j) - .Coef(i,j) + Standard_NODISCARD gp_Mat Subtracted (const gp_Mat& theOther) const; + + Standard_NODISCARD gp_Mat operator - (const gp_Mat& theOther) const { return Subtracted (theOther); } + + void Transpose(); //! Transposes the matrix. A(j, i) -> A (i, j) - Standard_NODISCARD gp_Mat Transposed() const; + Standard_NODISCARD gp_Mat Transposed() const + { + gp_Mat aNewMat = *this; + aNewMat.Transpose(); + return aNewMat; + } //! Dumps the content of me into the stream Standard_EXPORT void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const; - friend class gp_XYZ; friend class gp_Trsf; friend class gp_GTrsf; - -protected: - - - - - private: - - Standard_Real matrix[3][3]; - }; +//======================================================================= +//function : gp_Mat +// purpose : +//======================================================================= +inline gp_Mat::gp_Mat (const Standard_Real theA11, const Standard_Real theA12, const Standard_Real theA13, + const Standard_Real theA21, const Standard_Real theA22, const Standard_Real theA23, + const Standard_Real theA31, const Standard_Real theA32, const Standard_Real theA33) + { + Mat00 = theA11; + Mat01 = theA12; + Mat02 = theA13; + Mat10 = theA21; + Mat11 = theA22; + Mat12 = theA23; + Mat20 = theA31; + Mat21 = theA32; + Mat22 = theA33; + } -#include +//======================================================================= +//function : Add +// purpose : +//======================================================================= +inline void gp_Mat::Add (const gp_Mat& theOther) +{ + Mat00 = Mat00 + Oat00; + Mat01 = Mat01 + Oat01; + Mat02 = Mat02 + Oat02; + Mat10 = Mat10 + Oat10; + Mat11 = Mat11 + Oat11; + Mat12 = Mat12 + Oat12; + Mat20 = Mat20 + Oat20; + Mat21 = Mat21 + Oat21; + Mat22 = Mat22 + Oat22; +} +//======================================================================= +//function : Added +// purpose : +//======================================================================= +inline gp_Mat gp_Mat::Added (const gp_Mat& theOther) const +{ + gp_Mat aNewMat; + Nat00 = Mat00 + Oat00; + Nat01 = Mat01 + Oat01; + Nat02 = Mat02 + Oat02; + Nat10 = Mat10 + Oat10; + Nat11 = Mat11 + Oat11; + Nat12 = Mat12 + Oat12; + Nat20 = Mat20 + Oat20; + Nat21 = Mat21 + Oat21; + Nat22 = Mat22 + Oat22; + return aNewMat; +} +//======================================================================= +//function : Divide +// purpose : +//======================================================================= +inline void gp_Mat::Divide (const Standard_Real theScalar) +{ + Standard_Real aVal = theScalar; + if (aVal < 0) + { + aVal = -aVal; + } + Standard_ConstructionError_Raise_if (aVal <= gp::Resolution(),"gp_Mat : Divide by 0"); + Standard_Real anUnSurScalar = 1.0 / theScalar; + Mat00 *= anUnSurScalar; + Mat01 *= anUnSurScalar; + Mat02 *= anUnSurScalar; + Mat10 *= anUnSurScalar; + Mat11 *= anUnSurScalar; + Mat12 *= anUnSurScalar; + Mat20 *= anUnSurScalar; + Mat21 *= anUnSurScalar; + Mat22 *= anUnSurScalar; +} +//======================================================================= +//function : Divided +// purpose : +//======================================================================= +inline gp_Mat gp_Mat::Divided (const Standard_Real theScalar) const +{ + Standard_Real aVal = theScalar; + if (aVal < 0) + { + aVal = -aVal; + } + Standard_ConstructionError_Raise_if (aVal <= gp::Resolution(),"gp_Mat : Divide by 0"); + gp_Mat aNewMat; + Standard_Real anUnSurScalar = 1.0 / theScalar; + Nat00 = Mat00 * anUnSurScalar; + Nat01 = Mat01 * anUnSurScalar; + Nat02 = Mat02 * anUnSurScalar; + Nat10 = Mat10 * anUnSurScalar; + Nat11 = Mat11 * anUnSurScalar; + Nat12 = Mat12 * anUnSurScalar; + Nat20 = Mat20 * anUnSurScalar; + Nat21 = Mat21 * anUnSurScalar; + Nat22 = Mat22 * anUnSurScalar; + return aNewMat; +} +//======================================================================= +//function : Multiply +// purpose : +//======================================================================= +inline void gp_Mat::Multiply (const gp_Mat& theOther) +{ + Standard_Real aT00, aT01, aT02, aT10, aT11, aT12, aT20, aT21, aT22; + aT00 = Mat00 * Oat00 + Mat01 * Oat10 + Mat02 * Oat20; + aT01 = Mat00 * Oat01 + Mat01 * Oat11 + Mat02 * Oat21; + aT02 = Mat00 * Oat02 + Mat01 * Oat12 + Mat02 * Oat22; + aT10 = Mat10 * Oat00 + Mat11 * Oat10 + Mat12 * Oat20; + aT11 = Mat10 * Oat01 + Mat11 * Oat11 + Mat12 * Oat21; + aT12 = Mat10 * Oat02 + Mat11 * Oat12 + Mat12 * Oat22; + aT20 = Mat20 * Oat00 + Mat21 * Oat10 + Mat22 * Oat20; + aT21 = Mat20 * Oat01 + Mat21 * Oat11 + Mat22 * Oat21; + aT22 = Mat20 * Oat02 + Mat21 * Oat12 + Mat22 * Oat22; + Mat00 = aT00; + Mat01 = aT01; + Mat02 = aT02; + Mat10 = aT10; + Mat11 = aT11; + Mat12 = aT12; + Mat20 = aT20; + Mat21 = aT21; + Mat22 = aT22; +} + +//======================================================================= +//function : PreMultiply +// purpose : +//======================================================================= +inline void gp_Mat::PreMultiply (const gp_Mat& theOther) +{ + Standard_Real aT00, aT01, aT02, aT10, aT11, aT12, aT20, aT21, aT22; + aT00 = Oat00 * Mat00 + Oat01 * Mat10 + Oat02 * Mat20; + aT01 = Oat00 * Mat01 + Oat01 * Mat11 + Oat02 * Mat21; + aT02 = Oat00 * Mat02 + Oat01 * Mat12 + Oat02 * Mat22; + aT10 = Oat10 * Mat00 + Oat11 * Mat10 + Oat12 * Mat20; + aT11 = Oat10 * Mat01 + Oat11 * Mat11 + Oat12 * Mat21; + aT12 = Oat10 * Mat02 + Oat11 * Mat12 + Oat12 * Mat22; + aT20 = Oat20 * Mat00 + Oat21 * Mat10 + Oat22 * Mat20; + aT21 = Oat20 * Mat01 + Oat21 * Mat11 + Oat22 * Mat21; + aT22 = Oat20 * Mat02 + Oat21 * Mat12 + Oat22 * Mat22; + Mat00 = aT00; + Mat01 = aT01; + Mat02 = aT02; + Mat10 = aT10; + Mat11 = aT11; + Mat12 = aT12; + Mat20 = aT20; + Mat21 = aT21; + Mat22 = aT22; +} + +//======================================================================= +//function : Multiplied +// purpose : +//======================================================================= +inline gp_Mat gp_Mat::Multiplied (const Standard_Real theScalar) const +{ + gp_Mat aNewMat; + Nat00 = theScalar * Mat00; + Nat01 = theScalar * Mat01; + Nat02 = theScalar * Mat02; + Nat10 = theScalar * Mat10; + Nat11 = theScalar * Mat11; + Nat12 = theScalar * Mat12; + Nat20 = theScalar * Mat20; + Nat21 = theScalar * Mat21; + Nat22 = theScalar * Mat22; + return aNewMat; +} + +//======================================================================= +//function : Multiply +// purpose : +//======================================================================= +inline void gp_Mat::Multiply (const Standard_Real theScalar) +{ + Mat00 *= theScalar; + Mat01 *= theScalar; + Mat02 *= theScalar; + Mat10 *= theScalar; + Mat11 *= theScalar; + Mat12 *= theScalar; + Mat20 *= theScalar; + Mat21 *= theScalar; + Mat22 *= theScalar; +} + +//======================================================================= +//function : Subtract +// purpose : +//======================================================================= +inline void gp_Mat::Subtract (const gp_Mat& theOther) +{ + Mat00 -= Oat00; + Mat01 -= Oat01; + Mat02 -= Oat02; + Mat10 -= Oat10; + Mat11 -= Oat11; + Mat12 -= Oat12; + Mat20 -= Oat20; + Mat21 -= Oat21; + Mat22 -= Oat22; +} + +//======================================================================= +//function : Subtracted +// purpose : +//======================================================================= +inline gp_Mat gp_Mat::Subtracted (const gp_Mat& theOther) const +{ + gp_Mat aNewMat; + Nat00 = Mat00 - Oat00; + Nat01 = Mat01 - Oat01; + Nat02 = Mat02 - Oat02; + Nat10 = Mat10 - Oat10; + Nat11 = Mat11 - Oat11; + Nat12 = Mat12 - Oat12; + Nat20 = Mat20 - Oat20; + Nat21 = Mat21 - Oat21; + Nat22 = Mat22 - Oat22; + return aNewMat; +} + +//======================================================================= +//function : Transpose +// purpose : +//======================================================================= +// On macOS 10.13.6 with XCode 9.4.1 the compiler has a bug leading to +// generation of invalid code when method gp_Mat::Transpose() is called +// for a matrix which is when applied to vector; it looks like vector +// is transformed before the matrix is actually transposed; see #29978. +// To avoid this, we disable compiler optimization here. +#if defined(__APPLE__) && (__apple_build_version__ > 9020000) +__attribute__((optnone)) +#endif +inline void gp_Mat::Transpose() +{ + Standard_Real aTemp; + aTemp = Mat01; + Mat01 = Mat10; + Mat10 = aTemp; + aTemp = Mat02; + Mat02 = Mat20; + Mat20 = aTemp; + aTemp = Mat12; + Mat12 = Mat21; + Mat21 = aTemp; +} + +//======================================================================= +//function : operator* +// purpose : +//======================================================================= +inline gp_Mat operator* (const Standard_Real theScalar, + const gp_Mat& theMat3D) +{ + return theMat3D.Multiplied (theScalar); +} #endif // _gp_Mat_HeaderFile diff --git a/src/gp/gp_Mat.lxx b/src/gp/gp_Mat.lxx deleted file mode 100644 index f2bb985545..0000000000 --- a/src/gp/gp_Mat.lxx +++ /dev/null @@ -1,355 +0,0 @@ -// Copyright (c) 1995-1999 Matra Datavision -// Copyright (c) 1999-2014 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -#include -#include -#include - -#define Mat00 matrix[0][0] -#define Mat01 matrix[0][1] -#define Mat02 matrix[0][2] -#define Mat10 matrix[1][0] -#define Mat11 matrix[1][1] -#define Mat12 matrix[1][2] -#define Mat20 matrix[2][0] -#define Mat21 matrix[2][1] -#define Mat22 matrix[2][2] - -#define Nat00 NewMat.matrix[0][0] -#define Nat01 NewMat.matrix[0][1] -#define Nat02 NewMat.matrix[0][2] -#define Nat10 NewMat.matrix[1][0] -#define Nat11 NewMat.matrix[1][1] -#define Nat12 NewMat.matrix[1][2] -#define Nat20 NewMat.matrix[2][0] -#define Nat21 NewMat.matrix[2][1] -#define Nat22 NewMat.matrix[2][2] - -#define Oat00 Other.matrix[0][0] -#define Oat01 Other.matrix[0][1] -#define Oat02 Other.matrix[0][2] -#define Oat10 Other.matrix[1][0] -#define Oat11 Other.matrix[1][1] -#define Oat12 Other.matrix[1][2] -#define Oat20 Other.matrix[2][0] -#define Oat21 Other.matrix[2][1] -#define Oat22 Other.matrix[2][2] - -inline gp_Mat::gp_Mat () { - Mat00 = - Mat01 = - Mat02 = - Mat10 = - Mat11 = - Mat12 = - Mat20 = - Mat21 = - Mat22 = 0.0; -} - -inline gp_Mat::gp_Mat (const Standard_Real a11, - const Standard_Real a12, - const Standard_Real a13, - const Standard_Real a21, - const Standard_Real a22, - const Standard_Real a23, - const Standard_Real a31, - const Standard_Real a32, - const Standard_Real a33) { - - Mat00 = a11; - Mat01 = a12; - Mat02 = a13; - Mat10 = a21; - Mat11 = a22; - Mat12 = a23; - Mat20 = a31; - Mat21 = a32; - Mat22 = a33; -} - -inline void gp_Mat::SetDiagonal (const Standard_Real X1, - const Standard_Real X2, - const Standard_Real X3) -{ - Mat00 = X1; Mat11 = X2; Mat22 = X3; -} - -inline void gp_Mat::SetIdentity () -{ - Mat00 = Mat11 = Mat22 = 1.0; - Mat01 = Mat02 = Mat10 = Mat12 = Mat20 = Mat21 = 0.0; - } - -inline void gp_Mat::SetScale (const Standard_Real S) -{ - Mat00 = Mat11 = Mat22 = S; - Mat01 = Mat02 = Mat10 = Mat12 = Mat20 = Mat21 = 0.0; -} - -inline void gp_Mat::SetValue (const Standard_Integer Row, - const Standard_Integer Col, - const Standard_Real Value) -{ - Standard_OutOfRange_Raise_if - (Row < 1 || Row > 3 || Col < 1 || Col > 3, " "); - matrix[Row-1][Col-1] = Value; -} - -inline Standard_Real gp_Mat::Determinant () const -{ - return - Mat00 * (Mat11 * Mat22 - Mat21 * Mat12) - - Mat01 * (Mat10 * Mat22 - Mat20 * Mat12) + - Mat02 * (Mat10 * Mat21 - Mat20 * Mat11); -} - -inline const Standard_Real& gp_Mat::Value (const Standard_Integer Row, - const Standard_Integer Col) const -{ - Standard_OutOfRange_Raise_if - (Row < 1 || Row > 3 || Col < 1 || Col > 3, " "); - return matrix[Row-1][Col-1]; -} - -inline Standard_Real& gp_Mat::ChangeValue (const Standard_Integer Row, - const Standard_Integer Col) -{ - Standard_OutOfRange_Raise_if - (Row < 1 || Row > 3 || Col < 1 || Col > 3, " "); - return matrix[Row-1][Col-1]; -} - -inline Standard_Boolean gp_Mat::IsSingular () const -{ - // Pour etre sur que Gauss va fonctionner, il faut faire Gauss ... - Standard_Real val = Determinant(); - if (val < 0) val = - val; - return val <= gp::Resolution(); -} - -inline void gp_Mat::Add (const gp_Mat& Other) -{ - Mat00 = Mat00 + Oat00; - Mat01 = Mat01 + Oat01; - Mat02 = Mat02 + Oat02; - Mat10 = Mat10 + Oat10; - Mat11 = Mat11 + Oat11; - Mat12 = Mat12 + Oat12; - Mat20 = Mat20 + Oat20; - Mat21 = Mat21 + Oat21; - Mat22 = Mat22 + Oat22; -} - -inline gp_Mat gp_Mat::Added (const gp_Mat& Other) const -{ - gp_Mat NewMat; - Nat00 = Mat00 + Oat00; - Nat01 = Mat01 + Oat01; - Nat02 = Mat02 + Oat02; - Nat10 = Mat10 + Oat10; - Nat11 = Mat11 + Oat11; - Nat12 = Mat12 + Oat12; - Nat20 = Mat20 + Oat20; - Nat21 = Mat21 + Oat21; - Nat22 = Mat22 + Oat22; - return NewMat; -} - -inline void gp_Mat::Divide (const Standard_Real Scalar) -{ - Standard_Real val = Scalar; - if (val < 0) val = - val; - Standard_ConstructionError_Raise_if - (val <= gp::Resolution(),"gp_Mat : Divide by 0"); - Standard_Real UnSurScalar = 1.0 / Scalar; - Mat00 *= UnSurScalar; - Mat01 *= UnSurScalar; - Mat02 *= UnSurScalar; - Mat10 *= UnSurScalar; - Mat11 *= UnSurScalar; - Mat12 *= UnSurScalar; - Mat20 *= UnSurScalar; - Mat21 *= UnSurScalar; - Mat22 *= UnSurScalar; -} - -inline gp_Mat gp_Mat::Divided (const Standard_Real Scalar) const -{ - Standard_Real val = Scalar; - if (val < 0) val = - val; - Standard_ConstructionError_Raise_if - (val <= gp::Resolution(),"gp_Mat : Divide by 0"); - gp_Mat NewMat; - Standard_Real UnSurScalar = 1.0 / Scalar; - Nat00 = Mat00 * UnSurScalar; - Nat01 = Mat01 * UnSurScalar; - Nat02 = Mat02 * UnSurScalar; - Nat10 = Mat10 * UnSurScalar; - Nat11 = Mat11 * UnSurScalar; - Nat12 = Mat12 * UnSurScalar; - Nat20 = Mat20 * UnSurScalar; - Nat21 = Mat21 * UnSurScalar; - Nat22 = Mat22 * UnSurScalar; - return NewMat; -} - -inline gp_Mat gp_Mat::Multiplied (const gp_Mat& Other) const -{ - gp_Mat NewMat = *this; - NewMat.Multiply(Other); - return NewMat; -} - -inline void gp_Mat::Multiply (const gp_Mat& Other) -{ - Standard_Real T00,T01,T02,T10,T11,T12,T20,T21,T22; - T00 = Mat00 * Oat00 + Mat01 * Oat10 + Mat02 * Oat20; - T01 = Mat00 * Oat01 + Mat01 * Oat11 + Mat02 * Oat21; - T02 = Mat00 * Oat02 + Mat01 * Oat12 + Mat02 * Oat22; - T10 = Mat10 * Oat00 + Mat11 * Oat10 + Mat12 * Oat20; - T11 = Mat10 * Oat01 + Mat11 * Oat11 + Mat12 * Oat21; - T12 = Mat10 * Oat02 + Mat11 * Oat12 + Mat12 * Oat22; - T20 = Mat20 * Oat00 + Mat21 * Oat10 + Mat22 * Oat20; - T21 = Mat20 * Oat01 + Mat21 * Oat11 + Mat22 * Oat21; - T22 = Mat20 * Oat02 + Mat21 * Oat12 + Mat22 * Oat22; - Mat00 = T00; - Mat01 = T01; - Mat02 = T02; - Mat10 = T10; - Mat11 = T11; - Mat12 = T12; - Mat20 = T20; - Mat21 = T21; - Mat22 = T22; -} - -inline void gp_Mat::PreMultiply (const gp_Mat& Other) -{ - Standard_Real T00,T01,T02,T10,T11,T12,T20,T21,T22; - T00 = Oat00 * Mat00 + Oat01 * Mat10 + Oat02 * Mat20; - T01 = Oat00 * Mat01 + Oat01 * Mat11 + Oat02 * Mat21; - T02 = Oat00 * Mat02 + Oat01 * Mat12 + Oat02 * Mat22; - T10 = Oat10 * Mat00 + Oat11 * Mat10 + Oat12 * Mat20; - T11 = Oat10 * Mat01 + Oat11 * Mat11 + Oat12 * Mat21; - T12 = Oat10 * Mat02 + Oat11 * Mat12 + Oat12 * Mat22; - T20 = Oat20 * Mat00 + Oat21 * Mat10 + Oat22 * Mat20; - T21 = Oat20 * Mat01 + Oat21 * Mat11 + Oat22 * Mat21; - T22 = Oat20 * Mat02 + Oat21 * Mat12 + Oat22 * Mat22; - Mat00 = T00; - Mat01 = T01; - Mat02 = T02; - Mat10 = T10; - Mat11 = T11; - Mat12 = T12; - Mat20 = T20; - Mat21 = T21; - Mat22 = T22; -} - -inline gp_Mat gp_Mat::Multiplied (const Standard_Real Scalar) const -{ - gp_Mat NewMat; - Nat00 = Scalar * Mat00; - Nat01 = Scalar * Mat01; - Nat02 = Scalar * Mat02; - Nat10 = Scalar * Mat10; - Nat11 = Scalar * Mat11; - Nat12 = Scalar * Mat12; - Nat20 = Scalar * Mat20; - Nat21 = Scalar * Mat21; - Nat22 = Scalar * Mat22; - return NewMat; -} - -inline void gp_Mat::Multiply (const Standard_Real Scalar) -{ - Mat00 *= Scalar; - Mat01 *= Scalar; - Mat02 *= Scalar; - Mat10 *= Scalar; - Mat11 *= Scalar; - Mat12 *= Scalar; - Mat20 *= Scalar; - Mat21 *= Scalar; - Mat22 *= Scalar; -} - -inline gp_Mat gp_Mat::Powered (const Standard_Integer N) const -{ - gp_Mat MatN = *this; - MatN.Power (N); - return MatN; -} - -inline void gp_Mat::Subtract (const gp_Mat& Other) -{ - Mat00 -= Oat00; - Mat01 -= Oat01; - Mat02 -= Oat02; - Mat10 -= Oat10; - Mat11 -= Oat11; - Mat12 -= Oat12; - Mat20 -= Oat20; - Mat21 -= Oat21; - Mat22 -= Oat22; -} - -inline gp_Mat gp_Mat::Subtracted (const gp_Mat& Other) const -{ - gp_Mat NewMat; - Nat00 = Mat00 - Oat00; - Nat01 = Mat01 - Oat01; - Nat02 = Mat02 - Oat02; - Nat10 = Mat10 - Oat10; - Nat11 = Mat11 - Oat11; - Nat12 = Mat12 - Oat12; - Nat20 = Mat20 - Oat20; - Nat21 = Mat21 - Oat21; - Nat22 = Mat22 - Oat22; - return NewMat; -} - -// On macOS 10.13.6 with XCode 9.4.1 the compiler has a bug leading to -// generation of invalid code when method gp_Mat::Transpose() is called -// for a matrix which is when applied to vector; it looks like vector -// is transformed before the matrix is actually transposed; see #29978. -// To avoid this, we disable compiler optimization here. -#if defined(__APPLE__) && (__apple_build_version__ > 9020000) -__attribute__((optnone)) -#endif -inline void gp_Mat::Transpose () -{ - Standard_Real Temp; - Temp = Mat01; - Mat01 = Mat10; - Mat10 = Temp; - Temp = Mat02; - Mat02 = Mat20; - Mat20 = Temp; - Temp = Mat12; - Mat12 = Mat21; - Mat21 = Temp; -} - -inline gp_Mat gp_Mat::Transposed () const -{ - gp_Mat NewMat = *this; - NewMat.Transpose(); - return NewMat; -} - -inline gp_Mat operator* (const Standard_Real Scalar, const gp_Mat& Mat3D) -{ return Mat3D.Multiplied (Scalar); } - diff --git a/src/gp/gp_Mat2d.cxx b/src/gp/gp_Mat2d.cxx index 6aa7698c8e..e721db6fa8 100644 --- a/src/gp/gp_Mat2d.cxx +++ b/src/gp/gp_Mat2d.cxx @@ -19,9 +19,9 @@ #define No_Standard_ConstructionError #endif +#include #include -#include #include #include #include diff --git a/src/gp/gp_Mat2d.hxx b/src/gp/gp_Mat2d.hxx index 83c2bd8316..3c328263cb 100644 --- a/src/gp/gp_Mat2d.hxx +++ b/src/gp/gp_Mat2d.hxx @@ -15,20 +15,28 @@ #ifndef _gp_Mat2d_HeaderFile #define _gp_Mat2d_HeaderFile -#include -#include -#include +#include +#include +#include -#include -#include -#include -class Standard_ConstructionError; -class Standard_OutOfRange; class gp_Trsf2d; class gp_GTrsf2d; class gp_XY; +#define Mat2d00 ((Standard_Real*)aM)[0] +#define Mat2d01 ((Standard_Real*)aM)[1] +#define Mat2d10 ((Standard_Real*)aM)[2] +#define Mat2d11 ((Standard_Real*)aM)[3] +#define Nat2d00 ((Standard_Real*)aN)[0] +#define Nat2d01 ((Standard_Real*)aN)[1] +#define Nat2d10 ((Standard_Real*)aN)[2] +#define Nat2d11 ((Standard_Real*)aN)[3] + +#define Oat2d00 ((Standard_Real*)anO)[0] +#define Oat2d01 ((Standard_Real*)anO)[1] +#define Oat2d10 ((Standard_Real*)anO)[2] +#define Oat2d11 ((Standard_Real*)anO)[3] //! Describes a two column, two row matrix. This sort of //! object is used in various vectorial or matrix computations. @@ -38,227 +46,437 @@ public: DEFINE_STANDARD_ALLOC - //! Creates a matrix with null coefficients. - gp_Mat2d(); - + gp_Mat2d() + { + const Standard_Address aM = (Standard_Address)&(matrix[0][0]); + Mat2d00 = Mat2d01 = Mat2d10 = Mat2d11 = 0.0; + } - //! Col1, Col2 are the 2 columns of the matrix. - Standard_EXPORT gp_Mat2d(const gp_XY& Col1, const gp_XY& Col2); - - //! Assigns the two coordinates of Value to the column of range - //! Col of this matrix - //! Raises OutOfRange if Col < 1 or Col > 2. - Standard_EXPORT void SetCol (const Standard_Integer Col, const gp_XY& Value); - - //! Assigns the number pairs Col1, Col2 to the two columns of this matrix - Standard_EXPORT void SetCols (const gp_XY& Col1, const gp_XY& Col2); - + //! theCol1, theCol2 are the 2 columns of the matrix. + Standard_EXPORT gp_Mat2d (const gp_XY& theCol1, const gp_XY& theCol2); + + //! Assigns the two coordinates of theValue to the column of range + //! theCol of this matrix + //! Raises OutOfRange if theCol < 1 or theCol > 2. + Standard_EXPORT void SetCol (const Standard_Integer theCol, const gp_XY& theValue); + + //! Assigns the number pairs theCol1, theCol2 to the two columns of this matrix + Standard_EXPORT void SetCols (const gp_XY& theCol1, const gp_XY& theCol2); //! Modifies the main diagonal of the matrix. //! @code - //! .Value (1, 1) = X1 - //! .Value (2, 2) = X2 + //! .Value (1, 1) = theX1 + //! .Value (2, 2) = theX2 //! @endcode //! The other coefficients of the matrix are not modified. - void SetDiagonal (const Standard_Real X1, const Standard_Real X2); - - //! Modifies this matrix, so that it represents the Identity matrix. - void SetIdentity(); - + void SetDiagonal (const Standard_Real theX1, const Standard_Real theX2) + { + const Standard_Address aM = (Standard_Address)&(matrix[0][0]); + Mat2d00 = theX1; + Mat2d11 = theX2; + } - //! Modifies this matrix, so that it represents a rotation. Ang is the angular + //! Modifies this matrix, so that it represents the Identity matrix. + void SetIdentity() + { + const Standard_Address aM = (Standard_Address)&(matrix[0][0]); + Mat2d00 = Mat2d11 = 1.0; + Mat2d01 = Mat2d10 = 0.0; + } + + //! Modifies this matrix, so that it represents a rotation. theAng is the angular //! value in radian of the rotation. - void SetRotation (const Standard_Real Ang); - - //! Assigns the two coordinates of Value to the row of index Row of this matrix. - //! Raises OutOfRange if Row < 1 or Row > 2. - Standard_EXPORT void SetRow (const Standard_Integer Row, const gp_XY& Value); - - //! Assigns the number pairs Row1, Row2 to the two rows of this matrix. - Standard_EXPORT void SetRows (const gp_XY& Row1, const gp_XY& Row2); - + void SetRotation (const Standard_Real theAng); + + //! Assigns the two coordinates of theValue to the row of index theRow of this matrix. + //! Raises OutOfRange if theRow < 1 or theRow > 2. + Standard_EXPORT void SetRow (const Standard_Integer theRow, const gp_XY& theValue); + + //! Assigns the number pairs theRow1, theRow2 to the two rows of this matrix. + Standard_EXPORT void SetRows (const gp_XY& theRow1, const gp_XY& theRow2); //! Modifies the matrix such that it - //! represents a scaling transformation, where S is the scale factor : + //! represents a scaling transformation, where theS is the scale factor : //! @code - //! | S 0.0 | - //! = | 0.0 S | + //! | theS 0.0 | + //! = | 0.0 theS | //! @endcode - void SetScale (const Standard_Real S); - - //! Assigns to the coefficient of row Row, column Col of this matrix. - //! Raises OutOfRange if Row < 1 or Row > 2 or Col < 1 or Col > 2 - void SetValue (const Standard_Integer Row, const Standard_Integer Col, const Standard_Real Value); - - //! Returns the column of Col index. - //! Raises OutOfRange if Col < 1 or Col > 2 - Standard_EXPORT gp_XY Column (const Standard_Integer Col) const; - + void SetScale (const Standard_Real theS) + { + const Standard_Address aM = (Standard_Address)&(matrix[0][0]); + Mat2d00 = Mat2d11 = theS; + Mat2d01 = Mat2d10 = 0.0; + } + + //! Assigns to the coefficient of row theRow, column theCol of this matrix. + //! Raises OutOfRange if theRow < 1 or theRow > 2 or theCol < 1 or theCol > 2 + void SetValue (const Standard_Integer theRow, const Standard_Integer theCol, const Standard_Real theValue) + { + Standard_OutOfRange_Raise_if (theRow < 1 || theRow > 2 || theCol < 1 || theCol > 2, " "); + matrix[theRow - 1][theCol - 1] = theValue; + } + + //! Returns the column of theCol index. + //! Raises OutOfRange if theCol < 1 or theCol > 2 + Standard_EXPORT gp_XY Column (const Standard_Integer theCol) const; + //! Computes the determinant of the matrix. - Standard_Real Determinant() const; - + Standard_Real Determinant() const + { + const Standard_Address aM = (Standard_Address)&(matrix[0][0]); + return Mat2d00 * Mat2d11 - Mat2d10 * Mat2d01; + } + //! Returns the main diagonal of the matrix. Standard_EXPORT gp_XY Diagonal() const; - - //! Returns the row of index Row. - //! Raised if Row < 1 or Row > 2 - Standard_EXPORT gp_XY Row (const Standard_Integer Row) const; - - //! Returns the coefficient of range (Row, Col) + + //! Returns the row of index theRow. + //! Raised if theRow < 1 or theRow > 2 + Standard_EXPORT gp_XY Row (const Standard_Integer theRow) const; + + //! Returns the coefficient of range (ttheheRow, theCol) //! Raises OutOfRange - //! if Row < 1 or Row > 2 or Col < 1 or Col > 2 - const Standard_Real& Value (const Standard_Integer Row, const Standard_Integer Col) const; - const Standard_Real& operator() (const Standard_Integer Row, const Standard_Integer Col) const -{ - return Value(Row,Col); -} - - //! Returns the coefficient of range (Row, Col) + //! if theRow < 1 or theRow > 2 or theCol < 1 or theCol > 2 + const Standard_Real& Value (const Standard_Integer theRow, const Standard_Integer theCol) const + { + Standard_OutOfRange_Raise_if (theRow < 1 || theRow > 2 || theCol < 1 || theCol > 2, " "); + return matrix[theRow - 1][theCol - 1]; + } + + const Standard_Real& operator() (const Standard_Integer theRow, const Standard_Integer theCol) const { return Value (theRow, theCol); } + + //! Returns the coefficient of range (theRow, theCol) //! Raises OutOfRange - //! if Row < 1 or Row > 2 or Col < 1 or Col > 2 - Standard_Real& ChangeValue (const Standard_Integer Row, const Standard_Integer Col); - Standard_Real& operator() (const Standard_Integer Row, const Standard_Integer Col) -{ - return ChangeValue(Row,Col); -} - + //! if theRow < 1 or theRow > 2 or theCol < 1 or theCol > 2 + Standard_Real& ChangeValue (const Standard_Integer theRow, const Standard_Integer theCol) + { + Standard_OutOfRange_Raise_if (theRow < 1 || theRow > 2 || theCol < 1 || theCol > 2, " "); + return matrix[theRow - 1][theCol - 1]; + } + + Standard_Real& operator() (const Standard_Integer theRow, const Standard_Integer theCol) { return ChangeValue (theRow, theCol); } //! Returns true if this matrix is singular (and therefore, cannot be inverted). //! The Gauss LU decomposition is used to invert the matrix //! so the matrix is considered as singular if the largest //! pivot found is lower or equal to Resolution from gp. - Standard_Boolean IsSingular() const; - - void Add (const gp_Mat2d& Other); - void operator += (const gp_Mat2d& Other) -{ - Add(Other); -} - + Standard_Boolean IsSingular() const + { + Standard_Real aDet = Determinant(); + if (aDet < 0) + { + aDet = -aDet; + } + return aDet <= gp::Resolution(); + } + + void Add (const gp_Mat2d& Other); + + void operator += (const gp_Mat2d& theOther) { Add (theOther); } //! Computes the sum of this matrix and the matrix - //! Other.for each coefficient of the matrix : + //! theOther.for each coefficient of the matrix : //! @code - //! .Coef(i,j) + .Coef(i,j) + //! .Coef(i,j) + .Coef(i,j) //! @endcode //! Note: //! - operator += assigns the result to this matrix, while //! - operator + creates a new one. - Standard_NODISCARD gp_Mat2d Added (const gp_Mat2d& Other) const; - Standard_NODISCARD gp_Mat2d operator + (const gp_Mat2d& Other) const -{ - return Added(Other); -} - - void Divide (const Standard_Real Scalar); - void operator /= (const Standard_Real Scalar) -{ - Divide(Scalar); -} - + Standard_NODISCARD gp_Mat2d Added (const gp_Mat2d& theOther) const; + + Standard_NODISCARD gp_Mat2d operator + (const gp_Mat2d& theOther) const { return Added (theOther); } + + void Divide (const Standard_Real theScalar); + + void operator /= (const Standard_Real theScalar) { Divide (theScalar); } //! Divides all the coefficients of the matrix by a scalar. - Standard_NODISCARD gp_Mat2d Divided (const Standard_Real Scalar) const; - Standard_NODISCARD gp_Mat2d operator / (const Standard_Real Scalar) const -{ - return Divided(Scalar); -} - + Standard_NODISCARD gp_Mat2d Divided (const Standard_Real theScalar) const; + + Standard_NODISCARD gp_Mat2d operator / (const Standard_Real theScalar) const { return Divided (theScalar); } + Standard_EXPORT void Invert(); - //! Inverses the matrix and raises exception if the matrix //! is singular. - Standard_NODISCARD gp_Mat2d Inverted() const; - - Standard_NODISCARD gp_Mat2d Multiplied (const gp_Mat2d& Other) const; - Standard_NODISCARD gp_Mat2d operator * (const gp_Mat2d& Other) const -{ - return Multiplied(Other); -} - + Standard_NODISCARD gp_Mat2d Inverted() const + { + gp_Mat2d aNewMat = *this; + aNewMat.Invert(); + return aNewMat; + } + + Standard_NODISCARD gp_Mat2d Multiplied (const gp_Mat2d& theOther) const + { + gp_Mat2d aNewMat2d = *this; + aNewMat2d.Multiply (theOther); + return aNewMat2d; + } + + Standard_NODISCARD gp_Mat2d operator * (const gp_Mat2d& theOther) const { return Multiplied (theOther); } + + //! Computes the product of two matrices * + void Multiply (const gp_Mat2d& theOther); - //! Computes the product of two matrices * - void Multiply (const gp_Mat2d& Other); - //! Modifies this matrix by premultiplying it by the matrix Other - //! = Other * . - void PreMultiply (const gp_Mat2d& Other); - - Standard_NODISCARD gp_Mat2d Multiplied (const Standard_Real Scalar) const; - Standard_NODISCARD gp_Mat2d operator * (const Standard_Real Scalar) const -{ - return Multiplied(Scalar); -} - + //! = theOther * . + void PreMultiply (const gp_Mat2d& theOther); + + Standard_NODISCARD gp_Mat2d Multiplied (const Standard_Real theScalar) const; + + Standard_NODISCARD gp_Mat2d operator * (const Standard_Real theScalar) const { return Multiplied (theScalar); } //! Multiplies all the coefficients of the matrix by a scalar. - void Multiply (const Standard_Real Scalar); - void operator *= (const Standard_Real Scalar) -{ - Multiply(Scalar); -} - - Standard_EXPORT void Power (const Standard_Integer N); - + void Multiply (const Standard_Real theScalar); - //! computes = * * .......* , N time. - //! if N = 0 = Identity - //! if N < 0 = .Invert() *...........* .Invert(). - //! If N < 0 an exception can be raised if the matrix is not + void operator *= (const Standard_Real theScalar) { Multiply (theScalar); } + + Standard_EXPORT void Power (const Standard_Integer theN); + + //! computes = * * .......* , theN time. + //! if theN = 0 = Identity + //! if theN < 0 = .Invert() *...........* .Invert(). + //! If theN < 0 an exception can be raised if the matrix is not //! inversible - Standard_NODISCARD gp_Mat2d Powered (const Standard_Integer N) const; - - void Subtract (const gp_Mat2d& Other); - void operator -= (const gp_Mat2d& Other) -{ - Subtract(Other); -} - + Standard_NODISCARD gp_Mat2d Powered (const Standard_Integer theN) const + { + gp_Mat2d aMat2dN = *this; + aMat2dN.Power (theN); + return aMat2dN; + } + + void Subtract (const gp_Mat2d& theOther); + + void operator -= (const gp_Mat2d& theOther) { Subtract (theOther); } //! Computes for each coefficient of the matrix : //! @code - //! .Coef(i,j) - .Coef(i,j) + //! .Coef(i,j) - .Coef(i,j) //! @endcode - Standard_NODISCARD gp_Mat2d Subtracted (const gp_Mat2d& Other) const; - Standard_NODISCARD gp_Mat2d operator - (const gp_Mat2d& Other) const -{ - return Subtracted(Other); -} - - void Transpose(); - + Standard_NODISCARD gp_Mat2d Subtracted (const gp_Mat2d& theOther) const; + + Standard_NODISCARD gp_Mat2d operator - (const gp_Mat2d& theOther) const { return Subtracted (theOther); } + + void Transpose(); //! Transposes the matrix. A(j, i) -> A (i, j) - Standard_NODISCARD gp_Mat2d Transposed() const; - + Standard_NODISCARD gp_Mat2d Transposed() const; friend class gp_Trsf2d; friend class gp_GTrsf2d; friend class gp_XY; - -protected: - - - - - private: - - Standard_Real matrix[2][2]; - }; +//======================================================================= +//function : SetRotation +// purpose : +//======================================================================= +inline void gp_Mat2d::SetRotation (const Standard_Real theAng) +{ + const Standard_Address aM = (Standard_Address)&(matrix[0][0]); + Standard_Real aSinA = sin (theAng); + Standard_Real aCosA = cos (theAng); + Mat2d00 = Mat2d11 = aCosA; + Mat2d01 = -aSinA; + Mat2d10 = aSinA; +} -#include +//======================================================================= +//function : Add +// purpose : +//======================================================================= +inline void gp_Mat2d::Add (const gp_Mat2d& theOther) +{ + const Standard_Address aM = (Standard_Address)&(matrix[0][0]); + const Standard_Address anO = (Standard_Address)&(theOther.matrix[0][0]); + Mat2d00 += Oat2d00; + Mat2d01 += Oat2d01; + Mat2d10 += Oat2d10; + Mat2d11 += Oat2d11; +} +//======================================================================= +//function : Added +// purpose : +//======================================================================= +inline gp_Mat2d gp_Mat2d::Added (const gp_Mat2d& theOther) const +{ + gp_Mat2d aNewMat2d; + const Standard_Address aM = (Standard_Address)&(matrix[0][0]); + const Standard_Address aN = (Standard_Address)&(aNewMat2d.matrix[0][0]); + const Standard_Address anO = (Standard_Address)&(theOther .matrix[0][0]); + Nat2d00 = Mat2d00 + Oat2d00; + Nat2d01 = Mat2d01 + Oat2d01; + Nat2d10 = Mat2d10 + Oat2d10; + Nat2d11 = Mat2d11 + Oat2d11; + return aNewMat2d; +} +//======================================================================= +//function : Divide +// purpose : +//======================================================================= +inline void gp_Mat2d::Divide (const Standard_Real theScalar) +{ + const Standard_Address aM = (Standard_Address)&(matrix[0][0]); + Mat2d00 /= theScalar; + Mat2d01 /= theScalar; + Mat2d10 /= theScalar; + Mat2d11 /= theScalar; +} +//======================================================================= +//function : Divided +// purpose : +//======================================================================= +inline gp_Mat2d gp_Mat2d::Divided (const Standard_Real theScalar) const +{ + gp_Mat2d aNewMat2d; + const Standard_Address aM = (Standard_Address)&(matrix[0][0]); + const Standard_Address aN = (Standard_Address)&(aNewMat2d.matrix[0][0]); + Nat2d00 = Mat2d00 / theScalar; + Nat2d01 = Mat2d01 / theScalar; + Nat2d10 = Mat2d10 / theScalar; + Nat2d11 = Mat2d11 / theScalar; + return aNewMat2d; +} +//======================================================================= +//function : Multiply +// purpose : +//======================================================================= +inline void gp_Mat2d::Multiply (const gp_Mat2d& theOther) +{ + Standard_Real aT00, aT10; + const Standard_Address aM = (Standard_Address)&(matrix[0][0]); + const Standard_Address anO = (Standard_Address)&(theOther.matrix[0][0]); + aT00 = Mat2d00 * Oat2d00 + Mat2d01 * Oat2d10; + aT10 = Mat2d10 * Oat2d00 + Mat2d11 * Oat2d10; + Mat2d01 = Mat2d00 * Oat2d01 + Mat2d01 * Oat2d11; + Mat2d11 = Mat2d10 * Oat2d01 + Mat2d11 * Oat2d11; + Mat2d00 = aT00; + Mat2d10 = aT10; +} + +//======================================================================= +//function : PreMultiply +// purpose : +//======================================================================= +inline void gp_Mat2d::PreMultiply (const gp_Mat2d& theOther) +{ + Standard_Real aT00, aT01; + const Standard_Address aM = (Standard_Address)&(matrix[0][0]); + const Standard_Address anO = (Standard_Address)&(theOther.matrix[0][0]); + aT00 = Oat2d00 * Mat2d00 + Oat2d01 * Mat2d10; + Mat2d10 = Oat2d10 * Mat2d00 + Oat2d11 * Mat2d10; + aT01 = Oat2d00 * Mat2d01 + Oat2d01 * Mat2d11; + Mat2d11 = Oat2d10 * Mat2d01 + Oat2d11 * Mat2d11; + Mat2d00 = aT00; + Mat2d01 = aT01; +} + +//======================================================================= +//function : Multiplied +// purpose : +//======================================================================= +inline gp_Mat2d gp_Mat2d::Multiplied (const Standard_Real theScalar) const +{ + gp_Mat2d aNewMat2d; + const Standard_Address aM = (Standard_Address)&(matrix[0][0]); + const Standard_Address aN = (Standard_Address)&(aNewMat2d.matrix[0][0]); + Nat2d00 = Mat2d00 * theScalar; + Nat2d01 = Mat2d01 * theScalar; + Nat2d10 = Mat2d10 * theScalar; + Nat2d11 = Mat2d11 * theScalar; + return aNewMat2d; +} + +//======================================================================= +//function : Multiply +// purpose : +//======================================================================= +inline void gp_Mat2d::Multiply (const Standard_Real theScalar) +{ + const Standard_Address aM = (Standard_Address)&(matrix[0][0]); + Mat2d00 *= theScalar; + Mat2d01 *= theScalar; + Mat2d10 *= theScalar; + Mat2d11 *= theScalar; +} + +//======================================================================= +//function : Subtract +// purpose : +//======================================================================= +inline void gp_Mat2d::Subtract (const gp_Mat2d& theOther) +{ + const Standard_Address aM = (Standard_Address)&(matrix[0][0]); + const Standard_Address anO = (Standard_Address)&(theOther.matrix[0][0]); + Mat2d00 -= Oat2d00; + Mat2d01 -= Oat2d01; + Mat2d10 -= Oat2d10; + Mat2d11 -= Oat2d11; +} + +//======================================================================= +//function : Subtracted +// purpose : +//======================================================================= +inline gp_Mat2d gp_Mat2d::Subtracted (const gp_Mat2d& theOther) const +{ + gp_Mat2d aNewMat2d; + const Standard_Address aM = (Standard_Address)&(matrix[0][0]); + const Standard_Address aN = (Standard_Address)&(aNewMat2d.matrix[0][0]); + const Standard_Address anO = (Standard_Address)&(theOther.matrix[0][0]); + Nat2d00 = Mat2d00 - Oat2d00; + Nat2d01 = Mat2d01 - Oat2d01; + Nat2d10 = Mat2d10 - Oat2d10; + Nat2d11 = Mat2d11 - Oat2d11; + return aNewMat2d; +} + +//======================================================================= +//function : Transpose +// purpose : +//======================================================================= +inline void gp_Mat2d::Transpose() +{ + const Standard_Address aM = (Standard_Address)&(matrix[0][0]); + Standard_Real aTemp; + aTemp = Mat2d01; + Mat2d01 = Mat2d10; + Mat2d10 = aTemp; +} + +//======================================================================= +//function : Transposed +// purpose : +//======================================================================= +inline gp_Mat2d gp_Mat2d::Transposed() const +{ + gp_Mat2d aNewMat2d; + const Standard_Address aM = (Standard_Address)&(matrix[0][0]); + const Standard_Address aN = (Standard_Address)&(aNewMat2d.matrix[0][0]); + Nat2d10 = Mat2d01; + Nat2d01 = Mat2d10; + Nat2d00 = Mat2d00; + Nat2d11 = Mat2d11; + return aNewMat2d; +} + +//======================================================================= +//function : operator* +// purpose : +//======================================================================= +inline gp_Mat2d operator* (const Standard_Real theScalar, const gp_Mat2d& theMat2D) +{ + return theMat2D.Multiplied (theScalar); +} #endif // _gp_Mat2d_HeaderFile diff --git a/src/gp/gp_Mat2d.lxx b/src/gp/gp_Mat2d.lxx deleted file mode 100644 index add7bef410..0000000000 --- a/src/gp/gp_Mat2d.lxx +++ /dev/null @@ -1,268 +0,0 @@ -// Copyright (c) 1995-1999 Matra Datavision -// Copyright (c) 1999-2014 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -#include -#include - -#define Mat2d00 ((Standard_Real*)M)[0] -#define Mat2d01 ((Standard_Real*)M)[1] -#define Mat2d10 ((Standard_Real*)M)[2] -#define Mat2d11 ((Standard_Real*)M)[3] - -#define Nat2d00 ((Standard_Real*)N)[0] -#define Nat2d01 ((Standard_Real*)N)[1] -#define Nat2d10 ((Standard_Real*)N)[2] -#define Nat2d11 ((Standard_Real*)N)[3] - -#define Oat2d00 ((Standard_Real*)O)[0] -#define Oat2d01 ((Standard_Real*)O)[1] -#define Oat2d10 ((Standard_Real*)O)[2] -#define Oat2d11 ((Standard_Real*)O)[3] - -inline gp_Mat2d::gp_Mat2d () -{ - const Standard_Address M = (Standard_Address)&(matrix[0][0]); - Mat2d00 = Mat2d01 = Mat2d10 = Mat2d11 = 0.0; -} - -inline void gp_Mat2d::SetDiagonal (const Standard_Real X1, - const Standard_Real X2) -{ - const Standard_Address M = (Standard_Address)&(matrix[0][0]); - Mat2d00 = X1; Mat2d11 = X2; -} - -inline void gp_Mat2d::SetIdentity () -{ - const Standard_Address M = (Standard_Address)&(matrix[0][0]); - Mat2d00 = Mat2d11 = 1.0; - Mat2d01 = Mat2d10 = 0.0; -} - -inline void gp_Mat2d::SetRotation (const Standard_Real Ang) -{ - const Standard_Address M = (Standard_Address)&(matrix[0][0]); - Standard_Real SinA = sin(Ang); - Standard_Real CosA = cos(Ang); - Mat2d00 = Mat2d11 = CosA; - Mat2d01 = -SinA; - Mat2d10 = SinA; -} - -inline void gp_Mat2d::SetScale (const Standard_Real S) -{ - const Standard_Address M = (Standard_Address)&(matrix[0][0]); - Mat2d00 = Mat2d11 = S; - Mat2d01 = Mat2d10 = 0.0; -} - -inline void gp_Mat2d::SetValue (const Standard_Integer Row, - const Standard_Integer Col, - const Standard_Real Value) -{ - Standard_OutOfRange_Raise_if - (Row < 1 || Row > 2 || Col < 1 || Col > 2, " "); - matrix[Row-1][Col-1] = Value; -} - -inline Standard_Real gp_Mat2d::Determinant () const -{ - const Standard_Address M = (Standard_Address)&(matrix[0][0]); - return Mat2d00 * Mat2d11 - Mat2d10 * Mat2d01; -} - -inline const Standard_Real& gp_Mat2d::Value (const Standard_Integer Row, - const Standard_Integer Col) const -{ - Standard_OutOfRange_Raise_if - (Row < 1 || Row > 2 || Col < 1 || Col > 2, " "); - return matrix[Row-1][Col-1]; -} - -inline Standard_Real& -gp_Mat2d::ChangeValue (const Standard_Integer Row, - const Standard_Integer Col) -{ - Standard_OutOfRange_Raise_if - (Row < 1 || Row > 2 || Col < 1 || Col > 2, " "); - return matrix[Row-1][Col-1]; -} - -inline Standard_Boolean gp_Mat2d::IsSingular () const -{ - Standard_Real det = Determinant(); - if (det < 0) det = - det; - return det <= gp::Resolution(); -} - -inline void gp_Mat2d::Add (const gp_Mat2d& Other) -{ - const Standard_Address M = (Standard_Address)&( matrix[0][0]); - const Standard_Address O = (Standard_Address)&(Other.matrix[0][0]); - Mat2d00 += Oat2d00; - Mat2d01 += Oat2d01; - Mat2d10 += Oat2d10; - Mat2d11 += Oat2d11; -} - -inline gp_Mat2d gp_Mat2d::Added (const gp_Mat2d& Other) const -{ - gp_Mat2d NewMat2d; - const Standard_Address M = (Standard_Address)&( matrix[0][0]); - const Standard_Address N = (Standard_Address)&(NewMat2d.matrix[0][0]); - const Standard_Address O = (Standard_Address)&(Other .matrix[0][0]); - Nat2d00 = Mat2d00 + Oat2d00; - Nat2d01 = Mat2d01 + Oat2d01; - Nat2d10 = Mat2d10 + Oat2d10; - Nat2d11 = Mat2d11 + Oat2d11; - return NewMat2d; -} - -inline void gp_Mat2d::Divide (const Standard_Real Scalar) -{ - const Standard_Address M = (Standard_Address)&(matrix[0][0]); - Mat2d00 /= Scalar; - Mat2d01 /= Scalar; - Mat2d10 /= Scalar; - Mat2d11 /= Scalar; -} - -inline gp_Mat2d gp_Mat2d::Divided (const Standard_Real Scalar) const -{ - gp_Mat2d NewMat2d; - const Standard_Address M = (Standard_Address)&( matrix[0][0]); - const Standard_Address N = (Standard_Address)&(NewMat2d.matrix[0][0]); - Nat2d00 = Mat2d00 / Scalar; - Nat2d01 = Mat2d01 / Scalar; - Nat2d10 = Mat2d10 / Scalar; - Nat2d11 = Mat2d11 / Scalar; - return NewMat2d; -} - -inline gp_Mat2d gp_Mat2d::Inverted () const -{ - gp_Mat2d NewMat = *this; - NewMat.Invert(); - return NewMat; -} - -inline gp_Mat2d gp_Mat2d::Multiplied (const gp_Mat2d& Other) const -{ - gp_Mat2d NewMat2d = *this; - NewMat2d.Multiply(Other); - return NewMat2d; -} - -inline void gp_Mat2d::Multiply (const gp_Mat2d& Other) -{ - Standard_Real T00,T10; - const Standard_Address M = (Standard_Address)&( matrix[0][0]); - const Standard_Address O = (Standard_Address)&(Other.matrix[0][0]); - T00 = Mat2d00 * Oat2d00 + Mat2d01 * Oat2d10; - T10 = Mat2d10 * Oat2d00 + Mat2d11 * Oat2d10; - Mat2d01 = Mat2d00 * Oat2d01 + Mat2d01 * Oat2d11; - Mat2d11 = Mat2d10 * Oat2d01 + Mat2d11 * Oat2d11; - Mat2d00 = T00; - Mat2d10 = T10; -} - -inline void gp_Mat2d::PreMultiply (const gp_Mat2d& Other) -{ - Standard_Real T00,T01; - const Standard_Address M = (Standard_Address)&( matrix[0][0]); - const Standard_Address O = (Standard_Address)&(Other.matrix[0][0]); - T00 = Oat2d00 * Mat2d00 + Oat2d01 * Mat2d10; - Mat2d10 = Oat2d10 * Mat2d00 + Oat2d11 * Mat2d10; - T01 = Oat2d00 * Mat2d01 + Oat2d01 * Mat2d11; - Mat2d11 = Oat2d10 * Mat2d01 + Oat2d11 * Mat2d11; - Mat2d00 = T00; - Mat2d01 = T01; -} - -inline gp_Mat2d gp_Mat2d::Multiplied (const Standard_Real Scalar) const -{ - gp_Mat2d NewMat2d; - const Standard_Address M = (Standard_Address)&( matrix[0][0]); - const Standard_Address N = (Standard_Address)&(NewMat2d.matrix[0][0]); - Nat2d00 = Mat2d00 * Scalar; - Nat2d01 = Mat2d01 * Scalar; - Nat2d10 = Mat2d10 * Scalar; - Nat2d11 = Mat2d11 * Scalar; - return NewMat2d; -} - -inline void gp_Mat2d::Multiply (const Standard_Real Scalar) -{ - const Standard_Address M = (Standard_Address)&(matrix[0][0]); - Mat2d00 *= Scalar; - Mat2d01 *= Scalar; - Mat2d10 *= Scalar; - Mat2d11 *= Scalar; -} - -inline gp_Mat2d gp_Mat2d::Powered (const Standard_Integer N) const -{ - gp_Mat2d Mat2dN = *this; - Mat2dN.Power (N); - return Mat2dN; -} - -inline void gp_Mat2d::Subtract (const gp_Mat2d& Other) -{ - const Standard_Address M = (Standard_Address)&( matrix[0][0]); - const Standard_Address O = (Standard_Address)&(Other.matrix[0][0]); - Mat2d00 -= Oat2d00; - Mat2d01 -= Oat2d01; - Mat2d10 -= Oat2d10; - Mat2d11 -= Oat2d11; -} - -inline gp_Mat2d gp_Mat2d::Subtracted (const gp_Mat2d& Other) const -{ - gp_Mat2d NewMat2d; - const Standard_Address M = (Standard_Address)&( matrix[0][0]); - const Standard_Address N = (Standard_Address)&(NewMat2d.matrix[0][0]); - const Standard_Address O = (Standard_Address)&(Other .matrix[0][0]); - Nat2d00 = Mat2d00 - Oat2d00; - Nat2d01 = Mat2d01 - Oat2d01; - Nat2d10 = Mat2d10 - Oat2d10; - Nat2d11 = Mat2d11 - Oat2d11; - return NewMat2d; -} - -inline void gp_Mat2d::Transpose () -{ - const Standard_Address M = (Standard_Address)&(matrix[0][0]); - Standard_Real Temp; - Temp = Mat2d01; - Mat2d01 = Mat2d10; - Mat2d10 = Temp; -} - -inline gp_Mat2d gp_Mat2d::Transposed () const -{ - gp_Mat2d NewMat2d; - const Standard_Address M = (Standard_Address)&( matrix[0][0]); - const Standard_Address N = (Standard_Address)&(NewMat2d.matrix[0][0]); - Nat2d10 = Mat2d01; - Nat2d01 = Mat2d10; - Nat2d00 = Mat2d00; - Nat2d11 = Mat2d11; - return NewMat2d; -} - -inline gp_Mat2d operator* (const Standard_Real Scalar, - const gp_Mat2d& Mat2D) -{ return Mat2D.Multiplied (Scalar); } - diff --git a/src/gp/gp_Parab.cxx b/src/gp/gp_Parab.cxx index 1ab073e09d..0882d8aff1 100644 --- a/src/gp/gp_Parab.cxx +++ b/src/gp/gp_Parab.cxx @@ -14,9 +14,10 @@ // Modif jcv 14/12/90 suite a la premiere revue de projet +#include + #include #include -#include #include #include #include diff --git a/src/gp/gp_Parab.hxx b/src/gp/gp_Parab.hxx index 120697c99d..2bb548a520 100644 --- a/src/gp/gp_Parab.hxx +++ b/src/gp/gp_Parab.hxx @@ -15,22 +15,11 @@ #ifndef _gp_Parab_HeaderFile #define _gp_Parab_HeaderFile -#include -#include -#include - -#include -#include #include +#include +#include #include -class Standard_ConstructionError; -class gp_Ax2; -class gp_Ax1; -class gp_Pnt; -class gp_Trsf; -class gp_Vec; - - +#include //! Describes a parabola in 3D space. //! A parabola is defined by its focal length (that is, the @@ -65,58 +54,64 @@ public: DEFINE_STANDARD_ALLOC - //! Creates an indefinite Parabola. - gp_Parab(); - + gp_Parab() + : focalLength (RealLast()) + {} - //! Creates a parabola with its local coordinate system "A2" + //! Creates a parabola with its local coordinate system "theA2" //! and it's focal length "Focal". - //! The XDirection of A2 defines the axis of symmetry of the - //! parabola. The YDirection of A2 is parallel to the directrix - //! of the parabola. The Location point of A2 is the vertex of + //! The XDirection of theA2 defines the axis of symmetry of the + //! parabola. The YDirection of theA2 is parallel to the directrix + //! of the parabola. The Location point of theA2 is the vertex of //! the parabola - //! Raises ConstructionError if Focal < 0.0 - //! Raised if Focal < 0.0 - gp_Parab(const gp_Ax2& A2, const Standard_Real Focal); - + //! Raises ConstructionError if theFocal < 0.0 + //! Raised if theFocal < 0.0 + gp_Parab (const gp_Ax2& theA2, const Standard_Real theFocal) + : pos (theA2), + focalLength (theFocal) + { + Standard_ConstructionError_Raise_if (theFocal < 0.0, "gp_Parab() - focal length should be >= 0"); + } - //! D is the directrix of the parabola and F the focus point. + //! theD is the directrix of the parabola and theF the focus point. //! The symmetry axis (XAxis) of the parabola is normal to the - //! directrix and pass through the focus point F, but its + //! directrix and pass through the focus point theF, but its //! location point is the vertex of the parabola. - //! The YAxis of the parabola is parallel to D and its location + //! The YAxis of the parabola is parallel to theD and its location //! point is the vertex of the parabola. The normal to the plane //! of the parabola is the cross product between the XAxis and the //! YAxis. - gp_Parab(const gp_Ax1& D, const gp_Pnt& F); - + gp_Parab (const gp_Ax1& theD, const gp_Pnt& theF); + //! Modifies this parabola by redefining its local coordinate system so that //! - its origin and "main Direction" become those of the - //! axis A1 (the "X Direction" and "Y Direction" are then + //! axis theA1 (the "X Direction" and "Y Direction" are then //! recomputed in the same way as for any gp_Ax2) - //! Raises ConstructionError if the direction of A1 is parallel to the previous + //! Raises ConstructionError if the direction of theA1 is parallel to the previous //! XAxis of the parabola. - void SetAxis (const gp_Ax1& A1); - + void SetAxis (const gp_Ax1& theA1) { pos.SetAxis (theA1); } + //! Changes the focal distance of the parabola. - //! Raises ConstructionError if Focal < 0.0 - void SetFocal (const Standard_Real Focal); - + //! Raises ConstructionError if theFocal < 0.0 + void SetFocal (const Standard_Real theFocal) + { + Standard_ConstructionError_Raise_if (theFocal < 0.0, "gp_Parab::SetFocal() - focal length should be >= 0"); + focalLength = theFocal; + } //! Changes the location of the parabola. It is the vertex of //! the parabola. - void SetLocation (const gp_Pnt& P); - + void SetLocation (const gp_Pnt& theP) { pos.SetLocation (theP); } + //! Changes the local coordinate system of the parabola. - void SetPosition (const gp_Ax2& A2); - + void SetPosition (const gp_Ax2& theA2) { pos = theA2; } //! Returns the main axis of the parabola. //! It is the axis normal to the plane of the parabola passing //! through the vertex of the parabola. - const gp_Ax1& Axis() const; - + const gp_Ax1& Axis() const { return pos.Axis(); } + //! Computes the directrix of this parabola. //! The directrix is: //! - a line parallel to the "Y Direction" of the local @@ -126,123 +121,211 @@ public: //! length of this parabola. //! The directrix is returned as an axis (a gp_Ax1 object), //! the origin of which is situated on the "X Axis" of this parabola. - gp_Ax1 Directrix() const; - + gp_Ax1 Directrix() const; //! Returns the distance between the vertex and the focus //! of the parabola. - Standard_Real Focal() const; - + Standard_Real Focal() const { return focalLength; } + //! - Computes the focus of the parabola. - gp_Pnt Focus() const; - + gp_Pnt Focus() const; //! Returns the vertex of the parabola. It is the "Location" //! point of the coordinate system of the parabola. - const gp_Pnt& Location() const; - + const gp_Pnt& Location() const { return pos.Location(); } //! Computes the parameter of the parabola. //! It is the distance between the focus and the directrix of //! the parabola. This distance is twice the focal length. - Standard_Real Parameter() const; - + Standard_Real Parameter() const { return 2.0 * focalLength; } //! Returns the local coordinate system of the parabola. - const gp_Ax2& Position() const; - + const gp_Ax2& Position() const { return pos; } //! Returns the symmetry axis of the parabola. The location point //! of the axis is the vertex of the parabola. - gp_Ax1 XAxis() const; - + gp_Ax1 XAxis() const { return gp_Ax1 (pos.Location(), pos.XDirection()); } //! It is an axis parallel to the directrix of the parabola. //! The location point of this axis is the vertex of the parabola. - gp_Ax1 YAxis() const; - - Standard_EXPORT void Mirror (const gp_Pnt& P); - + gp_Ax1 YAxis() const { return gp_Ax1 (pos.Location(), pos.YDirection()); } + + Standard_EXPORT void Mirror (const gp_Pnt& theP); //! Performs the symmetrical transformation of a parabola - //! with respect to the point P which is the center of the + //! with respect to the point theP which is the center of the //! symmetry. - Standard_NODISCARD Standard_EXPORT gp_Parab Mirrored (const gp_Pnt& P) const; - - Standard_EXPORT void Mirror (const gp_Ax1& A1); - + Standard_NODISCARD Standard_EXPORT gp_Parab Mirrored (const gp_Pnt& theP) const; + + Standard_EXPORT void Mirror (const gp_Ax1& theA1); //! Performs the symmetrical transformation of a parabola //! with respect to an axis placement which is the axis of //! the symmetry. - Standard_NODISCARD Standard_EXPORT gp_Parab Mirrored (const gp_Ax1& A1) const; - - Standard_EXPORT void Mirror (const gp_Ax2& A2); - + Standard_NODISCARD Standard_EXPORT gp_Parab Mirrored (const gp_Ax1& theA1) const; + + Standard_EXPORT void Mirror (const gp_Ax2& theA2); //! Performs the symmetrical transformation of a parabola - //! with respect to a plane. The axis placement A2 locates + //! with respect to a plane. The axis placement theA2 locates //! the plane of the symmetry (Location, XDirection, YDirection). - Standard_NODISCARD Standard_EXPORT gp_Parab Mirrored (const gp_Ax2& A2) const; - - void Rotate (const gp_Ax1& A1, const Standard_Real Ang); - + Standard_NODISCARD Standard_EXPORT gp_Parab Mirrored (const gp_Ax2& theA2) const; - //! Rotates a parabola. A1 is the axis of the rotation. + void Rotate (const gp_Ax1& theA1, const Standard_Real theAng) { pos.Rotate (theA1, theAng); } + + //! Rotates a parabola. theA1 is the axis of the rotation. //! Ang is the angular value of the rotation in radians. - Standard_NODISCARD gp_Parab Rotated (const gp_Ax1& A1, const Standard_Real Ang) const; - - void Scale (const gp_Pnt& P, const Standard_Real S); - + Standard_NODISCARD gp_Parab Rotated (const gp_Ax1& theA1, const Standard_Real theAng) const + { + gp_Parab aPrb = *this; + aPrb.pos.Rotate (theA1, theAng); + return aPrb; + } - //! Scales a parabola. S is the scaling value. - //! If S is negative the direction of the symmetry axis + void Scale (const gp_Pnt& theP, const Standard_Real theS); + + //! Scales a parabola. theS is the scaling value. + //! If theS is negative the direction of the symmetry axis //! XAxis is reversed and the direction of the YAxis too. - Standard_NODISCARD gp_Parab Scaled (const gp_Pnt& P, const Standard_Real S) const; - - void Transform (const gp_Trsf& T); - + Standard_NODISCARD gp_Parab Scaled (const gp_Pnt& theP, const Standard_Real theS) const; - //! Transforms a parabola with the transformation T from class Trsf. - Standard_NODISCARD gp_Parab Transformed (const gp_Trsf& T) const; - - void Translate (const gp_Vec& V); - + void Transform (const gp_Trsf& theT); - //! Translates a parabola in the direction of the vector V. + //! Transforms a parabola with the transformation theT from class Trsf. + Standard_NODISCARD gp_Parab Transformed (const gp_Trsf& theT) const; + + void Translate (const gp_Vec& theV) { pos.Translate (theV); } + + //! Translates a parabola in the direction of the vector theV. //! The magnitude of the translation is the vector's magnitude. - Standard_NODISCARD gp_Parab Translated (const gp_Vec& V) const; - - void Translate (const gp_Pnt& P1, const gp_Pnt& P2); - - - //! Translates a parabola from the point P1 to the point P2. - Standard_NODISCARD gp_Parab Translated (const gp_Pnt& P1, const gp_Pnt& P2) const; - - - - -protected: - - + Standard_NODISCARD gp_Parab Translated (const gp_Vec& theV) const + { + gp_Parab aPrb = *this; + aPrb.pos.Translate (theV); + return aPrb; + } + void Translate (const gp_Pnt& theP1, const gp_Pnt& theP2) { pos.Translate (theP1, theP2); } + //! Translates a parabola from the point theP1 to the point theP2. + Standard_NODISCARD gp_Parab Translated (const gp_Pnt& theP1, const gp_Pnt& theP2) const + { + gp_Parab aPrb = *this; + aPrb.pos.Translate (theP1, theP2); + return aPrb; + } private: - - gp_Ax2 pos; Standard_Real focalLength; - }; +//======================================================================= +//function : gp_Parab +// purpose : +//======================================================================= +inline gp_Parab::gp_Parab (const gp_Ax1& theD, + const gp_Pnt& theF) +{ + gp_Lin aDroite (theD); + focalLength = aDroite.Distance (theF) / 2.; + gp_Ax1 anAx = aDroite.Normal (theF).Position(); + gp_Ax1 anAy = aDroite.Position(); + const gp_Dir& aDD = anAx.Direction(); + pos = gp_Ax2 (gp_Pnt (theF.X() - focalLength * aDD.X(), + theF.Y() - focalLength * aDD.Y(), + theF.Z() - focalLength * aDD.Z()), + anAx.Direction().Crossed (anAy.Direction()), + anAx.Direction()); +} -#include +//======================================================================= +//function : Directrix +// purpose : +//======================================================================= +inline gp_Ax1 gp_Parab::Directrix() const +{ + const gp_Pnt& aPP = pos.Location (); + const gp_Dir& aDD = pos.XDirection(); + gp_Pnt aP (aPP.X() - focalLength * aDD.X(), + aPP.Y() - focalLength * aDD.Y(), + aPP.Z() - focalLength * aDD.Z()); + return gp_Ax1 (aP, pos.YDirection()); +} +//======================================================================= +//function : Focus +// purpose : +//======================================================================= +inline gp_Pnt gp_Parab::Focus() const +{ + const gp_Pnt& aPP = pos.Location (); + const gp_Dir& aDD = pos.XDirection(); + return gp_Pnt (aPP.X() + focalLength * aDD.X(), + aPP.Y() + focalLength * aDD.Y(), + aPP.Z() + focalLength * aDD.Z()); +} +//======================================================================= +//function : Scale +// purpose : +//======================================================================= +inline void gp_Parab::Scale (const gp_Pnt& theP, const Standard_Real theS) +{ + focalLength *= theS; + if (focalLength < 0) + { + focalLength = -focalLength; + } + pos.Scale (theP, theS); +} +//======================================================================= +//function : Scaled +// purpose : +//======================================================================= +inline gp_Parab gp_Parab::Scaled (const gp_Pnt& theP, const Standard_Real theS) const +{ + gp_Parab aPrb = *this; + aPrb.focalLength *= theS; + if (aPrb.focalLength < 0) + { + aPrb.focalLength = -aPrb.focalLength; + } + aPrb.pos.Scale (theP, theS); + return aPrb; +} +//======================================================================= +//function : Transform +// purpose : +//======================================================================= +inline void gp_Parab::Transform (const gp_Trsf& theT) +{ + focalLength *= theT.ScaleFactor(); + if (focalLength < 0) + { + focalLength = -focalLength; + } + pos.Transform (theT); +} + +//======================================================================= +//function : Transformed +// purpose : +//======================================================================= +inline gp_Parab gp_Parab::Transformed (const gp_Trsf& theT) const +{ + gp_Parab aPrb = *this; + aPrb.focalLength *= theT.ScaleFactor(); + if (aPrb.focalLength < 0) + { + aPrb.focalLength = -aPrb.focalLength; + } + aPrb.pos.Transform (theT); + return aPrb; +} #endif // _gp_Parab_HeaderFile diff --git a/src/gp/gp_Parab.lxx b/src/gp/gp_Parab.lxx deleted file mode 100644 index c944527f7f..0000000000 --- a/src/gp/gp_Parab.lxx +++ /dev/null @@ -1,167 +0,0 @@ -// Copyright (c) 1995-1999 Matra Datavision -// Copyright (c) 1999-2014 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -#include -#include - -inline gp_Parab::gp_Parab () : -focalLength (RealLast()) -{ } - -inline gp_Parab::gp_Parab (const gp_Ax2& A2, - const Standard_Real Focal) : - pos(A2), - focalLength (Focal) -{ - Standard_ConstructionError_Raise_if (Focal < 0.0, "gp_Parab() - focal length should be >= 0"); -} - -inline gp_Parab::gp_Parab (const gp_Ax1& D, - const gp_Pnt& F) -{ - gp_Lin Droite(D); - focalLength = Droite.Distance(F) / 2.; - gp_Ax1 Ax = Droite.Normal(F).Position(); - gp_Ax1 Ay = Droite.Position(); - const gp_Dir& DD = Ax.Direction(); - pos = gp_Ax2 (gp_Pnt(F.X() - focalLength * DD.X(), - F.Y() - focalLength * DD.Y(), - F.Z() - focalLength * DD.Z()), - Ax.Direction().Crossed(Ay.Direction()), - Ax.Direction()); -} - -inline void gp_Parab::SetAxis (const gp_Ax1& A1) -{ pos.SetAxis (A1); } - -inline void gp_Parab::SetFocal (const Standard_Real Focal) -{ - Standard_ConstructionError_Raise_if (Focal < 0.0, "gp_Parab::SetFocal() - focal length should be >= 0"); - focalLength = Focal; -} - -inline void gp_Parab::SetLocation (const gp_Pnt& P) -{ pos.SetLocation(P); } - -inline void gp_Parab::SetPosition (const gp_Ax2& A2) -{ pos = A2; } - -inline const gp_Ax1& gp_Parab::Axis () const -{ return pos.Axis(); } - -inline gp_Ax1 gp_Parab::Directrix() const -{ - const gp_Pnt& PP = pos.Location (); - const gp_Dir& DD = pos.XDirection(); - gp_Pnt P (PP.X() - focalLength * DD.X(), - PP.Y() - focalLength * DD.Y(), - PP.Z() - focalLength * DD.Z()); - return gp_Ax1 (P, pos.YDirection()); -} - -inline Standard_Real gp_Parab::Focal() const -{ return focalLength; } - -inline gp_Pnt gp_Parab::Focus() const -{ - const gp_Pnt& PP = pos.Location (); - const gp_Dir& DD = pos.XDirection(); - return gp_Pnt (PP.X() + focalLength * DD.X(), - PP.Y() + focalLength * DD.Y(), - PP.Z() + focalLength * DD.Z()); -} - -inline const gp_Pnt& gp_Parab::Location () const -{ return pos.Location(); } - -inline Standard_Real gp_Parab::Parameter() const -{ return 2.0 * focalLength; } - -inline const gp_Ax2& gp_Parab::Position() const -{ return pos; } - -inline gp_Ax1 gp_Parab::XAxis () const -{ return gp_Ax1 (pos.Location(), pos.XDirection()); } - -inline gp_Ax1 gp_Parab::YAxis () const -{ return gp_Ax1 (pos.Location(), pos.YDirection()); } - -inline void gp_Parab::Rotate (const gp_Ax1& A1, - const Standard_Real Ang) -{ pos.Rotate (A1, Ang); } - -inline gp_Parab gp_Parab::Rotated (const gp_Ax1& A1, - const Standard_Real Ang) const -{ - gp_Parab Prb = *this; - Prb.pos.Rotate (A1, Ang); - return Prb; -} - -inline void gp_Parab::Scale (const gp_Pnt& P, - const Standard_Real S) -{ - focalLength *= S; - if (focalLength < 0) focalLength = - focalLength; - pos.Scale (P, S); -} - -inline gp_Parab gp_Parab::Scaled (const gp_Pnt& P, - const Standard_Real S) const -{ - gp_Parab Prb = *this; - Prb.focalLength *= S; - if (Prb.focalLength < 0) Prb.focalLength = - Prb.focalLength; - Prb.pos.Scale (P, S); - return Prb; -} - -inline void gp_Parab::Transform (const gp_Trsf& T) -{ - focalLength *= T.ScaleFactor(); - if (focalLength < 0) focalLength = - focalLength; - pos.Transform (T); -} - -inline gp_Parab gp_Parab::Transformed (const gp_Trsf& T) const -{ - gp_Parab Prb = *this; - Prb.focalLength *= T.ScaleFactor(); - if (Prb.focalLength < 0) Prb.focalLength = - Prb.focalLength; - Prb.pos.Transform (T); - return Prb; -} - -inline void gp_Parab::Translate (const gp_Vec& V) -{ pos.Translate (V); } - -inline gp_Parab gp_Parab::Translated (const gp_Vec& V) const -{ - gp_Parab Prb = *this; - Prb.pos.Translate (V); - return Prb; -} - -inline void gp_Parab::Translate (const gp_Pnt& P1, - const gp_Pnt& P2) -{ pos.Translate (P1, P2); } - -inline gp_Parab gp_Parab::Translated (const gp_Pnt& P1, - const gp_Pnt& P2) const -{ - gp_Parab Prb = *this; - Prb.pos.Translate (P1, P2); - return Prb; -} - diff --git a/src/gp/gp_Parab2d.cxx b/src/gp/gp_Parab2d.cxx index 48718479a9..c3b41eec29 100644 --- a/src/gp/gp_Parab2d.cxx +++ b/src/gp/gp_Parab2d.cxx @@ -14,10 +14,10 @@ #define No_Standard_OutOfRange +#include #include #include -#include #include #include #include diff --git a/src/gp/gp_Parab2d.hxx b/src/gp/gp_Parab2d.hxx index c322f04a0f..a16b61edb2 100644 --- a/src/gp/gp_Parab2d.hxx +++ b/src/gp/gp_Parab2d.hxx @@ -15,22 +15,10 @@ #ifndef _gp_Parab2d_HeaderFile #define _gp_Parab2d_HeaderFile -#include -#include -#include - #include -#include -#include #include #include -class Standard_ConstructionError; -class gp_Ax2d; -class gp_Ax22d; -class gp_Pnt2d; -class gp_Trsf2d; -class gp_Vec2d; - +#include //! Describes a parabola in the plane (2D space). //! A parabola is defined by its focal length (that is, the @@ -62,10 +50,10 @@ public: DEFINE_STANDARD_ALLOC - //! Creates an indefinite parabola. - gp_Parab2d(); - + gp_Parab2d() + : focalLength (RealLast()) + {} //! Creates a parabola with its vertex point, its axis of symmetry //! ("XAxis") and its focal length. @@ -75,18 +63,26 @@ public: //! Warnings : It is possible to have FocalLength = 0. In this case, //! the parabola looks like a line, which is parallel to the symmetry-axis. //! Raises ConstructionError if FocalLength < 0.0 - gp_Parab2d(const gp_Ax2d& theMirrorAxis, - const Standard_Real theFocalLength, - const Standard_Boolean theSense = Standard_True); - + gp_Parab2d (const gp_Ax2d& theMirrorAxis, + const Standard_Real theFocalLength, + const Standard_Boolean theSense = Standard_True) + : focalLength (theFocalLength) + { + pos = gp_Ax22d (theMirrorAxis, theSense); + Standard_ConstructionError_Raise_if (theFocalLength < 0.0, "gp_Parab2d() - focal length should be >= 0"); + } //! Creates a parabola with its vertex point, its axis of symmetry //! ("XAxis"), correspond Y-axis and its focal length. //! Warnings : It is possible to have FocalLength = 0. In this case, //! the parabola looks like a line, which is parallel to the symmetry-axis. //! Raises ConstructionError if Focal < 0.0 - gp_Parab2d(const gp_Ax22d& theAxes, const Standard_Real theFocalLength); - + gp_Parab2d (const gp_Ax22d& theAxes, const Standard_Real theFocalLength) + : pos (theAxes), + focalLength (theFocalLength) + { + Standard_ConstructionError_Raise_if (theFocalLength < 0.0, "gp_Parab2d() - focal length should be >= 0"); + } //! Creates a parabola with the directrix and the focus point. //! Y-axis of the parabola (in User Coordinate System - UCS) is @@ -99,42 +95,42 @@ public: //! by theSense parameter. If theSense == TRUE (by default) then right-handed //! coordinate system is used, otherwise - left-handed. Result parabola will look //! like a line, which is perpendicular to the directrix. - Standard_EXPORT gp_Parab2d(const gp_Ax2d& theDirectrix, - const gp_Pnt2d& theFocus, - const Standard_Boolean theSense = Standard_True); - + Standard_EXPORT gp_Parab2d (const gp_Ax2d& theDirectrix, + const gp_Pnt2d& theFocus, + const Standard_Boolean theSense = Standard_True); + //! Changes the focal distance of the parabola - //! Warnings : It is possible to have Focal = 0. - //! Raises ConstructionError if Focal < 0.0 - void SetFocal (const Standard_Real Focal); - + //! Warnings : It is possible to have theFocal = 0. + //! Raises ConstructionError if theFocal < 0.0 + void SetFocal (const Standard_Real theFocal) + { + Standard_ConstructionError_Raise_if (theFocal < 0.0, "gp_Parab2d::SetFocal() - focal length should be >= 0"); + focalLength = theFocal; + } //! Changes the "Location" point of the parabola. It is the //! vertex of the parabola. - void SetLocation (const gp_Pnt2d& P); - + void SetLocation (const gp_Pnt2d& theP) { pos.SetLocation (theP); } + //! Modifies this parabola, by redefining its local coordinate system so that //! its origin and "X Direction" become those of the axis //! MA. The "Y Direction" of the local coordinate system is //! then recomputed. The orientation of the local //! coordinate system is not modified. - void SetMirrorAxis (const gp_Ax2d& A); - + void SetMirrorAxis (const gp_Ax2d& theA) { pos.SetXAxis (theA); } //! Changes the local coordinate system of the parabola. //! The "Location" point of A becomes the vertex of the parabola. - void SetAxis (const gp_Ax22d& A); - + void SetAxis (const gp_Ax22d& theA) { pos.SetAxis (theA); } //! Computes the coefficients of the implicit equation of the parabola //! (in WCS - World Coordinate System). //! @code - //! A * (X**2) + B * (Y**2) + 2*C*(X*Y) + 2*D*X + 2*E*Y + F = 0. + //! theA * (X**2) + theB * (Y**2) + 2*theC*(X*Y) + 2*theD*X + 2*theE*Y + theF = 0. //! @endcode - Standard_EXPORT void Coefficients (Standard_Real& A, Standard_Real& B, - Standard_Real& C, Standard_Real& D, - Standard_Real& E, Standard_Real& F) const; - + Standard_EXPORT void Coefficients (Standard_Real& theA, Standard_Real& theB, + Standard_Real& theC, Standard_Real& theD, + Standard_Real& theE, Standard_Real& theF) const; //! Computes the directrix of the parabola. //! The directrix is: @@ -144,36 +140,40 @@ public: //! at a distance from the apex which is equal to the focal length of this parabola. //! The directrix is returned as an axis (a gp_Ax2d object), //! the origin of which is situated on the "X Axis" of this parabola. - gp_Ax2d Directrix() const; - + gp_Ax2d Directrix() const; //! Returns the distance between the vertex and the focus //! of the parabola. - Standard_Real Focal() const; - + Standard_Real Focal() const { return focalLength; } + //! Returns the focus of the parabola. - gp_Pnt2d Focus() const; - + gp_Pnt2d Focus() const + { + return gp_Pnt2d (pos.Location().X() + focalLength * pos.XDirection().X(), + pos.Location().Y() + focalLength * pos.XDirection().Y()); + } + //! Returns the vertex of the parabola. - gp_Pnt2d Location() const; - + gp_Pnt2d Location() const { return pos.Location(); } //! Returns the symmetry axis of the parabola. //! The "Location" point of this axis is the vertex of the parabola. - gp_Ax2d MirrorAxis() const; - + gp_Ax2d MirrorAxis() const { return pos.XAxis(); } //! Returns the local coordinate system of the parabola. //! The "Location" point of this axis is the vertex of the parabola. - gp_Ax22d Axis() const; - + gp_Ax22d Axis() const { return pos; } //! Returns the distance between the focus and the //! directrix of the parabola. - Standard_Real Parameter() const; - - void Reverse(); - + Standard_Real Parameter() const { return 2.0 * focalLength; } + + void Reverse() + { + gp_Dir2d aTemp = pos.YDirection(); + aTemp.Reverse(); + pos.SetAxis (gp_Ax22d (pos.Location(), pos.XDirection(), aTemp)); + } //! Reverses the orientation of the local coordinate system //! of this parabola (the "Y Direction" is reversed). @@ -181,84 +181,161 @@ public: //! Note: //! - Reverse assigns the result to this parabola, while //! - Reversed creates a new one. - Standard_NODISCARD gp_Parab2d Reversed() const; - + Standard_NODISCARD gp_Parab2d Reversed() const; + //! Returns true if the local coordinate system is direct //! and false in the other case. - Standard_Boolean IsDirect() const; - - Standard_EXPORT void Mirror (const gp_Pnt2d& P); - + Standard_Boolean IsDirect() const + { + return (pos.XDirection().Crossed (pos.YDirection())) >= 0.0; + } + + Standard_EXPORT void Mirror (const gp_Pnt2d& theP); //! Performs the symmetrical transformation of a parabola with respect - //! to the point P which is the center of the symmetry - Standard_NODISCARD Standard_EXPORT gp_Parab2d Mirrored (const gp_Pnt2d& P) const; - - Standard_EXPORT void Mirror (const gp_Ax2d& A); - + //! to the point theP which is the center of the symmetry + Standard_NODISCARD Standard_EXPORT gp_Parab2d Mirrored (const gp_Pnt2d& theP) const; + + Standard_EXPORT void Mirror (const gp_Ax2d& theA); //! Performs the symmetrical transformation of a parabola with respect //! to an axis placement which is the axis of the symmetry. - Standard_NODISCARD Standard_EXPORT gp_Parab2d Mirrored (const gp_Ax2d& A) const; - - void Rotate (const gp_Pnt2d& P, const Standard_Real Ang); - + Standard_NODISCARD Standard_EXPORT gp_Parab2d Mirrored (const gp_Ax2d& theA) const; - //! Rotates a parabola. P is the center of the rotation. - //! Ang is the angular value of the rotation in radians. - Standard_NODISCARD gp_Parab2d Rotated (const gp_Pnt2d& P, const Standard_Real Ang) const; - - void Scale (const gp_Pnt2d& P, const Standard_Real S); - + void Rotate (const gp_Pnt2d& theP, const Standard_Real theAng) { pos.Rotate (theP, theAng); } - //! Scales a parabola. S is the scaling value. - //! If S is negative the direction of the symmetry axis + //! Rotates a parabola. theP is the center of the rotation. + //! theAng is the angular value of the rotation in radians. + Standard_NODISCARD gp_Parab2d Rotated (const gp_Pnt2d& theP, const Standard_Real theAng) const + { + gp_Parab2d aPrb = *this; + aPrb.pos.Rotate (theP, theAng); + return aPrb; + } + + void Scale (const gp_Pnt2d& theP, const Standard_Real theS); + + //! Scales a parabola. theS is the scaling value. + //! If theS is negative the direction of the symmetry axis //! "XAxis" is reversed and the direction of the "YAxis" too. - Standard_NODISCARD gp_Parab2d Scaled (const gp_Pnt2d& P, const Standard_Real S) const; - - void Transform (const gp_Trsf2d& T); - + Standard_NODISCARD gp_Parab2d Scaled (const gp_Pnt2d& theP, const Standard_Real theS) const; - //! Transforms an parabola with the transformation T from class Trsf2d. - Standard_NODISCARD gp_Parab2d Transformed (const gp_Trsf2d& T) const; - - void Translate (const gp_Vec2d& V); - + void Transform (const gp_Trsf2d& theT); - //! Translates a parabola in the direction of the vector V. + //! Transforms an parabola with the transformation theT from class Trsf2d. + Standard_NODISCARD gp_Parab2d Transformed (const gp_Trsf2d& theT) const; + + void Translate (const gp_Vec2d& theV) { pos.Translate (theV); } + + //! Translates a parabola in the direction of the vectorthe theV. //! The magnitude of the translation is the vector's magnitude. - Standard_NODISCARD gp_Parab2d Translated (const gp_Vec2d& V) const; - - void Translate (const gp_Pnt2d& P1, const gp_Pnt2d& P2); - - - //! Translates a parabola from the point P1 to the point P2. - Standard_NODISCARD gp_Parab2d Translated (const gp_Pnt2d& P1, const gp_Pnt2d& P2) const; - - - - -protected: - - + Standard_NODISCARD gp_Parab2d Translated (const gp_Vec2d& theV) const + { + gp_Parab2d aPrb = *this; + aPrb.pos.Translate (theV); + return aPrb; + } + void Translate (const gp_Pnt2d& theP1, const gp_Pnt2d& theP2) { pos.Translate (theP1, theP2); } + //! Translates a parabola from the point theP1 to the point theP2. + Standard_NODISCARD gp_Parab2d Translated (const gp_Pnt2d& theP1, const gp_Pnt2d& theP2) const + { + gp_Parab2d aPrb = *this; + aPrb.pos.Translate (theP1, theP2); + return aPrb; + } private: - - gp_Ax22d pos; Standard_Real focalLength; - }; +//======================================================================= +//function : Directrix +// purpose : +//======================================================================= +inline gp_Ax2d gp_Parab2d::Directrix() const +{ + gp_Pnt2d aP (pos.Location().X() - focalLength * pos.XDirection().X(), + pos.Location().Y() - focalLength * pos.XDirection().Y()); + gp_Dir2d aV (pos.YDirection()); + return gp_Ax2d (aP, aV); +} -#include +//======================================================================= +//function : Reversed +// purpose : +//======================================================================= +inline gp_Parab2d gp_Parab2d::Reversed() const +{ + gp_Parab2d aP = *this; + gp_Dir2d aTemp = pos.YDirection(); + aTemp.Reverse(); + aP.pos.SetAxis (gp_Ax22d (pos.Location(), pos.XDirection(), aTemp)); + return aP; +} +//======================================================================= +//function : Scale +// purpose : +//======================================================================= +inline void gp_Parab2d::Scale (const gp_Pnt2d& theP, const Standard_Real theS) +{ + focalLength *= theS; + if (focalLength < 0) + { + focalLength = -focalLength; + } + pos.Scale (theP, theS); +} +//======================================================================= +//function : Scaled +// purpose : +//======================================================================= +inline gp_Parab2d gp_Parab2d::Scaled (const gp_Pnt2d& theP, const Standard_Real theS) const +{ + gp_Parab2d aPrb = *this; + aPrb.focalLength *= theS; + if (aPrb.focalLength < 0) + { + aPrb.focalLength = -aPrb.focalLength; + } + aPrb.pos.Scale (theP, theS); + return aPrb; +} +//======================================================================= +//function : Transform +// purpose : +//======================================================================= +inline void gp_Parab2d::Transform (const gp_Trsf2d& theT) +{ + focalLength *= theT.ScaleFactor(); + if (focalLength < 0) + { + focalLength = -focalLength; + } + pos.Transform (theT); +} +//======================================================================= +//function : Transformed +// purpose : +//======================================================================= +inline gp_Parab2d gp_Parab2d::Transformed (const gp_Trsf2d& theT) const +{ + gp_Parab2d aPrb = *this; + aPrb.focalLength *= theT.ScaleFactor(); + if (aPrb.focalLength < 0) + { + aPrb.focalLength = -aPrb.focalLength; + } + aPrb.pos.Transform (theT); + return aPrb; +} #endif // _gp_Parab2d_HeaderFile diff --git a/src/gp/gp_Parab2d.lxx b/src/gp/gp_Parab2d.lxx deleted file mode 100644 index c1ba7253cd..0000000000 --- a/src/gp/gp_Parab2d.lxx +++ /dev/null @@ -1,166 +0,0 @@ -// Copyright (c) 1995-1999 Matra Datavision -// Copyright (c) 1999-2014 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -#include - -inline gp_Parab2d::gp_Parab2d () :focalLength(RealLast()){ } - -inline gp_Parab2d::gp_Parab2d(const gp_Ax22d& theMirrorAxis, - const Standard_Real theFocalLength) : - pos (theMirrorAxis), - focalLength (theFocalLength) -{ - Standard_ConstructionError_Raise_if (theFocalLength < 0.0, "gp_Parab2d() - focal length should be >= 0"); -} - -inline gp_Parab2d::gp_Parab2d(const gp_Ax2d& theMirrorAxis, - const Standard_Real theFocalLength, - const Standard_Boolean theSense) : - focalLength (theFocalLength) -{ - pos = gp_Ax22d(theMirrorAxis,theSense); - Standard_ConstructionError_Raise_if (theFocalLength < 0.0, "gp_Parab2d() - focal length should be >= 0"); -} - -inline void gp_Parab2d::SetFocal (const Standard_Real Focal) -{ - Standard_ConstructionError_Raise_if (Focal < 0.0, "gp_Parab2d::SetFocal() - focal length should be >= 0"); - focalLength = Focal; -} - -inline void gp_Parab2d::SetLocation (const gp_Pnt2d& P) -{ pos.SetLocation(P); } - -inline void gp_Parab2d::SetMirrorAxis (const gp_Ax2d& A) -{ pos.SetXAxis(A); } - -inline void gp_Parab2d::SetAxis (const gp_Ax22d& A) -{ pos.SetAxis(A); } - -inline gp_Ax2d gp_Parab2d::Directrix() const -{ - gp_Pnt2d P (pos.Location().X() - focalLength * pos.XDirection().X(), - pos.Location().Y() - focalLength * pos.XDirection().Y() ); - gp_Dir2d V (pos.YDirection()); - return gp_Ax2d(P, V); -} - -inline Standard_Real gp_Parab2d::Focal() const -{ return focalLength; } - -inline gp_Pnt2d gp_Parab2d::Focus() const -{ - return gp_Pnt2d (pos.Location().X() + focalLength * pos.XDirection().X(), - pos.Location().Y() + focalLength * pos.XDirection().Y()); -} - -inline gp_Pnt2d gp_Parab2d::Location () const -{ return pos.Location(); } - -inline gp_Ax2d gp_Parab2d::MirrorAxis () const -{ return pos.XAxis(); } - -inline gp_Ax22d gp_Parab2d::Axis () const -{ return pos; } - -inline Standard_Real gp_Parab2d::Parameter() const -{ return 2.0 * focalLength; } - -inline void gp_Parab2d::Reverse() -{ - gp_Dir2d Temp = pos.YDirection (); - Temp.Reverse (); - pos.SetAxis(gp_Ax22d(pos.Location(),pos.XDirection(),Temp)); -} - -inline gp_Parab2d gp_Parab2d::Reversed() const -{ - gp_Parab2d P = *this; - gp_Dir2d Temp = pos.YDirection (); - Temp.Reverse (); - P.pos.SetAxis(gp_Ax22d(pos.Location(),pos.XDirection(),Temp)); - return P; -} - -inline Standard_Boolean gp_Parab2d::IsDirect() const -{ return (pos.XDirection().Crossed(pos.YDirection())) >= 0.0; } - -inline void gp_Parab2d::Rotate (const gp_Pnt2d& P, - const Standard_Real Ang) -{pos.Rotate (P, Ang);} - -inline gp_Parab2d gp_Parab2d::Rotated (const gp_Pnt2d& P, - const Standard_Real Ang) const -{ - gp_Parab2d Prb = *this; - Prb.pos.Rotate (P, Ang); - return Prb; -} - -inline void gp_Parab2d::Scale (const gp_Pnt2d& P, - const Standard_Real S) -{ - focalLength *= S; - if (focalLength < 0) focalLength = - focalLength; - pos.Scale (P, S); -} - -inline gp_Parab2d gp_Parab2d::Scaled (const gp_Pnt2d& P, - const Standard_Real S) const -{ - gp_Parab2d Prb = *this; - Prb.focalLength *= S; - if (Prb.focalLength < 0) Prb.focalLength = - Prb.focalLength; - Prb.pos.Scale (P, S); - return Prb; -} - -inline void gp_Parab2d::Transform (const gp_Trsf2d& T) -{ - focalLength *= T.ScaleFactor(); - if (focalLength < 0) focalLength = - focalLength; - pos.Transform (T); -} - -inline gp_Parab2d gp_Parab2d::Transformed (const gp_Trsf2d& T) const -{ - gp_Parab2d Prb = *this; - Prb.focalLength *= T.ScaleFactor(); - if (Prb.focalLength < 0) Prb.focalLength = - Prb.focalLength; - Prb.pos.Transform (T); - return Prb; -} - -inline void gp_Parab2d::Translate (const gp_Vec2d& V) -{ pos.Translate (V); } - -inline gp_Parab2d gp_Parab2d::Translated (const gp_Vec2d& V) const -{ - gp_Parab2d Prb = *this; - Prb.pos.Translate(V); - return Prb; -} - -inline void gp_Parab2d::Translate (const gp_Pnt2d& P1, - const gp_Pnt2d& P2) -{ pos.Translate (P1, P2); } - -inline gp_Parab2d gp_Parab2d::Translated (const gp_Pnt2d& P1, - const gp_Pnt2d& P2) const -{ - gp_Parab2d Prb = *this; - Prb.pos.Translate (P1, P2); - return Prb; -} - diff --git a/src/gp/gp_Pln.cxx b/src/gp/gp_Pln.cxx index 4d14751d50..2c6ce80e0d 100644 --- a/src/gp/gp_Pln.cxx +++ b/src/gp/gp_Pln.cxx @@ -19,13 +19,14 @@ // JCV 07/92 Introduction de la method Dump // LBO 08/93 Passage aux Ax3 +#include + #include #include #include #include #include #include -#include #include #include #include diff --git a/src/gp/gp_Pln.hxx b/src/gp/gp_Pln.hxx index 0099564310..18a6590c2e 100644 --- a/src/gp/gp_Pln.hxx +++ b/src/gp/gp_Pln.hxx @@ -15,24 +15,13 @@ #ifndef _gp_Pln_HeaderFile #define _gp_Pln_HeaderFile -#include -#include -#include - -#include -#include -#include #include -class Standard_ConstructionError; -class gp_Ax3; -class gp_Pnt; -class gp_Dir; -class gp_Ax1; -class gp_Lin; -class gp_Ax2; -class gp_Trsf; -class gp_Vec; - +#include +#include +#include +#include +#include +#include //! Describes a plane. //! A plane is positioned in space with a coordinate system @@ -61,131 +50,143 @@ public: DEFINE_STANDARD_ALLOC - //! Creates a plane coincident with OXY plane of the //! reference coordinate system. - gp_Pln(); - + gp_Pln() {} //! The coordinate system of the plane is defined with the axis - //! placement A3. - //! The "Direction" of A3 defines the normal to the plane. - //! The "Location" of A3 defines the location (origin) of the plane. - //! The "XDirection" and "YDirection" of A3 define the "XAxis" and + //! placement theA3. + //! The "Direction" of theA3 defines the normal to the plane. + //! The "Location" of theA3 defines the location (origin) of the plane. + //! The "XDirection" and "YDirection" of theA3 define the "XAxis" and //! the "YAxis" of the plane used to parametrize the plane. - gp_Pln(const gp_Ax3& A3); - + gp_Pln (const gp_Ax3& theA3) + : pos (theA3) + {} - //! Creates a plane with the "Location" point

- //! and the normal direction . - Standard_EXPORT gp_Pln(const gp_Pnt& P, const gp_Dir& V); - + //! Creates a plane with the "Location" point + //! and the normal direction . + Standard_EXPORT gp_Pln (const gp_Pnt& theP, const gp_Dir& theV); //! Creates a plane from its cartesian equation : //! @code - //! A * X + B * Y + C * Z + D = 0.0 + //! theA * X + theB * Y + theC * Z + theD = 0.0 //! @endcode - //! Raises ConstructionError if Sqrt (A*A + B*B + C*C) <= Resolution from gp. - Standard_EXPORT gp_Pln(const Standard_Real A, const Standard_Real B, const Standard_Real C, const Standard_Real D); - + //! Raises ConstructionError if Sqrt (theA*theA + theB*theB + theC*theC) <= Resolution from gp. + Standard_EXPORT gp_Pln (const Standard_Real theA, const Standard_Real theB, const Standard_Real theC, const Standard_Real theD); //! Returns the coefficients of the plane's cartesian equation : //! @code - //! A * X + B * Y + C * Z + D = 0. + //! theA * X + theB * Y + theC * Z + theD = 0. //! @endcode - void Coefficients (Standard_Real& A, Standard_Real& B, Standard_Real& C, Standard_Real& D) const; - + void Coefficients (Standard_Real& theA, Standard_Real& theB, Standard_Real& theC, Standard_Real& theD) const; + //! Modifies this plane, by redefining its local coordinate system so that //! - its origin and "main Direction" become those of the - //! axis A1 (the "X Direction" and "Y Direction" are then recomputed). - //! Raises ConstructionError if the A1 is parallel to the "XAxis" of the plane. - void SetAxis (const gp_Ax1& A1); - + //! axis theA1 (the "X Direction" and "Y Direction" are then recomputed). + //! Raises ConstructionError if the theA1 is parallel to the "XAxis" of the plane. + void SetAxis (const gp_Ax1& theA1) { pos.SetAxis (theA1); } + //! Changes the origin of the plane. - void SetLocation (const gp_Pnt& Loc); - + void SetLocation (const gp_Pnt& theLoc) { pos.SetLocation (theLoc); } + //! Changes the local coordinate system of the plane. - void SetPosition (const gp_Ax3& A3); - + void SetPosition (const gp_Ax3& theA3) { pos = theA3; } + //! Reverses the U parametrization of the plane //! reversing the XAxis. - void UReverse(); - + void UReverse() { pos.XReverse(); } + //! Reverses the V parametrization of the plane //! reversing the YAxis. - void VReverse(); - + void VReverse() { pos.YReverse(); } + //! returns true if the Ax3 is right handed. - Standard_Boolean Direct() const; - + Standard_Boolean Direct() const { return pos.Direct(); } + //! Returns the plane's normal Axis. - const gp_Ax1& Axis() const; - + const gp_Ax1& Axis() const { return pos.Axis(); } + //! Returns the plane's location (origin). - const gp_Pnt& Location() const; - + const gp_Pnt& Location() const { return pos.Location(); } + //! Returns the local coordinate system of the plane . - const gp_Ax3& Position() const; - - //! Computes the distance between and the point

. - Standard_Real Distance (const gp_Pnt& P) const; - - //! Computes the distance between and the line . - Standard_Real Distance (const gp_Lin& L) const; - + const gp_Ax3& Position() const { return pos; } + + //! Computes the distance between and the point . + Standard_Real Distance (const gp_Pnt& theP) const; + + //! Computes the distance between and the line . + Standard_Real Distance (const gp_Lin& theL) const; + //! Computes the distance between two planes. - Standard_Real Distance (const gp_Pln& Other) const; - + Standard_Real Distance (const gp_Pln& theOther) const; - //! Computes the square distance between and the point

. - Standard_Real SquareDistance (const gp_Pnt& P) const; - + //! Computes the square distance between and the point . + Standard_Real SquareDistance (const gp_Pnt& theP) const + { + Standard_Real aD = Distance (theP); + return aD * aD; + } - //! Computes the square distance between and the line . - Standard_Real SquareDistance (const gp_Lin& L) const; - + //! Computes the square distance between and the line . + Standard_Real SquareDistance (const gp_Lin& theL) const + { + Standard_Real aD = Distance (theL); + return aD * aD; + } //! Computes the square distance between two planes. - Standard_Real SquareDistance (const gp_Pln& Other) const; - + Standard_Real SquareDistance (const gp_Pln& theOther) const + { + Standard_Real aD = Distance (theOther); + return aD * aD; + } + //! Returns the X axis of the plane. - gp_Ax1 XAxis() const; - + gp_Ax1 XAxis() const { return gp_Ax1 (pos.Location(), pos.XDirection()); } + //! Returns the Y axis of the plane. - gp_Ax1 YAxis() const; - - //! Returns true if this plane contains the point P. This means that - //! - the distance between point P and this plane is less - //! than or equal to LinearTolerance, or + gp_Ax1 YAxis() const { return gp_Ax1 (pos.Location(), pos.YDirection()); } + + //! Returns true if this plane contains the point theP. This means that + //! - the distance between point theP and this plane is less + //! than or equal to theLinearTolerance, or //! - line L is normal to the "main Axis" of the local //! coordinate system of this plane, within the tolerance //! AngularTolerance, and the distance between the origin //! of line L and this plane is less than or equal to - //! LinearTolerance. - Standard_Boolean Contains (const gp_Pnt& P, const Standard_Real LinearTolerance) const; - - //! Returns true if this plane contains the line L. This means that + //! theLinearTolerance. + Standard_Boolean Contains (const gp_Pnt& theP, const Standard_Real theLinearTolerance) const + { + return Distance (theP) <= theLinearTolerance; + } + + //! Returns true if this plane contains the line theL. This means that //! - the distance between point P and this plane is less //! than or equal to LinearTolerance, or - //! - line L is normal to the "main Axis" of the local + //! - line theL is normal to the "main Axis" of the local //! coordinate system of this plane, within the tolerance - //! AngularTolerance, and the distance between the origin - //! of line L and this plane is less than or equal to - //! LinearTolerance. - Standard_Boolean Contains (const gp_Lin& L, const Standard_Real LinearTolerance, const Standard_Real AngularTolerance) const; - - Standard_EXPORT void Mirror (const gp_Pnt& P); - + //! theAngularTolerance, and the distance between the origin + //! of line theL and this plane is less than or equal to + //! theLinearTolerance. + Standard_Boolean Contains (const gp_Lin& theL, const Standard_Real theLinearTolerance, const Standard_Real theAngularTolerance) const + { + return Contains (theL.Location(), theLinearTolerance) && + pos.Direction().IsNormal (theL.Direction(), theAngularTolerance); + } + + Standard_EXPORT void Mirror (const gp_Pnt& theP); //! Performs the symmetrical transformation of a plane with respect - //! to the point

which is the center of the symmetry + //! to the point which is the center of the symmetry //! Warnings : //! The normal direction to the plane is not changed. //! The "XAxis" and the "YAxis" are reversed. - Standard_NODISCARD Standard_EXPORT gp_Pln Mirrored (const gp_Pnt& P) const; - - Standard_EXPORT void Mirror (const gp_Ax1& A1); - + Standard_NODISCARD Standard_EXPORT gp_Pln Mirrored (const gp_Pnt& theP) const; + + Standard_EXPORT void Mirror (const gp_Ax1& theA1); + //! Performs the symmetrical transformation of a //! plane with respect to an axis placement which is the axis //! of the symmetry. The transformation is performed on the @@ -194,10 +195,10 @@ public: //! the "XDirection" and the "YDirection" after transformation //! if the initial plane was right handed, else it is the //! opposite. - Standard_NODISCARD Standard_EXPORT gp_Pln Mirrored (const gp_Ax1& A1) const; - - Standard_EXPORT void Mirror (const gp_Ax2& A2); - + Standard_NODISCARD Standard_EXPORT gp_Pln Mirrored (const gp_Ax1& theA1) const; + + Standard_EXPORT void Mirror (const gp_Ax2& theA2); + //! Performs the symmetrical transformation of a //! plane with respect to an axis placement. The axis //! placement locates the plane of the symmetry. The @@ -206,70 +207,163 @@ public: //! direction is the cross product between the "XDirection" //! and the "YDirection" after transformation if the initial //! plane was right handed, else it is the opposite. - Standard_NODISCARD Standard_EXPORT gp_Pln Mirrored (const gp_Ax2& A2) const; - - void Rotate (const gp_Ax1& A1, const Standard_Real Ang); - + Standard_NODISCARD Standard_EXPORT gp_Pln Mirrored (const gp_Ax2& theA2) const; - //! rotates a plane. A1 is the axis of the rotation. - //! Ang is the angular value of the rotation in radians. - Standard_NODISCARD gp_Pln Rotated (const gp_Ax1& A1, const Standard_Real Ang) const; - - void Scale (const gp_Pnt& P, const Standard_Real S); - + void Rotate (const gp_Ax1& theA1, const Standard_Real theAng) { pos.Rotate (theA1, theAng); } - //! Scales a plane. S is the scaling value. - Standard_NODISCARD gp_Pln Scaled (const gp_Pnt& P, const Standard_Real S) const; - - void Transform (const gp_Trsf& T); - + //! rotates a plane. theA1 is the axis of the rotation. + //! theAng is the angular value of the rotation in radians. + Standard_NODISCARD gp_Pln Rotated (const gp_Ax1& theA1, const Standard_Real theAng) const + { + gp_Pln aPl = *this; + aPl.pos.Rotate (theA1, theAng); + return aPl; + } - //! Transforms a plane with the transformation T from class Trsf. + void Scale (const gp_Pnt& theP, const Standard_Real theS) { pos.Scale (theP, theS); } + + //! Scales a plane. theS is the scaling value. + Standard_NODISCARD gp_Pln Scaled (const gp_Pnt& theP, const Standard_Real theS) const + { + gp_Pln aPl = *this; + aPl.pos.Scale (theP, theS); + return aPl; + } + + void Transform (const gp_Trsf& theT) { pos.Transform (theT); } + + //! Transforms a plane with the transformation theT from class Trsf. //! The transformation is performed on the "Location" //! point, on the "XAxis" and the "YAxis". //! The resulting normal direction is the cross product between //! the "XDirection" and the "YDirection" after transformation. - Standard_NODISCARD gp_Pln Transformed (const gp_Trsf& T) const; - - void Translate (const gp_Vec& V); - + Standard_NODISCARD gp_Pln Transformed (const gp_Trsf& theT) const + { + gp_Pln aPl = *this; + aPl.pos.Transform (theT); + return aPl; + } - //! Translates a plane in the direction of the vector V. + void Translate (const gp_Vec& theV) { pos.Translate (theV); } + + //! Translates a plane in the direction of the vector theV. //! The magnitude of the translation is the vector's magnitude. - Standard_NODISCARD gp_Pln Translated (const gp_Vec& V) const; - - void Translate (const gp_Pnt& P1, const gp_Pnt& P2); - + Standard_NODISCARD gp_Pln Translated (const gp_Vec& theV) const + { + gp_Pln aPl = *this; + aPl.pos.Translate (theV); + return aPl; + } - //! Translates a plane from the point P1 to the point P2. - Standard_NODISCARD gp_Pln Translated (const gp_Pnt& P1, const gp_Pnt& P2) const; + void Translate (const gp_Pnt& theP1, const gp_Pnt& theP2) { pos.Translate (theP1, theP2); } + //! Translates a plane from the point theP1 to the point theP2. + Standard_NODISCARD gp_Pln Translated (const gp_Pnt& theP1, const gp_Pnt& theP2) const + { + gp_Pln aPl = *this; + aPl.pos.Translate (theP1, theP2); + return aPl; + } //! Dumps the content of me into the stream Standard_EXPORT void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const; - - -protected: - - - - - private: - - gp_Ax3 pos; - }; +#include -#include - +//======================================================================= +//function : Coefficients +// purpose : +//======================================================================= +inline void gp_Pln::Coefficients (Standard_Real& theA, + Standard_Real& theB, + Standard_Real& theC, + Standard_Real& theD) const +{ + const gp_Dir& aDir = pos.Direction(); + if (pos.Direct()) + { + theA = aDir.X(); + theB = aDir.Y(); + theC = aDir.Z(); + } + else + { + theA = -aDir.X(); + theB = -aDir.Y(); + theC = -aDir.Z(); + } + const gp_Pnt& aP = pos.Location(); + theD = -(theA * aP.X() + theB * aP.Y() + theC * aP.Z()); +} +//======================================================================= +//function : Distance +// purpose : +//======================================================================= +inline Standard_Real gp_Pln::Distance (const gp_Pnt& theP) const +{ + const gp_Pnt& aLoc = pos.Location (); + const gp_Dir& aDir = pos.Direction(); + Standard_Real aD = (aDir.X() * (theP.X() - aLoc.X()) + + aDir.Y() * (theP.Y() - aLoc.Y()) + + aDir.Z() * (theP.Z() - aLoc.Z())); + if (aD < 0) + { + aD = -aD; + } + return aD; +} +//======================================================================= +//function : Distance +// purpose : +//======================================================================= +inline Standard_Real gp_Pln::Distance (const gp_Lin& theL) const +{ + Standard_Real aD = 0.0; + if ((pos.Direction()).IsNormal (theL.Direction(), gp::Resolution())) + { + const gp_Pnt& aP = theL.Location(); + const gp_Pnt& aLoc = pos.Location(); + const gp_Dir& aDir = pos.Direction(); + aD = (aDir.X() * (aP.X() - aLoc.X()) + + aDir.Y() * (aP.Y() - aLoc.Y()) + + aDir.Z() * (aP.Z() - aLoc.Z())); + if (aD < 0) + { + aD = -aD; + } + } + return aD; +} +//======================================================================= +//function : Distance +// purpose : +//======================================================================= +inline Standard_Real gp_Pln::Distance (const gp_Pln& theOther) const +{ + Standard_Real aD = 0.0; + if ((pos.Direction()).IsParallel (theOther.pos.Direction(), gp::Resolution())) + { + const gp_Pnt& aP = theOther.pos.Location(); + const gp_Pnt& aLoc = pos.Location (); + const gp_Dir& aDir = pos.Direction(); + aD = (aDir.X() * (aP.X() - aLoc.X()) + + aDir.Y() * (aP.Y() - aLoc.Y()) + + aDir.Z() * (aP.Z() - aLoc.Z())); + if (aD < 0) + { + aD = -aD; + } + } + return aD; +} #endif // _gp_Pln_HeaderFile diff --git a/src/gp/gp_Pln.lxx b/src/gp/gp_Pln.lxx deleted file mode 100644 index c2b056fac8..0000000000 --- a/src/gp/gp_Pln.lxx +++ /dev/null @@ -1,193 +0,0 @@ -// Copyright (c) 1995-1999 Matra Datavision -// Copyright (c) 1999-2014 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -// JCV 30/08/90 Modif passage version C++ 2.0 sur Sun - -#include - -inline gp_Pln::gp_Pln() -{ } - -inline gp_Pln::gp_Pln(const gp_Ax3& A3) : pos(A3) -{ } - -inline void gp_Pln::Coefficients (Standard_Real& A, - Standard_Real& B, - Standard_Real& C, - Standard_Real& D) const -{ - const gp_Dir& dir = pos.Direction(); - if (pos.Direct()) { - A = dir.X(); - B = dir.Y(); - C = dir.Z(); - } - else { - A = -dir.X(); - B = -dir.Y(); - C = -dir.Z(); - } - const gp_Pnt& P = pos.Location(); - D = -(A * P.X() + B * P.Y() + C * P.Z()); -} - -inline void gp_Pln::SetAxis (const gp_Ax1& A1) -{ pos.SetAxis (A1); } - -inline void gp_Pln::SetLocation (const gp_Pnt& Loc) -{ pos.SetLocation (Loc); } - -inline void gp_Pln::SetPosition (const gp_Ax3& A3) -{ pos = A3; } - -inline void gp_Pln::UReverse () -{ pos.XReverse(); } - -inline void gp_Pln::VReverse () -{ pos.YReverse(); } - -inline Standard_Boolean gp_Pln::Direct()const -{ return pos.Direct(); } - -inline const gp_Ax1& gp_Pln::Axis() const -{ return pos.Axis(); } - -inline const gp_Pnt& gp_Pln::Location() const -{ return pos.Location(); } - -inline const gp_Ax3& gp_Pln::Position() const -{ return pos; } - -inline Standard_Real gp_Pln::Distance(const gp_Pnt& P) const -{ - const gp_Pnt& loc = pos.Location (); - const gp_Dir& dir = pos.Direction(); - Standard_Real D = (dir.X() * (P.X() - loc.X()) + - dir.Y() * (P.Y() - loc.Y()) + - dir.Z() * (P.Z() - loc.Z())); - if (D < 0) D = - D; - return D; -} - -inline Standard_Real gp_Pln::Distance (const gp_Lin& L) const -{ - Standard_Real D = 0.0; - if ((pos.Direction()).IsNormal (L.Direction(), gp::Resolution())) { - const gp_Pnt& P = L .Location (); - const gp_Pnt& loc = pos.Location (); - const gp_Dir& dir = pos.Direction(); - D = (dir.X() * (P.X() - loc.X()) + - dir.Y() * (P.Y() - loc.Y()) + - dir.Z() * (P.Z() - loc.Z())); - if (D < 0) D = - D; - } - return D; -} - -inline Standard_Real gp_Pln::Distance(const gp_Pln& Other) const -{ - Standard_Real D = 0.0; - if ((pos.Direction()).IsParallel(Other.pos.Direction(), gp::Resolution())){ - const gp_Pnt& P = Other.pos.Location(); - const gp_Pnt& loc = pos.Location (); - const gp_Dir& dir = pos.Direction(); - D = (dir.X() * (P.X() - loc.X()) + - dir.Y() * (P.Y() - loc.Y()) + - dir.Z() * (P.Z() - loc.Z())); - if (D < 0) D = - D; - } - return D; -} - -inline Standard_Real gp_Pln::SquareDistance (const gp_Pnt& P) const -{ Standard_Real D = Distance(P); return D * D; } - -inline Standard_Real gp_Pln::SquareDistance (const gp_Lin& L) const -{ Standard_Real D = Distance(L); return D * D; } - -inline Standard_Real gp_Pln::SquareDistance (const gp_Pln& Other) const -{ Standard_Real D = Distance(Other); return D * D; } - -inline gp_Ax1 gp_Pln::XAxis () const -{ return gp_Ax1 (pos.Location(), pos.XDirection()); } - -inline gp_Ax1 gp_Pln::YAxis () const -{ return gp_Ax1 (pos.Location(), pos.YDirection()); } - -inline Standard_Boolean gp_Pln::Contains -(const gp_Pnt& P, - const Standard_Real LinearTolerance) const -{ return Distance(P) <= LinearTolerance; } - -inline Standard_Boolean gp_Pln::Contains -(const gp_Lin& L, - const Standard_Real LinearTolerance, - const Standard_Real AngularTolerance) const -{ return Contains(L.Location(), LinearTolerance) && - pos.Direction().IsNormal(L.Direction(), AngularTolerance); -} - -inline void gp_Pln::Rotate (const gp_Ax1& A1, const Standard_Real Ang) -{ pos.Rotate(A1, Ang); } - -inline gp_Pln gp_Pln::Rotated (const gp_Ax1& A1, - const Standard_Real Ang) const -{ - gp_Pln Pl = *this; - Pl.pos.Rotate(A1, Ang); - return Pl; -} - -inline void gp_Pln::Scale (const gp_Pnt& P, const Standard_Real S) -{ pos.Scale(P, S); } - -inline gp_Pln gp_Pln::Scaled (const gp_Pnt& P, - const Standard_Real S) const -{ - gp_Pln Pl = *this; - Pl.pos.Scale(P, S); - return Pl; -} - -inline void gp_Pln::Transform (const gp_Trsf& T) -{ pos.Transform(T); } - -inline gp_Pln gp_Pln::Transformed (const gp_Trsf& T) const -{ - gp_Pln Pl = *this; - Pl.pos.Transform(T); - return Pl; -} - -inline void gp_Pln::Translate (const gp_Vec& V) -{ pos.Translate(V); } - -inline gp_Pln gp_Pln::Translated (const gp_Vec& V) const -{ - gp_Pln Pl = *this; - Pl.pos.Translate(V); - return Pl; -} - -inline void gp_Pln::Translate (const gp_Pnt& P1, const gp_Pnt& P2) -{ pos.Translate(P1,P2); } - -inline gp_Pln gp_Pln::Translated (const gp_Pnt& P1, - const gp_Pnt& P2) const -{ - gp_Pln Pl = *this; - Pl.pos.Translate(P1, P2); - return Pl; -} - diff --git a/src/gp/gp_Pnt.cxx b/src/gp/gp_Pnt.cxx index 8929df71ea..94b38b69f0 100644 --- a/src/gp/gp_Pnt.cxx +++ b/src/gp/gp_Pnt.cxx @@ -18,10 +18,10 @@ #define No_Standard_OutOfRange +#include #include #include -#include #include #include #include diff --git a/src/gp/gp_Pnt.hxx b/src/gp/gp_Pnt.hxx index 5f6e396c1a..a80f5db62f 100644 --- a/src/gp/gp_Pnt.hxx +++ b/src/gp/gp_Pnt.hxx @@ -18,19 +18,18 @@ #include #include #include - #include #include #include #include -class Standard_OutOfRange; + class gp_XYZ; +class Standard_OutOfRange; class gp_Ax1; class gp_Ax2; class gp_Trsf; class gp_Vec; - //! Defines a 3D cartesian point. class gp_Pnt { @@ -38,141 +37,173 @@ public: DEFINE_STANDARD_ALLOC - //! Creates a point with zero coordinates. - gp_Pnt(); - + gp_Pnt() {} + //! Creates a point from a XYZ object. - gp_Pnt(const gp_XYZ& Coord); - + gp_Pnt (const gp_XYZ& theCoord) + : coord (theCoord) + {} - //! Creates a point with its 3 cartesian's coordinates : Xp, Yp, Zp. - gp_Pnt(const Standard_Real Xp, const Standard_Real Yp, const Standard_Real Zp); - + //! Creates a point with its 3 cartesian's coordinates : theXp, theYp, theZp. + gp_Pnt (const Standard_Real theXp, const Standard_Real theYp, const Standard_Real theZp) + : coord (theXp, theYp, theZp) + {} + + //! Changes the coordinate of range theIndex : + //! theIndex = 1 => X is modified + //! theIndex = 2 => Y is modified + //! theIndex = 3 => Z is modified + //! Raised if theIndex != {1, 2, 3}. + void SetCoord (const Standard_Integer theIndex, const Standard_Real theXi) + { + coord.SetCoord (theIndex, theXi); + } + + //! For this point, assigns the values theXp, theYp and theZp to its three coordinates. + void SetCoord (const Standard_Real theXp, const Standard_Real theYp, const Standard_Real theZp) + { + coord.SetCoord (theXp, theYp, theZp); + } - //! Changes the coordinate of range Index : - //! Index = 1 => X is modified - //! Index = 2 => Y is modified - //! Index = 3 => Z is modified - //! Raised if Index != {1, 2, 3}. - void SetCoord (const Standard_Integer Index, const Standard_Real Xi); - - //! For this point, assigns the values Xp, Yp and Zp to its three coordinates. - void SetCoord (const Standard_Real Xp, const Standard_Real Yp, const Standard_Real Zp); - //! Assigns the given value to the X coordinate of this point. - void SetX (const Standard_Real X); - - //! Assigns the given value to the Y coordinate of this point. - void SetY (const Standard_Real Y); - - //! Assigns the given value to the Z coordinate of this point. - void SetZ (const Standard_Real Z); - - //! Assigns the three coordinates of Coord to this point. - void SetXYZ (const gp_XYZ& Coord); - + void SetX (const Standard_Real theX) { coord.SetX (theX); } + + //! Assigns the given value to the Y coordinate of this point. + void SetY (const Standard_Real theY) { coord.SetY (theY); } + + //! Assigns the given value to the Z coordinate of this point. + void SetZ (const Standard_Real theZ) { coord.SetZ (theZ); } + + //! Assigns the three coordinates of theCoord to this point. + void SetXYZ (const gp_XYZ& theCoord) { coord = theCoord; } + + //! Returns the coordinate of corresponding to the value of theIndex : + //! theIndex = 1 => X is returned + //! theIndex = 2 => Y is returned + //! theIndex = 3 => Z is returned + //! Raises OutOfRange if theIndex != {1, 2, 3}. + //! Raised if theIndex != {1, 2, 3}. + Standard_Real Coord (const Standard_Integer theIndex) const { return coord.Coord (theIndex); } + + //! For this point gives its three coordinates theXp, theYp and theZp. + void Coord (Standard_Real& theXp, Standard_Real& theYp, Standard_Real& theZp) const + { + coord.Coord (theXp, theYp, theZp); + } - //! Returns the coordinate of corresponding to the value of Index : - //! Index = 1 => X is returned - //! Index = 2 => Y is returned - //! Index = 3 => Z is returned - //! Raises OutOfRange if Index != {1, 2, 3}. - //! Raised if Index != {1, 2, 3}. - Standard_Real Coord (const Standard_Integer Index) const; - - //! For this point gives its three coordinates Xp, Yp and Zp. - void Coord (Standard_Real& Xp, Standard_Real& Yp, Standard_Real& Zp) const; - //! For this point, returns its X coordinate. - Standard_Real X() const; - + Standard_Real X() const { return coord.X(); } + //! For this point, returns its Y coordinate. - Standard_Real Y() const; - + Standard_Real Y() const { return coord.Y(); } + //! For this point, returns its Z coordinate. - Standard_Real Z() const; - + Standard_Real Z() const { return coord.Z(); } + //! For this point, returns its three coordinates as a XYZ object. - const gp_XYZ& XYZ() const; - + const gp_XYZ& XYZ() const { return coord; } + //! For this point, returns its three coordinates as a XYZ object. - const gp_XYZ& Coord() const; - + const gp_XYZ& Coord() const { return coord; } //! Returns the coordinates of this point. //! Note: This syntax allows direct modification of the returned value. - gp_XYZ& ChangeCoord(); - + gp_XYZ& ChangeCoord() { return coord; } + //! Assigns the result of the following expression to this point - //! (Alpha*this + Beta*P) / (Alpha + Beta) - void BaryCenter (const Standard_Real Alpha, const gp_Pnt& P, const Standard_Real Beta); - + //! (theAlpha*this + theBeta*theP) / (theAlpha + theBeta) + void BaryCenter (const Standard_Real theAlpha, const gp_Pnt& theP, const Standard_Real theBeta) + { + coord.SetLinearForm (theAlpha, coord, theBeta, theP.coord); + coord.Divide (theAlpha + theBeta); + } + //! Comparison //! Returns True if the distance between the two points is - //! lower or equal to LinearTolerance. - Standard_Boolean IsEqual (const gp_Pnt& Other, const Standard_Real LinearTolerance) const; - + //! lower or equal to theLinearTolerance. + Standard_Boolean IsEqual (const gp_Pnt& theOther, const Standard_Real theLinearTolerance) const + { + return Distance (theOther) <= theLinearTolerance; + } + //! Computes the distance between two points. - Standard_Real Distance (const gp_Pnt& Other) const; - + Standard_Real Distance (const gp_Pnt& theOther) const; + //! Computes the square distance between two points. - Standard_Real SquareDistance (const gp_Pnt& Other) const; - + Standard_Real SquareDistance (const gp_Pnt& theOther) const; //! Performs the symmetrical transformation of a point - //! with respect to the point P which is the center of + //! with respect to the point theP which is the center of //! the symmetry. - Standard_EXPORT void Mirror (const gp_Pnt& P); - + Standard_EXPORT void Mirror (const gp_Pnt& theP); //! Performs the symmetrical transformation of a point //! with respect to an axis placement which is the axis //! of the symmetry. - Standard_NODISCARD Standard_EXPORT gp_Pnt Mirrored (const gp_Pnt& P) const; - - Standard_EXPORT void Mirror (const gp_Ax1& A1); - + Standard_NODISCARD Standard_EXPORT gp_Pnt Mirrored (const gp_Pnt& theP) const; + + Standard_EXPORT void Mirror (const gp_Ax1& theA1); //! Performs the symmetrical transformation of a point - //! with respect to a plane. The axis placement A2 locates + //! with respect to a plane. The axis placement theA2 locates //! the plane of the symmetry : (Location, XDirection, YDirection). - Standard_NODISCARD Standard_EXPORT gp_Pnt Mirrored (const gp_Ax1& A1) const; - - Standard_EXPORT void Mirror (const gp_Ax2& A2); - + Standard_NODISCARD Standard_EXPORT gp_Pnt Mirrored (const gp_Ax1& theA1) const; + + Standard_EXPORT void Mirror (const gp_Ax2& theA2); + + //! Rotates a point. theA1 is the axis of the rotation. + //! theAng is the angular value of the rotation in radians. + Standard_NODISCARD Standard_EXPORT gp_Pnt Mirrored (const gp_Ax2& theA2) const; + + void Rotate (const gp_Ax1& theA1, const Standard_Real theAng); + + Standard_NODISCARD gp_Pnt Rotated (const gp_Ax1& theA1, const Standard_Real theAng) const + { + gp_Pnt aP = *this; + aP.Rotate (theA1, theAng); + return aP; + } + + //! Scales a point. theS is the scaling value. + void Scale (const gp_Pnt& theP, const Standard_Real theS); + + Standard_NODISCARD gp_Pnt Scaled (const gp_Pnt& theP, const Standard_Real theS) const + { + gp_Pnt aPres = *this; + aPres.Scale (theP, theS); + return aPres; + } - //! Rotates a point. A1 is the axis of the rotation. - //! Ang is the angular value of the rotation in radians. - Standard_NODISCARD Standard_EXPORT gp_Pnt Mirrored (const gp_Ax2& A2) const; - - void Rotate (const gp_Ax1& A1, const Standard_Real Ang); - - //! Scales a point. S is the scaling value. - Standard_NODISCARD gp_Pnt Rotated (const gp_Ax1& A1, const Standard_Real Ang) const; - - void Scale (const gp_Pnt& P, const Standard_Real S); - //! Transforms a point with the transformation T. - Standard_NODISCARD gp_Pnt Scaled (const gp_Pnt& P, const Standard_Real S) const; - - Standard_EXPORT void Transform (const gp_Trsf& T); - + Standard_EXPORT void Transform (const gp_Trsf& theT); - //! Translates a point in the direction of the vector V. + Standard_NODISCARD gp_Pnt Transformed (const gp_Trsf& theT) const + { + gp_Pnt aP = *this; + aP.Transform (theT); + return aP; + } + + //! Translates a point in the direction of the vector theV. //! The magnitude of the translation is the vector's magnitude. - Standard_NODISCARD gp_Pnt Transformed (const gp_Trsf& T) const; - - void Translate (const gp_Vec& V); - + void Translate (const gp_Vec& theV); - //! Translates a point from the point P1 to the point P2. - Standard_NODISCARD gp_Pnt Translated (const gp_Vec& V) const; - - void Translate (const gp_Pnt& P1, const gp_Pnt& P2); - - Standard_NODISCARD gp_Pnt Translated (const gp_Pnt& P1, const gp_Pnt& P2) const; + Standard_NODISCARD gp_Pnt Translated (const gp_Vec& theV) const; + //! Translates a point from the point theP1 to the point theP2. + void Translate (const gp_Pnt& theP1, const gp_Pnt& theP2) + { + coord.Add (theP2.coord); + coord.Subtract (theP1.coord); + } + + Standard_NODISCARD gp_Pnt Translated (const gp_Pnt& theP1, const gp_Pnt& theP2) const + { + gp_Pnt aP = *this; + aP.Translate (theP1, theP2); + return aP; + } //! Dumps the content of me into the stream Standard_EXPORT void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const; @@ -180,26 +211,85 @@ public: //! Inits the content of me from the stream Standard_EXPORT Standard_Boolean InitFromJson (const Standard_SStream& theSStream, Standard_Integer& theStreamPos); -protected: - - - - - private: - - gp_XYZ coord; - }; +#include +#include +#include -#include +//======================================================================= +//function : Distance +// purpose : +//======================================================================= +inline Standard_Real gp_Pnt::Distance (const gp_Pnt& theOther) const +{ + Standard_Real aD=0,aDD; + const gp_XYZ& aXYZ = theOther.coord; + aDD = coord.X(); aDD -= aXYZ.X(); aDD *= aDD; aD += aDD; + aDD = coord.Y(); aDD -= aXYZ.Y(); aDD *= aDD; aD += aDD; + aDD = coord.Z(); aDD -= aXYZ.Z(); aDD *= aDD; aD += aDD; + return sqrt (aD); +} +//======================================================================= +//function : SquareDistance +// purpose : +//======================================================================= +inline Standard_Real gp_Pnt::SquareDistance (const gp_Pnt& theOther) const +{ + Standard_Real aD=0, aDD; + const gp_XYZ& XYZ = theOther.coord; + aDD = coord.X(); aDD -= XYZ.X(); aDD *= aDD; aD += aDD; + aDD = coord.Y(); aDD -= XYZ.Y(); aDD *= aDD; aD += aDD; + aDD = coord.Z(); aDD -= XYZ.Z(); aDD *= aDD; aD += aDD; + return aD; +} +//======================================================================= +//function : Rotate +// purpose : +//======================================================================= +inline void gp_Pnt::Rotate (const gp_Ax1& theA1, const Standard_Real theAng) +{ + gp_Trsf aT; + aT.SetRotation (theA1, theAng); + aT.Transforms (coord); +} +//======================================================================= +//function : Scale +// purpose : +//======================================================================= +inline void gp_Pnt::Scale (const gp_Pnt& theP, const Standard_Real theS) +{ + gp_XYZ aXYZ = theP.coord; + aXYZ.Multiply (1.0 - theS); + coord.Multiply (theS); + coord.Add (aXYZ); +} +//======================================================================= +//function : Translate +// purpose : +//======================================================================= +inline void gp_Pnt::Translate(const gp_Vec& theV) +{ + coord.Add (theV.XYZ()); +} + +//======================================================================= +//function : Translated +// purpose : +//======================================================================= +inline gp_Pnt gp_Pnt::Translated (const gp_Vec& theV) const +{ + gp_Pnt aP = *this; + aP.coord.Add (theV.XYZ()); + return aP; +} #endif // _gp_Pnt_HeaderFile diff --git a/src/gp/gp_Pnt.lxx b/src/gp/gp_Pnt.lxx deleted file mode 100644 index a918b29382..0000000000 --- a/src/gp/gp_Pnt.lxx +++ /dev/null @@ -1,178 +0,0 @@ -// Copyright (c) 1995-1999 Matra Datavision -// Copyright (c) 1999-2014 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -// JCV 30/08/90 Modif passage version C++ 2.0 sur Sun -// JCV 06/12/90 Modif introduction des classes XYZ Mat dans le package gp -// Modif DPF 23/06/93 Ajout fonction Coord pour genericite 2d 3d - -#include -#include - -inline gp_Pnt::gp_Pnt() { } - -inline gp_Pnt::gp_Pnt (const gp_XYZ& Coordinates) : coord (Coordinates) -{ } - -inline gp_Pnt::gp_Pnt (const Standard_Real Xp, - const Standard_Real Yp, - const Standard_Real Zp) : coord(Xp, Yp,Zp) -{ } - -inline void gp_Pnt::SetCoord (const Standard_Integer Index, - const Standard_Real Xi) -{ coord.SetCoord (Index, Xi); } - -inline void gp_Pnt::SetCoord (const Standard_Real Xp, - const Standard_Real Yp, - const Standard_Real Zp) { - coord.SetCoord (Xp, Yp, Zp); -} - -inline void gp_Pnt::SetX (const Standard_Real X) -{ coord.SetX (X); } - -inline void gp_Pnt::SetY (const Standard_Real Y) -{ coord.SetY (Y); } - -inline void gp_Pnt::SetZ (const Standard_Real Z) -{ coord.SetZ (Z); } - -inline void gp_Pnt::SetXYZ (const gp_XYZ& Coordinates) -{ coord = Coordinates; } - -inline Standard_Real gp_Pnt::Coord (const Standard_Integer Index) const -{ return coord.Coord(Index); } - -inline void gp_Pnt::Coord (Standard_Real& Xp, - Standard_Real& Yp, - Standard_Real& Zp) const { - coord.Coord (Xp, Yp, Zp); - } - -inline Standard_Real gp_Pnt::X() const -{ return coord.X(); } - -inline Standard_Real gp_Pnt::Y() const -{ return coord.Y(); } - -inline Standard_Real gp_Pnt::Z() const -{ return coord.Z(); } - -inline const gp_XYZ& gp_Pnt::XYZ () const -{ return coord; } - -inline const gp_XYZ& gp_Pnt::Coord () const -{ return coord; } - -inline gp_XYZ& gp_Pnt::ChangeCoord () -{ return coord; } - -inline void gp_Pnt::BaryCenter(const Standard_Real A, - const gp_Pnt& P, - const Standard_Real B) -{ - coord.SetLinearForm(A,coord,B,P.coord); - coord.Divide(A + B); -} - -inline Standard_Boolean gp_Pnt::IsEqual -(const gp_Pnt& Other, - const Standard_Real LinearTolerance) const -{ return Distance (Other) <= LinearTolerance; } - -inline Standard_Real gp_Pnt::Distance (const gp_Pnt& Other) const -{ - Standard_Real d=0,dd; - const gp_XYZ& XYZ = Other.coord; - dd = coord.X(); dd -= XYZ.X(); dd *= dd; d += dd; - dd = coord.Y(); dd -= XYZ.Y(); dd *= dd; d += dd; - dd = coord.Z(); dd -= XYZ.Z(); dd *= dd; d += dd; - return(sqrt(d)); -} - -inline Standard_Real gp_Pnt::SquareDistance (const gp_Pnt& Other) const -{ - Standard_Real d=0,dd; - const gp_XYZ& XYZ = Other.coord; - dd = coord.X(); dd -= XYZ.X(); dd *= dd; d += dd; - dd = coord.Y(); dd -= XYZ.Y(); dd *= dd; d += dd; - dd = coord.Z(); dd -= XYZ.Z(); dd *= dd; d += dd; - return(d); -} - -inline void gp_Pnt::Rotate (const gp_Ax1& A1, - const Standard_Real Ang) -{ - gp_Trsf T; - T.SetRotation (A1, Ang); - T.Transforms (coord); -} - -inline gp_Pnt gp_Pnt::Rotated (const gp_Ax1& A1, - const Standard_Real Ang) const -{ - gp_Pnt P = *this; - P.Rotate (A1, Ang); - return P; -} - -inline void gp_Pnt::Scale (const gp_Pnt& P, - const Standard_Real S) -{ - gp_XYZ XYZ = P.coord; - XYZ.Multiply (1.0 - S); - coord.Multiply (S); - coord.Add (XYZ); -} - -inline gp_Pnt gp_Pnt::Scaled (const gp_Pnt& P, - const Standard_Real S) const -{ - gp_Pnt Pres = *this; - Pres.Scale (P, S); - return Pres; -} - -inline gp_Pnt gp_Pnt::Transformed (const gp_Trsf& T) const -{ - gp_Pnt P = *this; - P.Transform (T); - return P; -} - -inline void gp_Pnt::Translate (const gp_Vec& V) -{ coord.Add (V.XYZ()); } - -inline gp_Pnt gp_Pnt::Translated (const gp_Vec& V) const -{ - gp_Pnt P = *this; - P.coord.Add (V.XYZ()); - return P; -} - -inline void gp_Pnt::Translate (const gp_Pnt& P1, - const gp_Pnt& P2) -{ - coord.Add (P2.coord); - coord.Subtract (P1.coord); -} - -inline gp_Pnt gp_Pnt::Translated (const gp_Pnt& P1, - const gp_Pnt& P2) const -{ - gp_Pnt P = *this; - P.Translate (P1 , P2); - return P; -} - diff --git a/src/gp/gp_Pnt2d.cxx b/src/gp/gp_Pnt2d.cxx index 51119eb850..de1149fae4 100644 --- a/src/gp/gp_Pnt2d.cxx +++ b/src/gp/gp_Pnt2d.cxx @@ -16,9 +16,9 @@ #define No_Standard_OutOfRange +#include #include -#include #include #include #include diff --git a/src/gp/gp_Pnt2d.hxx b/src/gp/gp_Pnt2d.hxx index badbfa9137..377e39d55f 100644 --- a/src/gp/gp_Pnt2d.hxx +++ b/src/gp/gp_Pnt2d.hxx @@ -23,13 +23,13 @@ #include #include #include + class Standard_OutOfRange; class gp_XY; class gp_Ax2d; class gp_Trsf2d; class gp_Vec2d; - //! Defines a non-persistent 2D cartesian point. class gp_Pnt2d { @@ -37,145 +37,218 @@ public: DEFINE_STANDARD_ALLOC - //! Creates a point with zero coordinates. - gp_Pnt2d(); - + gp_Pnt2d() {} + //! Creates a point with a doublet of coordinates. - gp_Pnt2d(const gp_XY& Coord); - + gp_Pnt2d (const gp_XY& theCoord) + : coord (theCoord) + {} - //! Creates a point with its 2 cartesian's coordinates : Xp, Yp. - gp_Pnt2d(const Standard_Real Xp, const Standard_Real Yp); - + //! Creates a point with its 2 cartesian's coordinates : theXp, theYp. + gp_Pnt2d (const Standard_Real theXp, const Standard_Real theYp) + : coord (theXp, theYp) + {} + + //! Assigns the value Xi to the coordinate that corresponds to theIndex: + //! theIndex = 1 => X is modified + //! theIndex = 2 => Y is modified + //! Raises OutOfRange if theIndex != {1, 2}. + void SetCoord (const Standard_Integer theIndex, const Standard_Real theXi) { coord.SetCoord (theIndex, theXi); } + + //! For this point, assigns the values theXp and theYp to its two coordinates + void SetCoord (const Standard_Real theXp, const Standard_Real theYp) { coord.SetCoord (theXp, theYp); } - //! Assigns the value Xi to the coordinate that corresponds to Index: - //! Index = 1 => X is modified - //! Index = 2 => Y is modified - //! Raises OutOfRange if Index != {1, 2}. - void SetCoord (const Standard_Integer Index, const Standard_Real Xi); - - //! For this point, assigns the values Xp and Yp to its two coordinates - void SetCoord (const Standard_Real Xp, const Standard_Real Yp); - //! Assigns the given value to the X coordinate of this point. - void SetX (const Standard_Real X); - - //! Assigns the given value to the Y coordinate of this point. - void SetY (const Standard_Real Y); - - //! Assigns the two coordinates of Coord to this point. - void SetXY (const gp_XY& Coord); - + void SetX (const Standard_Real theX) { coord.SetX (theX); } + + //! Assigns the given value to the Y coordinate of this point. + void SetY (const Standard_Real theY) { coord.SetY (theY); } + + //! Assigns the two coordinates of Coord to this point. + void SetXY (const gp_XY& theCoord) { coord = theCoord; } + + //! Returns the coordinate of range theIndex : + //! theIndex = 1 => X is returned + //! theIndex = 2 => Y is returned + //! Raises OutOfRange if theIndex != {1, 2}. + Standard_Real Coord (const Standard_Integer theIndex) const { return coord.Coord (theIndex); } - //! Returns the coordinate of range Index : - //! Index = 1 => X is returned - //! Index = 2 => Y is returned - //! Raises OutOfRange if Index != {1, 2}. - Standard_Real Coord (const Standard_Integer Index) const; - //! For this point returns its two coordinates as a number pair. - void Coord (Standard_Real& Xp, Standard_Real& Yp) const; - + void Coord (Standard_Real& theXp, Standard_Real& theYp) const { coord.Coord (theXp, theYp); } + //! For this point, returns its X coordinate. - Standard_Real X() const; - + Standard_Real X() const { return coord.X(); } + //! For this point, returns its Y coordinate. - Standard_Real Y() const; - + Standard_Real Y() const { return coord.Y(); } + //! For this point, returns its two coordinates as a number pair. - const gp_XY& XY() const; - + const gp_XY& XY() const { return coord; } + //! For this point, returns its two coordinates as a number pair. - const gp_XY& Coord() const; - + const gp_XY& Coord() const { return coord; } //! Returns the coordinates of this point. //! Note: This syntax allows direct modification of the returned value. - gp_XY& ChangeCoord(); - + gp_XY& ChangeCoord() { return coord; } + //! Comparison //! Returns True if the distance between the two - //! points is lower or equal to LinearTolerance. - Standard_Boolean IsEqual (const gp_Pnt2d& Other, const Standard_Real LinearTolerance) const; - + //! points is lower or equal to theLinearTolerance. + Standard_Boolean IsEqual (const gp_Pnt2d& theOther, const Standard_Real theLinearTolerance) const + { + return Distance (theOther) <= theLinearTolerance; + } + //! Computes the distance between two points. - Standard_Real Distance (const gp_Pnt2d& Other) const; - + Standard_Real Distance (const gp_Pnt2d& theOther) const; + //! Computes the square distance between two points. - Standard_Real SquareDistance (const gp_Pnt2d& Other) const; - + Standard_Real SquareDistance (const gp_Pnt2d& theOther) const; //! Performs the symmetrical transformation of a point - //! with respect to the point P which is the center of + //! with respect to the point theP which is the center of //! the symmetry. - Standard_EXPORT void Mirror (const gp_Pnt2d& P); - + Standard_EXPORT void Mirror (const gp_Pnt2d& theP); //! Performs the symmetrical transformation of a point //! with respect to an axis placement which is the axis - Standard_NODISCARD Standard_EXPORT gp_Pnt2d Mirrored (const gp_Pnt2d& P) const; - - Standard_EXPORT void Mirror (const gp_Ax2d& A); - + Standard_NODISCARD Standard_EXPORT gp_Pnt2d Mirrored (const gp_Pnt2d& theP) const; - //! Rotates a point. A1 is the axis of the rotation. + Standard_EXPORT void Mirror (const gp_Ax2d& theA); + + Standard_NODISCARD Standard_EXPORT gp_Pnt2d Mirrored (const gp_Ax2d& theA) const; + + //! Rotates a point. theA1 is the axis of the rotation. //! Ang is the angular value of the rotation in radians. - Standard_NODISCARD Standard_EXPORT gp_Pnt2d Mirrored (const gp_Ax2d& A) const; - - void Rotate (const gp_Pnt2d& P, const Standard_Real Ang); - - //! Scales a point. S is the scaling value. - Standard_NODISCARD gp_Pnt2d Rotated (const gp_Pnt2d& P, const Standard_Real Ang) const; - - void Scale (const gp_Pnt2d& P, const Standard_Real S); - - //! Transforms a point with the transformation T. - Standard_NODISCARD gp_Pnt2d Scaled (const gp_Pnt2d& P, const Standard_Real S) const; - - Standard_EXPORT void Transform (const gp_Trsf2d& T); - + void Rotate (const gp_Pnt2d& theP, const Standard_Real theAng); - //! Translates a point in the direction of the vector V. + Standard_NODISCARD gp_Pnt2d Rotated (const gp_Pnt2d& theP, const Standard_Real theAng) const + { + gp_Pnt2d aPres = *this; + aPres.Rotate (theP, theAng); + return aPres; + } + + //! Scales a point. theS is the scaling value. + void Scale (const gp_Pnt2d& theP, const Standard_Real theS); + + Standard_NODISCARD gp_Pnt2d Scaled (const gp_Pnt2d& theP, const Standard_Real theS) const + { + gp_Pnt2d aPres = *this; + aPres.Scale (theP, theS); + return aPres; + } + + //! Transforms a point with the transformation theT. + Standard_EXPORT void Transform (const gp_Trsf2d& theT); + + Standard_NODISCARD gp_Pnt2d Transformed (const gp_Trsf2d& theT) const + { + gp_Pnt2d aPres = *this; + aPres.Transform (theT); + return aPres; + } + + //! Translates a point in the direction of the vector theV. //! The magnitude of the translation is the vector's magnitude. - Standard_NODISCARD gp_Pnt2d Transformed (const gp_Trsf2d& T) const; - - void Translate (const gp_Vec2d& V); - + void Translate (const gp_Vec2d& theV); - //! Translates a point from the point P1 to the point P2. - Standard_NODISCARD gp_Pnt2d Translated (const gp_Vec2d& V) const; - - void Translate (const gp_Pnt2d& P1, const gp_Pnt2d& P2); - - Standard_NODISCARD gp_Pnt2d Translated (const gp_Pnt2d& P1, const gp_Pnt2d& P2) const; + Standard_NODISCARD gp_Pnt2d Translated (const gp_Vec2d& theV) const; + //! Translates a point from the point theP1 to the point theP2. + void Translate (const gp_Pnt2d& theP1, const gp_Pnt2d& theP2) + { + coord.Add (theP2.coord); + coord.Subtract (theP1.coord); + } + + Standard_NODISCARD gp_Pnt2d Translated (const gp_Pnt2d& theP1, const gp_Pnt2d& theP2) const + { + gp_Pnt2d aP = *this; + aP.Translate (theP1, theP2); + return aP; + } //! Dumps the content of me into the stream - Standard_EXPORT void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const; - - - -protected: - - - - + Standard_EXPORT void DumpJson(Standard_OStream& theOStream, Standard_Integer theDepth = -1) const; private: - - gp_XY coord; - }; +#include +#include +#include -#include +//======================================================================= +//function : Distance +// purpose : +//======================================================================= +inline Standard_Real gp_Pnt2d::Distance (const gp_Pnt2d& theOther) const +{ + const gp_XY& aXY = theOther.coord; + Standard_Real aX = coord.X() - aXY.X(); + Standard_Real aY = coord.Y() - aXY.Y(); + return sqrt (aX * aX + aY * aY); +} +//======================================================================= +//function : SquareDistance +// purpose : +//======================================================================= +inline Standard_Real gp_Pnt2d::SquareDistance (const gp_Pnt2d& theOther) const +{ + const gp_XY& aXY = theOther.coord; + Standard_Real aX = coord.X() - aXY.X(); + Standard_Real aY = coord.Y() - aXY.Y(); + return (aX * aX + aY * aY); +} +//======================================================================= +//function : Rotate +// purpose : +//======================================================================= +inline void gp_Pnt2d::Rotate (const gp_Pnt2d& theP, const Standard_Real theAng) +{ + gp_Trsf2d aT; + aT.SetRotation (theP, theAng); + aT.Transforms (coord); +} +//======================================================================= +//function : Scale +// purpose : +//======================================================================= +inline void gp_Pnt2d::Scale (const gp_Pnt2d& theP, const Standard_Real theS) +{ + gp_XY aXY = theP.coord; + aXY.Multiply (1.0 - theS); + coord.Multiply (theS); + coord.Add (aXY); +} +//======================================================================= +//function : Translate +// purpose : +//======================================================================= +inline void gp_Pnt2d::Translate(const gp_Vec2d& theV) +{ + coord.Add (theV.XY()); +} + +//======================================================================= +//function : Translated +// purpose : +//======================================================================= +inline gp_Pnt2d gp_Pnt2d::Translated (const gp_Vec2d& theV) const +{ + gp_Pnt2d aP = *this; + aP.coord.Add (theV.XY()); + return aP; +} #endif // _gp_Pnt2d_HeaderFile diff --git a/src/gp/gp_Pnt2d.lxx b/src/gp/gp_Pnt2d.lxx deleted file mode 100644 index bee35ec5b1..0000000000 --- a/src/gp/gp_Pnt2d.lxx +++ /dev/null @@ -1,155 +0,0 @@ -// Copyright (c) 1995-1999 Matra Datavision -// Copyright (c) 1999-2014 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -// Modif JCV 08/01/91 modifs suite a la deuxieme revue de projet -// et introduction des classes XY, Mat2d. -// Modif DPF 23/06/93 Ajout fonction Coord pour genericite 2d 3d - -#include -#include -#include - -inline gp_Pnt2d::gp_Pnt2d (const gp_XY& Coordinates) : coord (Coordinates) -{ } - -inline gp_Pnt2d::gp_Pnt2d (const Standard_Real Xp, - const Standard_Real Yp) : coord (Xp, Yp) -{ } - -inline gp_Pnt2d::gp_Pnt2d() { } - -inline Standard_Real gp_Pnt2d::Coord(const Standard_Integer Index) const { return coord.Coord(Index); } - -inline void gp_Pnt2d::SetX (const Standard_Real X) -{ coord.SetX (X); } - -inline void gp_Pnt2d::SetY (const Standard_Real Y) -{ coord.SetY (Y); } - -inline void gp_Pnt2d::SetXY (const gp_XY& Coordinates) -{ coord = Coordinates; } - -inline void gp_Pnt2d::SetCoord (const Standard_Real Xp, - const Standard_Real Yp) -{ coord.SetCoord (Xp, Yp);} - -inline void gp_Pnt2d::SetCoord (const Standard_Integer Index, - const Standard_Real Xi) -{ coord.SetCoord (Index, Xi); } - -inline void gp_Pnt2d::Coord (Standard_Real& Xp, - Standard_Real& Yp) const -{ coord.Coord (Xp, Yp); } - -inline Standard_Real gp_Pnt2d::X() const -{ return coord.X(); } - -inline Standard_Real gp_Pnt2d::Y() const -{ return coord.Y(); } - -inline const gp_XY& gp_Pnt2d::XY () const -{ return coord; } - -inline const gp_XY& gp_Pnt2d::Coord () const -{ return coord; } - -inline gp_XY& gp_Pnt2d::ChangeCoord () -{ return coord; } - -inline Standard_Boolean gp_Pnt2d::IsEqual -(const gp_Pnt2d& Other, - const Standard_Real LinearTolerance) const -{ return Distance (Other) <= LinearTolerance; } - -inline Standard_Real gp_Pnt2d::Distance (const gp_Pnt2d& Other) const -{ - const gp_XY& XY = Other.coord; - Standard_Real X = coord.X() - XY.X(); - Standard_Real Y = coord.Y() - XY.Y(); - return sqrt (X * X + Y * Y); -} - -inline Standard_Real gp_Pnt2d::SquareDistance (const gp_Pnt2d& Other) const -{ - const gp_XY& XY = Other.coord; - Standard_Real X = coord.X() - XY.X(); - Standard_Real Y = coord.Y() - XY.Y(); - return (X * X + Y * Y); -} - -inline void gp_Pnt2d::Rotate (const gp_Pnt2d& P, - const Standard_Real Ang) -{ - gp_Trsf2d T; - T.SetRotation (P, Ang); - T.Transforms (coord); -} - -inline gp_Pnt2d gp_Pnt2d::Rotated (const gp_Pnt2d& P, - const Standard_Real Ang) const -{ - gp_Pnt2d Pres = *this; - Pres.Rotate (P, Ang); - return Pres; -} - -inline void gp_Pnt2d::Scale (const gp_Pnt2d& P, - const Standard_Real S) -{ - gp_XY XY = P.coord; - XY.Multiply (1.0 - S); - coord.Multiply (S); - coord.Add (XY); -} - -inline gp_Pnt2d gp_Pnt2d::Scaled (const gp_Pnt2d& P, - const Standard_Real S) const -{ - gp_Pnt2d Pres = *this; - Pres.Scale (P, S); - return Pres; -} - -inline gp_Pnt2d gp_Pnt2d::Transformed (const gp_Trsf2d& T) const -{ - gp_Pnt2d Pres = *this; - Pres.Transform (T); - return Pres; -} - -inline void gp_Pnt2d::Translate (const gp_Vec2d& V) -{ coord.Add (V.XY()); } - -inline gp_Pnt2d gp_Pnt2d::Translated (const gp_Vec2d& V) const -{ - gp_Pnt2d P = *this; - P.coord.Add (V.XY ()); - return P; -} - -inline void gp_Pnt2d::Translate (const gp_Pnt2d& P1, - const gp_Pnt2d& P2) -{ - coord.Add (P2.coord); - coord.Subtract (P1.coord); -} - -inline gp_Pnt2d gp_Pnt2d::Translated (const gp_Pnt2d& P1, - const gp_Pnt2d& P2) const -{ - gp_Pnt2d P = *this; - P.Translate (P1, P2); - return P; -} - diff --git a/src/gp/gp_Quaternion.cxx b/src/gp/gp_Quaternion.cxx index f98a3e99da..3b53940ac3 100644 --- a/src/gp/gp_Quaternion.cxx +++ b/src/gp/gp_Quaternion.cxx @@ -18,6 +18,7 @@ // and maths found in Wikipedia and elsewhere #include + #include #include diff --git a/src/gp/gp_Quaternion.hxx b/src/gp/gp_Quaternion.hxx index 958227ad19..2b503af711 100644 --- a/src/gp/gp_Quaternion.hxx +++ b/src/gp/gp_Quaternion.hxx @@ -16,17 +16,9 @@ #ifndef _gp_Quaternion_HeaderFile #define _gp_Quaternion_HeaderFile -#include -#include -#include - -#include -#include #include +#include #include -class gp_Vec; -class gp_Mat; - //! Represents operation of rotation in 3d space as quaternion //! and implements operations with rotations basing on @@ -41,155 +33,200 @@ public: DEFINE_STANDARD_ALLOC - //! Creates an identity quaternion - gp_Quaternion(); - + gp_Quaternion() + : x (0.0), + y (0.0), + z (0.0), + w (1.0) + {} + //! Creates quaternion directly from component values - gp_Quaternion(const Standard_Real x, const Standard_Real y, const Standard_Real z, const Standard_Real w); - + gp_Quaternion (const Standard_Real theX, const Standard_Real theY, const Standard_Real theZ, const Standard_Real theW) + : x (theX), + y (theY), + z (theZ), + w (theW) + {} + //! Creates quaternion representing shortest-arc rotation //! operator producing vector theVecTo from vector theVecFrom. - gp_Quaternion(const gp_Vec& theVecFrom, const gp_Vec& theVecTo); - + gp_Quaternion (const gp_Vec& theVecFrom, const gp_Vec& theVecTo) + { + SetRotation (theVecFrom, theVecTo); + } + //! Creates quaternion representing shortest-arc rotation //! operator producing vector theVecTo from vector theVecFrom. //! Additional vector theHelpCrossVec defines preferred direction for //! rotation and is used when theVecTo and theVecFrom are directed //! oppositely. - gp_Quaternion(const gp_Vec& theVecFrom, const gp_Vec& theVecTo, const gp_Vec& theHelpCrossVec); - + gp_Quaternion(const gp_Vec& theVecFrom, const gp_Vec& theVecTo, const gp_Vec& theHelpCrossVec) + { + SetRotation (theVecFrom, theVecTo, theHelpCrossVec); + } + //! Creates quaternion representing rotation on angle //! theAngle around vector theAxis - gp_Quaternion(const gp_Vec& theAxis, const Standard_Real theAngle); - + gp_Quaternion(const gp_Vec& theAxis, const Standard_Real theAngle) + { + SetVectorAndAngle (theAxis, theAngle); + } + //! Creates quaternion from rotation matrix 3*3 //! (which should be orthonormal skew-symmetric matrix) - gp_Quaternion(const gp_Mat& theMat); - + gp_Quaternion(const gp_Mat& theMat) + { + SetMatrix (theMat); + } + //! Simple equal test without precision Standard_EXPORT Standard_Boolean IsEqual (const gp_Quaternion& theOther) const; - + //! Sets quaternion to shortest-arc rotation producing //! vector theVecTo from vector theVecFrom. //! If vectors theVecFrom and theVecTo are opposite then rotation //! axis is computed as theVecFrom ^ (1,0,0) or theVecFrom ^ (0,0,1). Standard_EXPORT void SetRotation (const gp_Vec& theVecFrom, const gp_Vec& theVecTo); - + //! Sets quaternion to shortest-arc rotation producing //! vector theVecTo from vector theVecFrom. //! If vectors theVecFrom and theVecTo are opposite then rotation //! axis is computed as theVecFrom ^ theHelpCrossVec. Standard_EXPORT void SetRotation (const gp_Vec& theVecFrom, const gp_Vec& theVecTo, const gp_Vec& theHelpCrossVec); - + //! Create a unit quaternion from Axis+Angle representation Standard_EXPORT void SetVectorAndAngle (const gp_Vec& theAxis, const Standard_Real theAngle); - + //! Convert a quaternion to Axis+Angle representation, //! preserve the axis direction and angle from -PI to +PI Standard_EXPORT void GetVectorAndAngle (gp_Vec& theAxis, Standard_Real& theAngle) const; - + //! Create a unit quaternion by rotation matrix //! matrix must contain only rotation (not scale or shear) //! //! For numerical stability we find first the greatest component of quaternion //! and than search others from this one Standard_EXPORT void SetMatrix (const gp_Mat& theMat); - + //! Returns rotation operation as 3*3 matrix Standard_EXPORT gp_Mat GetMatrix() const; - + //! Create a unit quaternion representing rotation defined //! by generalized Euler angles Standard_EXPORT void SetEulerAngles (const gp_EulerSequence theOrder, const Standard_Real theAlpha, const Standard_Real theBeta, const Standard_Real theGamma); - + //! Returns Euler angles describing current rotation Standard_EXPORT void GetEulerAngles (const gp_EulerSequence theOrder, Standard_Real& theAlpha, Standard_Real& theBeta, Standard_Real& theGamma) const; - - void Set (const Standard_Real x, const Standard_Real y, const Standard_Real z, const Standard_Real w); - + + void Set (const Standard_Real theX, const Standard_Real theY, const Standard_Real theZ, const Standard_Real theW); + void Set (const gp_Quaternion& theQuaternion); - - Standard_Real X() const; - - Standard_Real Y() const; - - Standard_Real Z() const; - - Standard_Real W() const; - + + Standard_Real X() const { return x; } + + Standard_Real Y() const { return y; } + + Standard_Real Z() const { return z; } + + Standard_Real W() const { return w; } + //! Make identity quaternion (zero-rotation) - void SetIdent(); - + void SetIdent() + { + x = y = z = 0.0; + w = 1.0; + } + //! Reverse direction of rotation (conjugate quaternion) - void Reverse(); - + void Reverse() + { + x = -x; + y = -y; + z = -z; + } + //! Return rotation with reversed direction (conjugated quaternion) - Standard_NODISCARD gp_Quaternion Reversed() const; - + Standard_NODISCARD gp_Quaternion Reversed() const { return gp_Quaternion (-x, -y, -z, w); } + //! Inverts quaternion (both rotation direction and norm) - void Invert(); - + void Invert() + { + Standard_Real anIn = 1.0 / SquareNorm(); + Set (-x * anIn, -y * anIn, -z * anIn, w * anIn); + } + //! Return inversed quaternion q^-1 - Standard_NODISCARD gp_Quaternion Inverted() const; - + Standard_NODISCARD gp_Quaternion Inverted() const + { + Standard_Real anIn = 1.0 / SquareNorm(); + return gp_Quaternion (-x * anIn, -y * anIn, -z * anIn, w * anIn); + } + //! Returns square norm of quaternion - Standard_Real SquareNorm() const; - + Standard_Real SquareNorm() const + { + return x * x + y * y + z * z + w * w; + } + //! Returns norm of quaternion - Standard_Real Norm() const; - + Standard_Real Norm() const { return Sqrt (SquareNorm()); } + //! Scale all components by quaternion by theScale; note that //! rotation is not changed by this operation (except 0-scaling) void Scale (const Standard_Real theScale); -void operator *= (const Standard_Real theScale) -{ - Scale(theScale); -} - + + void operator *= (const Standard_Real theScale) { Scale (theScale); } + //! Returns scaled quaternion -Standard_NODISCARD gp_Quaternion Scaled (const Standard_Real theScale) const; -Standard_NODISCARD gp_Quaternion operator * (const Standard_Real theScale) const -{ - return Scaled(theScale); -} - + Standard_NODISCARD gp_Quaternion Scaled (const Standard_Real theScale) const + { + return gp_Quaternion (x * theScale, y * theScale, z * theScale, w * theScale); + } + + Standard_NODISCARD gp_Quaternion operator * (const Standard_Real theScale) const { return Scaled (theScale); } + //! Stabilize quaternion length within 1 - 1/4. //! This operation is a lot faster than normalization //! and preserve length goes to 0 or infinity Standard_EXPORT void StabilizeLength(); - + //! Scale quaternion that its norm goes to 1. //! The appearing of 0 magnitude or near is a error, //! so we can be sure that can divide by magnitude Standard_EXPORT void Normalize(); - + //! Returns quaternion scaled so that its norm goes to 1. - Standard_NODISCARD gp_Quaternion Normalized() const; - + Standard_NODISCARD gp_Quaternion Normalized() const + { + gp_Quaternion aNormilizedQ (*this); + aNormilizedQ.Normalize(); + return aNormilizedQ; + } + //! Returns quaternion with all components negated. //! Note that this operation does not affect neither //! rotation operator defined by quaternion nor its norm. - Standard_NODISCARD gp_Quaternion Negated() const; -Standard_NODISCARD gp_Quaternion operator -() const -{ - return Negated(); -} - + Standard_NODISCARD gp_Quaternion Negated() const { return gp_Quaternion (-x, -y, -z, -w); } + + Standard_NODISCARD gp_Quaternion operator -() const { return Negated(); } + //! Makes sum of quaternion components; result is "rotations mix" -Standard_NODISCARD gp_Quaternion Added (const gp_Quaternion& theOther) const; -Standard_NODISCARD gp_Quaternion operator + (const gp_Quaternion& theOther) const -{ - return Added(theOther); -} - + Standard_NODISCARD gp_Quaternion Added (const gp_Quaternion& theOther) const + { + return gp_Quaternion (x + theOther.x, y + theOther.y, z + theOther.z, w + theOther.w); + } + + Standard_NODISCARD gp_Quaternion operator + (const gp_Quaternion& theOther) const { return Added (theOther); } + //! Makes difference of quaternion components; result is "rotations mix" -Standard_NODISCARD gp_Quaternion Subtracted (const gp_Quaternion& theOther) const; -Standard_NODISCARD gp_Quaternion operator - (const gp_Quaternion& theOther) const -{ - return Subtracted(theOther); -} - + Standard_NODISCARD gp_Quaternion Subtracted (const gp_Quaternion& theOther) const + { + return gp_Quaternion (x - theOther.x, y - theOther.y, z - theOther.z, w - theOther.w); + } + + Standard_NODISCARD gp_Quaternion operator - (const gp_Quaternion& theOther) const { return Subtracted (theOther); } + //! Multiply function - work the same as Matrices multiplying. //! @code //! qq' = (cross(v,v') + wv' + w'v, ww' - dot(v,v')) @@ -200,72 +237,123 @@ Standard_NODISCARD gp_Quaternion operator - (const gp_Quaternion& theOther) cons //! qq' != q'q; //! qq^-1 = q; //! @endcode -Standard_NODISCARD gp_Quaternion Multiplied (const gp_Quaternion& theOther) const; -Standard_NODISCARD gp_Quaternion operator * (const gp_Quaternion& theOther) const -{ - return Multiplied(theOther); -} - + Standard_NODISCARD gp_Quaternion Multiplied (const gp_Quaternion& theOther) const; + + Standard_NODISCARD gp_Quaternion operator * (const gp_Quaternion& theOther) const { return Multiplied (theOther); } + //! Adds components of other quaternion; result is "rotations mix" void Add (const gp_Quaternion& theOther); -void operator += (const gp_Quaternion& theOther) -{ - Add(theOther); -} - + + void operator += (const gp_Quaternion& theOther) { Add (theOther); } + //! Subtracts components of other quaternion; result is "rotations mix" void Subtract (const gp_Quaternion& theOther); -void operator -= (const gp_Quaternion& theOther) -{ - Subtract(theOther); -} - + + void operator -= (const gp_Quaternion& theOther) { Subtract (theOther); } + //! Adds rotation by multiplication - void Multiply (const gp_Quaternion& theOther); -void operator *= (const gp_Quaternion& theOther) -{ - Multiply(theOther); -} - + void Multiply (const gp_Quaternion& theOther) + { + (*this) = Multiplied (theOther); // have no optimization here + } + + void operator *= (const gp_Quaternion& theOther) { Multiply (theOther); } + //! Computes inner product / scalar product / Dot - Standard_Real Dot (const gp_Quaternion& theOther) const; - + Standard_Real Dot (const gp_Quaternion& theOther) const + { + return x * theOther.x + y * theOther.y + z * theOther.z + w * theOther.w; + } + //! Return rotation angle from -PI to PI Standard_EXPORT Standard_Real GetRotationAngle() const; - + //! Rotates vector by quaternion as rotation operator Standard_EXPORT gp_Vec Multiply (const gp_Vec& theVec) const; -gp_Vec operator * (const gp_Vec& theVec) const -{ - return Multiply(theVec); -} - - - - -protected: - - - + gp_Vec operator * (const gp_Vec& theVec) const { return Multiply (theVec); } private: - - Standard_Real x; Standard_Real y; Standard_Real z; Standard_Real w; - }; +//======================================================================= +//function : Set +//purpose : +//======================================================================= +inline void gp_Quaternion::Set (Standard_Real theX, Standard_Real theY, + Standard_Real theZ, Standard_Real theW) +{ + this->x = theX; + this->y = theY; + this->z = theZ; + this->w = theW; +} -#include +//======================================================================= +//function : Set +//purpose : +//======================================================================= +inline void gp_Quaternion::Set (const gp_Quaternion& theQuaternion) +{ + x = theQuaternion.x; + y = theQuaternion.y; + z = theQuaternion.z; + w = theQuaternion.w; +} +//======================================================================= +//function : Scale +//purpose : +//======================================================================= +inline void gp_Quaternion::Scale (const Standard_Real theScale) +{ + x *= theScale; + y *= theScale; + z *= theScale; + w *= theScale; +} +//======================================================================= +//function : Multiplied +//purpose : +//======================================================================= +inline gp_Quaternion gp_Quaternion::Multiplied (const gp_Quaternion& theQ) const +{ + return gp_Quaternion (w * theQ.x + x * theQ.w + y * theQ.z - z * theQ.y, + w * theQ.y + y * theQ.w + z * theQ.x - x * theQ.z, + w * theQ.z + z * theQ.w + x * theQ.y - y * theQ.x, + w * theQ.w - x * theQ.x - y * theQ.y - z * theQ.z); + // 16 multiplications 12 addidtions 0 variables +} +//======================================================================= +//function : Add +//purpose : +//======================================================================= +inline void gp_Quaternion::Add (const gp_Quaternion& theQ) +{ + x += theQ.x; + y += theQ.y; + z += theQ.z; + w += theQ.w; +} +//======================================================================= +//function : Subtract +//purpose : +//======================================================================= +inline void gp_Quaternion::Subtract (const gp_Quaternion& theQ) +{ + x -= theQ.x; + y -= theQ.y; + z -= theQ.z; + w -= theQ.w; +} #endif // _gp_Quaternion_HeaderFile diff --git a/src/gp/gp_Quaternion.lxx b/src/gp/gp_Quaternion.lxx deleted file mode 100644 index 3e6273eaf5..0000000000 --- a/src/gp/gp_Quaternion.lxx +++ /dev/null @@ -1,341 +0,0 @@ -// Copyright (c) 1999-2014 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -//======================================================================= -//function : gp_Quaternion -//purpose : -//======================================================================= - -inline gp_Quaternion::gp_Quaternion() -: x(0.0), y(0.0), z(0.0), w(1.0) -{ -} - -//======================================================================= -//function : gp_Quaternion -//purpose : -//======================================================================= - -inline gp_Quaternion::gp_Quaternion (const Standard_Real theX, const Standard_Real theY, - const Standard_Real theZ, const Standard_Real theW) -: x(theX), y(theY), z(theZ), w(theW) -{ -} - -//======================================================================= -//function : gp_Quaternion -//purpose : -//======================================================================= - -inline gp_Quaternion::gp_Quaternion (const gp_Vec& theVecFrom, const gp_Vec& theVecTo) -{ - SetRotation (theVecFrom, theVecTo); -} - -//======================================================================= -//function : gp_Quaternion -//purpose : -//======================================================================= - -inline gp_Quaternion::gp_Quaternion (const gp_Vec& theVecFrom, const gp_Vec& theVecTo, const gp_Vec& theHelpCrossVec) -{ - SetRotation (theVecFrom, theVecTo, theHelpCrossVec); -} - -//======================================================================= -//function : gp_Quaternion -//purpose : -//======================================================================= - -inline gp_Quaternion::gp_Quaternion (const gp_Vec& theAxis, const Standard_Real theAngle) -{ - SetVectorAndAngle (theAxis, theAngle); -} - -//======================================================================= -//function : gp_Quaternion -//purpose : -//======================================================================= - -inline gp_Quaternion::gp_Quaternion (const gp_Mat& theMat) -{ - SetMatrix (theMat); -} - -//======================================================================= -//function : Set -//purpose : -//======================================================================= - -inline void gp_Quaternion::Set (Standard_Real theX, Standard_Real theY, - Standard_Real theZ, Standard_Real theW) -{ - this->x = theX; - this->y = theY; - this->z = theZ; - this->w = theW; -} - -//======================================================================= -//function : Set -//purpose : -//======================================================================= - -inline void gp_Quaternion::Set (const gp_Quaternion& theQuaternion) -{ - x = theQuaternion.x; - y = theQuaternion.y; - z = theQuaternion.z; - w = theQuaternion.w; -} - -//======================================================================= -//function : X -//purpose : -//======================================================================= - -inline Standard_Real gp_Quaternion::X() const -{ - return x; -} - -//======================================================================= -//function : Y -//purpose : -//======================================================================= - -inline Standard_Real gp_Quaternion::Y() const -{ - return y; -} - -//======================================================================= -//function : Z -//purpose : -//======================================================================= - -inline Standard_Real gp_Quaternion::Z() const -{ - return z; -} - -//======================================================================= -//function : W -//purpose : -//======================================================================= - -inline Standard_Real gp_Quaternion::W() const -{ - return w; -} - -//======================================================================= -//function : SetIdent -//purpose : -//======================================================================= - -inline void gp_Quaternion::SetIdent() -{ - x = y = z = 0.0; - w = 1.0; -} - -//======================================================================= -//function : Reverse -//purpose : -//======================================================================= - -inline void gp_Quaternion::Reverse() -{ - x = -x; - y = -y; - z = -z; -} - -//======================================================================= -//function : Reversed -//purpose : -//======================================================================= - -inline gp_Quaternion gp_Quaternion::Reversed() const -{ - return gp_Quaternion (-x, -y, -z, w); -} - -//======================================================================= -//function : Scale -//purpose : -//======================================================================= - -inline void gp_Quaternion::Scale (const Standard_Real theScale) -{ - x *= theScale; - y *= theScale; - z *= theScale; - w *= theScale; -} - -//======================================================================= -//function : Scaled -//purpose : -//======================================================================= - -inline gp_Quaternion gp_Quaternion::Scaled (const Standard_Real theScale) const -{ - return gp_Quaternion (x * theScale, y * theScale, z * theScale, w * theScale); -} - -//======================================================================= -//function : SquareNorm -//purpose : -//======================================================================= - -inline Standard_Real gp_Quaternion::SquareNorm() const -{ - return x * x + y * y + z * z + w * w; -} - -//======================================================================= -//function : Norm -//purpose : -//======================================================================= - -inline Standard_Real gp_Quaternion::Norm() const -{ - return Sqrt (SquareNorm()); -} - -//======================================================================= -//function : Invert -//purpose : -//======================================================================= - -inline void gp_Quaternion::Invert() -{ - Standard_Real in = 1.0 / SquareNorm(); - Set (-x * in, -y * in, -z * in, w * in); -} - -//======================================================================= -//function : Inverted -//purpose : -//======================================================================= - -inline gp_Quaternion gp_Quaternion::Inverted() const -{ - Standard_Real in = 1.0 / SquareNorm(); - return gp_Quaternion (-x * in, -y * in, -z * in, w * in); -} - -//======================================================================= -//function : Normalized -//purpose : -//======================================================================= - -inline gp_Quaternion gp_Quaternion::Normalized() const -{ - gp_Quaternion aNormilizedQ (*this); - aNormilizedQ.Normalize(); - return aNormilizedQ; -} - -//======================================================================= -//function : Negated -//purpose : -//======================================================================= - -inline gp_Quaternion gp_Quaternion::Negated () const -{ - return gp_Quaternion (-x, -y, -z, -w); -} - -//======================================================================= -//function : Added -//purpose : -//======================================================================= - -inline gp_Quaternion gp_Quaternion::Added (const gp_Quaternion& theQ) const -{ - return gp_Quaternion (x + theQ.x, y + theQ.y, z + theQ.z, w + theQ.w); -} - -//======================================================================= -//function : Subtracted -//purpose : -//======================================================================= - -inline gp_Quaternion gp_Quaternion::Subtracted (const gp_Quaternion& theQ) const -{ - return gp_Quaternion (x - theQ.x, y - theQ.y, z - theQ.z, w - theQ.w); -} - -//======================================================================= -//function : Multiplied -//purpose : -//======================================================================= - -inline gp_Quaternion gp_Quaternion::Multiplied (const gp_Quaternion& theQ) const -{ - return gp_Quaternion (w * theQ.x + x * theQ.w + y * theQ.z - z * theQ.y, - w * theQ.y + y * theQ.w + z * theQ.x - x * theQ.z, - w * theQ.z + z * theQ.w + x * theQ.y - y * theQ.x, - w * theQ.w - x * theQ.x - y * theQ.y - z * theQ.z); - // 16 multiplications 12 addidtions 0 variables -} - -//======================================================================= -//function : Add -//purpose : -//======================================================================= - -inline void gp_Quaternion::Add (const gp_Quaternion& theQ) -{ - x += theQ.x; - y += theQ.y; - z += theQ.z; - w += theQ.w; -} - -//======================================================================= -//function : Subtract -//purpose : -//======================================================================= - -inline void gp_Quaternion::Subtract (const gp_Quaternion& theQ) -{ - x -= theQ.x; - y -= theQ.y; - z -= theQ.z; - w -= theQ.w; -} - -//======================================================================= -//function : Multiply -//purpose : -//======================================================================= - -inline void gp_Quaternion::Multiply (const gp_Quaternion& theQ) -{ - (*this) = Multiplied (theQ); // have no optimization here -} - -//======================================================================= -//function : Dot -//purpose : -//======================================================================= - -inline Standard_Real gp_Quaternion::Dot (const gp_Quaternion& theQ) const -{ - return x * theQ.x + y * theQ.y + z * theQ.z + w * theQ.w; -} - diff --git a/src/gp/gp_Sphere.cxx b/src/gp/gp_Sphere.cxx index 9efcba15c7..0ce1aad59a 100644 --- a/src/gp/gp_Sphere.cxx +++ b/src/gp/gp_Sphere.cxx @@ -12,12 +12,12 @@ // Alternatively, this file may be used under the terms of Open CASCADE // commercial license or contractual agreement. +#include #include #include #include #include -#include #include #include #include diff --git a/src/gp/gp_Sphere.hxx b/src/gp/gp_Sphere.hxx index 17cd6e5a15..e7e08c7aab 100644 --- a/src/gp/gp_Sphere.hxx +++ b/src/gp/gp_Sphere.hxx @@ -15,23 +15,9 @@ #ifndef _gp_Sphere_HeaderFile #define _gp_Sphere_HeaderFile -#include -#include -#include - -#include -#include -#include #include -class Standard_ConstructionError; -class gp_Ax3; -class gp_Pnt; -class gp_Ax1; -class gp_Ax2; -class gp_Trsf; -class gp_Vec; - - +#include +#include //! Describes a sphere. //! A sphere is defined by its radius and positioned in space @@ -59,156 +45,224 @@ public: DEFINE_STANDARD_ALLOC - //! Creates an indefinite sphere. - gp_Sphere(); - + gp_Sphere() + : radius (RealLast()) + {} - //! Constructs a sphere with radius Radius, centered on the origin - //! of A3. A3 is the local coordinate system of the sphere. + //! Constructs a sphere with radius theRadius, centered on the origin + //! of theA3. theA3 is the local coordinate system of the sphere. //! Warnings : //! It is not forbidden to create a sphere with null radius. - //! Raises ConstructionError if Radius < 0.0 - gp_Sphere(const gp_Ax3& A3, const Standard_Real Radius); - + //! Raises ConstructionError if theRadius < 0.0 + gp_Sphere (const gp_Ax3& theA3, const Standard_Real theRadius) + : pos (theA3), + radius (theRadius) + { + Standard_ConstructionError_Raise_if (theRadius < 0.0, "gp_Sphere() - radius should be >= 0"); + } + //! Changes the center of the sphere. - void SetLocation (const gp_Pnt& Loc); - + void SetLocation (const gp_Pnt& theLoc) { pos.SetLocation (theLoc); } + //! Changes the local coordinate system of the sphere. - void SetPosition (const gp_Ax3& A3); - - //! Assigns R the radius of the Sphere. + void SetPosition (const gp_Ax3& theA3) { pos = theA3; } + + //! Assigns theR the radius of the Sphere. //! Warnings : //! It is not forbidden to create a sphere with null radius. - //! Raises ConstructionError if R < 0.0 - void SetRadius (const Standard_Real R); - + //! Raises ConstructionError if theR < 0.0 + void SetRadius (const Standard_Real theR) + { + Standard_ConstructionError_Raise_if (theR < 0.0, "gp_Sphere::SetRadius() - radius should be >= 0"); + radius = theR; + } //! Computes the area of the sphere. - Standard_Real Area() const; - + Standard_Real Area() const + { + return 4.0 * M_PI * radius * radius; + } //! Computes the coefficients of the implicit equation of the quadric //! in the absolute cartesian coordinates system : //! @code - //! A1.X**2 + A2.Y**2 + A3.Z**2 + 2.(B1.X.Y + B2.X.Z + B3.Y.Z) + - //! 2.(C1.X + C2.Y + C3.Z) + D = 0.0 + //! theA1.X**2 + theA2.Y**2 + theA3.Z**2 + 2.(theB1.X.Y + theB2.X.Z + theB3.Y.Z) + + //! 2.(theC1.X + theC2.Y + theC3.Z) + theD = 0.0 //! @endcode - Standard_EXPORT void Coefficients (Standard_Real& A1, Standard_Real& A2, Standard_Real& A3, Standard_Real& B1, Standard_Real& B2, Standard_Real& B3, Standard_Real& C1, Standard_Real& C2, Standard_Real& C3, Standard_Real& D) const; - + Standard_EXPORT void Coefficients (Standard_Real& theA1, Standard_Real& theA2, Standard_Real& theA3, + Standard_Real& theB1, Standard_Real& theB2, Standard_Real& theB3, + Standard_Real& theC1, Standard_Real& theC2, Standard_Real& theC3, Standard_Real& theD) const; + //! Reverses the U parametrization of the sphere //! reversing the YAxis. - void UReverse(); - + void UReverse() { pos.YReverse(); } + //! Reverses the V parametrization of the sphere //! reversing the ZAxis. - void VReverse(); - + void VReverse() { pos.ZReverse(); } + //! Returns true if the local coordinate system of this sphere //! is right-handed. - Standard_Boolean Direct() const; - + Standard_Boolean Direct() const { return pos.Direct(); } + //! --- Purpose ; //! Returns the center of the sphere. - const gp_Pnt& Location() const; - + const gp_Pnt& Location() const { return pos.Location(); } //! Returns the local coordinates system of the sphere. - const gp_Ax3& Position() const; - + const gp_Ax3& Position() const { return pos; } + //! Returns the radius of the sphere. - Standard_Real Radius() const; - + Standard_Real Radius() const { return radius; } + //! Computes the volume of the sphere - Standard_Real Volume() const; - + Standard_Real Volume() const + { + return (4.0 * M_PI * radius * radius * radius) / 3.0; + } + //! Returns the axis X of the sphere. - gp_Ax1 XAxis() const; - + gp_Ax1 XAxis() const + { + return gp_Ax1 (pos.Location(), pos.XDirection()); + } + //! Returns the axis Y of the sphere. - gp_Ax1 YAxis() const; - - Standard_EXPORT void Mirror (const gp_Pnt& P); - + gp_Ax1 YAxis() const + { + return gp_Ax1 (pos.Location(), pos.YDirection()); + } + + Standard_EXPORT void Mirror (const gp_Pnt& theP); //! Performs the symmetrical transformation of a sphere - //! with respect to the point P which is the center of the + //! with respect to the point theP which is the center of the //! symmetry. - Standard_NODISCARD Standard_EXPORT gp_Sphere Mirrored (const gp_Pnt& P) const; - - Standard_EXPORT void Mirror (const gp_Ax1& A1); - + Standard_NODISCARD Standard_EXPORT gp_Sphere Mirrored (const gp_Pnt& theP) const; + + Standard_EXPORT void Mirror (const gp_Ax1& theA1); //! Performs the symmetrical transformation of a sphere with //! respect to an axis placement which is the axis of the //! symmetry. - Standard_NODISCARD Standard_EXPORT gp_Sphere Mirrored (const gp_Ax1& A1) const; - - Standard_EXPORT void Mirror (const gp_Ax2& A2); - + Standard_NODISCARD Standard_EXPORT gp_Sphere Mirrored (const gp_Ax1& theA1) const; + + Standard_EXPORT void Mirror (const gp_Ax2& theA2); //! Performs the symmetrical transformation of a sphere with respect - //! to a plane. The axis placement A2 locates the plane of the + //! to a plane. The axis placement theA2 locates the plane of the //! of the symmetry : (Location, XDirection, YDirection). - Standard_NODISCARD Standard_EXPORT gp_Sphere Mirrored (const gp_Ax2& A2) const; - - void Rotate (const gp_Ax1& A1, const Standard_Real Ang); - + Standard_NODISCARD Standard_EXPORT gp_Sphere Mirrored (const gp_Ax2& theA2) const; - //! Rotates a sphere. A1 is the axis of the rotation. - //! Ang is the angular value of the rotation in radians. - Standard_NODISCARD gp_Sphere Rotated (const gp_Ax1& A1, const Standard_Real Ang) const; - - void Scale (const gp_Pnt& P, const Standard_Real S); - + void Rotate (const gp_Ax1& theA1, const Standard_Real theAng) { pos.Rotate (theA1, theAng); } - //! Scales a sphere. S is the scaling value. + //! Rotates a sphere. theA1 is the axis of the rotation. + //! theAng is the angular value of the rotation in radians. + Standard_NODISCARD gp_Sphere Rotated (const gp_Ax1& theA1, const Standard_Real theAng) const + { + gp_Sphere aC = *this; + aC.pos.Rotate (theA1, theAng); + return aC; + } + + void Scale (const gp_Pnt& theP, const Standard_Real theS); + + //! Scales a sphere. theS is the scaling value. //! The absolute value of S is used to scale the sphere - Standard_NODISCARD gp_Sphere Scaled (const gp_Pnt& P, const Standard_Real S) const; - - void Transform (const gp_Trsf& T); - + Standard_NODISCARD gp_Sphere Scaled (const gp_Pnt& theP, const Standard_Real theS) const; - //! Transforms a sphere with the transformation T from class Trsf. - Standard_NODISCARD gp_Sphere Transformed (const gp_Trsf& T) const; - - void Translate (const gp_Vec& V); - + void Transform (const gp_Trsf& theT); - //! Translates a sphere in the direction of the vector V. + //! Transforms a sphere with the transformation theT from class Trsf. + Standard_NODISCARD gp_Sphere Transformed (const gp_Trsf& theT) const; + + void Translate (const gp_Vec& theV) { pos.Translate (theV); } + + //! Translates a sphere in the direction of the vector theV. //! The magnitude of the translation is the vector's magnitude. - Standard_NODISCARD gp_Sphere Translated (const gp_Vec& V) const; - - void Translate (const gp_Pnt& P1, const gp_Pnt& P2); - - - //! Translates a sphere from the point P1 to the point P2. - Standard_NODISCARD gp_Sphere Translated (const gp_Pnt& P1, const gp_Pnt& P2) const; - - - - -protected: - - + Standard_NODISCARD gp_Sphere Translated (const gp_Vec& theV) const + { + gp_Sphere aC = *this; + aC.pos.Translate (theV); + return aC; + } + void Translate (const gp_Pnt& theP1, const gp_Pnt& theP2) { pos.Translate (theP1, theP2); } + //! Translates a sphere from the point theP1 to the point theP2. + Standard_NODISCARD gp_Sphere Translated (const gp_Pnt& theP1, const gp_Pnt& theP2) const + { + gp_Sphere aC = *this; + aC.pos.Translate (theP1, theP2); + return aC; + } private: - - gp_Ax3 pos; Standard_Real radius; - }; +//======================================================================= +//function : Scale +// purpose : +//======================================================================= +inline void gp_Sphere::Scale (const gp_Pnt& theP, const Standard_Real theS) +{ + pos.Scale (theP, theS); + radius *= theS; + if (radius < 0) + { + radius = -radius; + } +} -#include - - +//======================================================================= +//function : Scaled +// purpose : +//======================================================================= +inline gp_Sphere gp_Sphere::Scaled (const gp_Pnt& theP, const Standard_Real theS) const +{ + gp_Sphere aC = *this; + aC.pos.Scale (theP, theS); + aC.radius *= theS; + if (aC.radius < 0) + { + aC.radius = -aC.radius; + } + return aC; +} +//======================================================================= +//function : Transform +// purpose : +//======================================================================= +inline void gp_Sphere::Transform (const gp_Trsf& theT) +{ + pos.Transform(theT); + radius *= theT.ScaleFactor(); + if (radius < 0) + { + radius = -radius; + } +} +//======================================================================= +//function : Transformed +// purpose : +//======================================================================= +inline gp_Sphere gp_Sphere::Transformed (const gp_Trsf& theT) const +{ + gp_Sphere aC = *this; + aC.pos.Transform (theT); + aC.radius *= theT.ScaleFactor(); + if (aC.radius < 0) + { + aC.radius = -aC.radius; + } + return aC; +} #endif // _gp_Sphere_HeaderFile diff --git a/src/gp/gp_Sphere.lxx b/src/gp/gp_Sphere.lxx deleted file mode 100644 index 6caacc5d56..0000000000 --- a/src/gp/gp_Sphere.lxx +++ /dev/null @@ -1,135 +0,0 @@ -// Copyright (c) 1995-1999 Matra Datavision -// Copyright (c) 1999-2014 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -inline gp_Sphere::gp_Sphere () : radius (RealLast()) -{ } - -inline gp_Sphere::gp_Sphere (const gp_Ax3& A3, - const Standard_Real Radius) : - pos (A3), - radius (Radius) -{ - Standard_ConstructionError_Raise_if (Radius < 0.0, "gp_Sphere() - radius should be >= 0"); -} - -inline void gp_Sphere::SetLocation (const gp_Pnt& Loc) -{ pos.SetLocation (Loc); } - -inline void gp_Sphere::SetPosition (const gp_Ax3& A3) -{ pos = A3; } - -inline void gp_Sphere::SetRadius (const Standard_Real R) -{ - Standard_ConstructionError_Raise_if (R < 0.0, "gp_Sphere::SetRadius() - radius should be >= 0"); - radius = R; -} - -inline Standard_Real gp_Sphere::Area () const -{ return 4.0 * M_PI * radius * radius; } - -inline void gp_Sphere::UReverse() -{ pos.YReverse(); } - -inline void gp_Sphere::VReverse() -{ pos.ZReverse(); } - -inline Standard_Boolean gp_Sphere::Direct() const -{ return pos.Direct(); } - -inline const gp_Pnt& gp_Sphere::Location () const -{ return pos.Location(); } - -inline const gp_Ax3& gp_Sphere::Position () const -{ return pos; } - -inline Standard_Real gp_Sphere::Radius () const -{ return radius; } - -inline Standard_Real gp_Sphere::Volume () const -{ return (4.0 * M_PI * radius * radius * radius) / 3.0; } - -inline gp_Ax1 gp_Sphere::XAxis () const -{ return gp_Ax1(pos.Location(), pos.XDirection()); } - -inline gp_Ax1 gp_Sphere::YAxis () const -{ return gp_Ax1(pos.Location(), pos.YDirection()); } - -inline void gp_Sphere::Rotate (const gp_Ax1& A1, - const Standard_Real Ang) -{ pos.Rotate (A1, Ang); } - -inline gp_Sphere gp_Sphere::Rotated (const gp_Ax1& A1, - const Standard_Real Ang) const -{ - gp_Sphere C = *this; - C.pos.Rotate (A1, Ang); - return C; -} - -inline void gp_Sphere::Scale (const gp_Pnt& P, - const Standard_Real S) -{ - pos.Scale (P, S); - radius *= S; - if (radius < 0) radius = - radius; -} - -inline gp_Sphere gp_Sphere::Scaled (const gp_Pnt& P, - const Standard_Real S) const -{ - gp_Sphere C = *this; - C.pos.Scale (P, S); - C.radius *= S; - if (C.radius < 0) C.radius = - C.radius; - return C; -} - -inline void gp_Sphere::Transform (const gp_Trsf& T) -{ - pos.Transform (T); - radius *= T.ScaleFactor(); - if (radius < 0) radius = - radius; -} - -inline gp_Sphere gp_Sphere::Transformed (const gp_Trsf& T) const -{ - gp_Sphere C = *this; - C.pos.Transform (T); - C.radius *= T.ScaleFactor(); - if (C.radius < 0) C.radius = - C.radius; - return C; -} - -inline void gp_Sphere::Translate (const gp_Vec& V) -{ pos.Translate (V); } - -inline gp_Sphere gp_Sphere::Translated (const gp_Vec& V) const -{ - gp_Sphere C = *this; - C.pos.Translate (V); - return C; -} - -inline void gp_Sphere::Translate (const gp_Pnt& P1, - const gp_Pnt& P2) -{ pos.Translate (P1, P2); } - -inline gp_Sphere gp_Sphere::Translated (const gp_Pnt& P1, - const gp_Pnt& P2) const -{ - gp_Sphere C = *this; - C.pos.Translate (P1, P2); - return C; -} - diff --git a/src/gp/gp_Torus.cxx b/src/gp/gp_Torus.cxx index 3eadc2c2ea..3fde34cc81 100644 --- a/src/gp/gp_Torus.cxx +++ b/src/gp/gp_Torus.cxx @@ -12,13 +12,13 @@ // Alternatively, this file may be used under the terms of Open CASCADE // commercial license or contractual agreement. +#include #include #include #include #include #include -#include #include #include #include diff --git a/src/gp/gp_Torus.hxx b/src/gp/gp_Torus.hxx index a82cabc933..eb888a2323 100644 --- a/src/gp/gp_Torus.hxx +++ b/src/gp/gp_Torus.hxx @@ -15,25 +15,11 @@ #ifndef _gp_Torus_HeaderFile #define _gp_Torus_HeaderFile -#include -#include -#include - -#include -#include -#include -#include #include -class Standard_ConstructionError; -class Standard_DimensionError; -class gp_Ax3; -class gp_Ax1; -class gp_Pnt; -class gp_Ax2; -class gp_Trsf; -class gp_Vec; - - +#include +#include +#include +#include //! Describes a torus. //! A torus is defined by its major and minor radii and @@ -73,61 +59,79 @@ public: DEFINE_STANDARD_ALLOC - //! creates an indefinite Torus. - gp_Torus(); - + gp_Torus() + : majorRadius (RealLast()), + minorRadius (RealSmall()) + {} //! a torus centered on the origin of coordinate system - //! A3, with major radius MajorRadius and minor radius - //! MinorRadius, and with the reference plane defined - //! by the origin, the "X Direction" and the "Y Direction" of A3. + //! theA3, with major radius theMajorRadius and minor radius + //! theMinorRadius, and with the reference plane defined + //! by the origin, the "X Direction" and the "Y Direction" of theA3. //! Warnings : //! It is not forbidden to create a torus with - //! MajorRadius = MinorRadius = 0.0 - //! Raises ConstructionError if MinorRadius < 0.0 or if MajorRadius < 0.0 - gp_Torus(const gp_Ax3& A3, const Standard_Real MajorRadius, const Standard_Real MinorRadius); - + //! theMajorRadius = theMinorRadius = 0.0 + //! Raises ConstructionError if theMinorRadius < 0.0 or if theMajorRadius < 0.0 + gp_Torus (const gp_Ax3& theA3, const Standard_Real theMajorRadius, const Standard_Real theMinorRadius) + : pos (theA3), + majorRadius (theMajorRadius), + minorRadius (theMinorRadius) + { + Standard_ConstructionError_Raise_if (theMinorRadius < 0.0 || theMajorRadius < 0.0, + "gp_Torus() - invalid construction parameters"); + } + //! Modifies this torus, by redefining its local coordinate //! system so that: //! - its origin and "main Direction" become those of the - //! axis A1 (the "X Direction" and "Y Direction" are then recomputed). - //! Raises ConstructionError if the direction of A1 is parallel to the "XDirection" + //! axis theA1 (the "X Direction" and "Y Direction" are then recomputed). + //! Raises ConstructionError if the direction of theA1 is parallel to the "XDirection" //! of the coordinate system of the toroidal surface. - void SetAxis (const gp_Ax1& A1); - + void SetAxis (const gp_Ax1& theA1) { pos.SetAxis (theA1); } + //! Changes the location of the torus. - void SetLocation (const gp_Pnt& Loc); - + void SetLocation (const gp_Pnt& theLoc) { pos.SetLocation (theLoc); } + //! Assigns value to the major radius of this torus. - //! Raises ConstructionError if MajorRadius - MinorRadius <= Resolution() - void SetMajorRadius (const Standard_Real MajorRadius); - + //! Raises ConstructionError if theMajorRadius - MinorRadius <= Resolution() + void SetMajorRadius (const Standard_Real theMajorRadius) + { + Standard_ConstructionError_Raise_if (theMajorRadius - minorRadius <= gp::Resolution(), + "gp_Torus::SetMajorRadius() - invalid input parameters"); + majorRadius = theMajorRadius; + } + //! Assigns value to the minor radius of this torus. - //! Raises ConstructionError if MinorRadius < 0.0 or if - //! MajorRadius - MinorRadius <= Resolution from gp. - void SetMinorRadius (const Standard_Real MinorRadius); - + //! Raises ConstructionError if theMinorRadius < 0.0 or if + //! MajorRadius - theMinorRadius <= Resolution from gp. + void SetMinorRadius (const Standard_Real theMinorRadius) + { + Standard_ConstructionError_Raise_if (theMinorRadius < 0.0 || majorRadius - theMinorRadius <= gp::Resolution(), + "gp_Torus::SetMinorRadius() - invalid input parameters"); + minorRadius = theMinorRadius; + } + //! Changes the local coordinate system of the surface. - void SetPosition (const gp_Ax3& A3); - + void SetPosition (const gp_Ax3& theA3) { pos = theA3; } + //! Computes the area of the torus. - Standard_Real Area() const; - + Standard_Real Area() const { return 4.0 * M_PI * M_PI * minorRadius * majorRadius; } + //! Reverses the U parametrization of the torus //! reversing the YAxis. - void UReverse(); - + void UReverse() { pos.YReverse(); } + //! Reverses the V parametrization of the torus //! reversing the ZAxis. - void VReverse(); - + void VReverse() { pos.ZReverse(); } + //! returns true if the Ax3, the local coordinate system of this torus, is right handed. - Standard_Boolean Direct() const; - + Standard_Boolean Direct() const { return pos.Direct(); } + //! returns the symmetry axis of the torus. - const gp_Ax1& Axis() const; - + const gp_Ax1& Axis() const { return pos.Axis(); } + //! Computes the coefficients of the implicit equation of the surface //! in the absolute Cartesian coordinate system: //! @code @@ -146,112 +150,185 @@ public: //! Coef(32) * X + Coef(33) * Y + Coef(34) * Z + //! Coef(35) = 0.0 //! @endcode - //! Raises DimensionError if the length of Coef is lower than 35. - Standard_EXPORT void Coefficients (TColStd_Array1OfReal& Coef) const; - + //! Raises DimensionError if the length of theCoef is lower than 35. + Standard_EXPORT void Coefficients (TColStd_Array1OfReal& theCoef) const; + //! Returns the Torus's location. - const gp_Pnt& Location() const; - + const gp_Pnt& Location() const { return pos.Location(); } + //! Returns the local coordinates system of the torus. - const gp_Ax3& Position() const; - + const gp_Ax3& Position() const { return pos; } + //! returns the major radius of the torus. - Standard_Real MajorRadius() const; - + Standard_Real MajorRadius() const { return majorRadius; } + //! returns the minor radius of the torus. - Standard_Real MinorRadius() const; - + Standard_Real MinorRadius() const { return minorRadius; } + //! Computes the volume of the torus. - Standard_Real Volume() const; - + Standard_Real Volume() const + { + return (M_PI * minorRadius * minorRadius) * (2.0 * M_PI * majorRadius); + } + //! returns the axis X of the torus. - gp_Ax1 XAxis() const; - + gp_Ax1 XAxis() const + { + return gp_Ax1 (pos.Location(), pos.XDirection()); + } + //! returns the axis Y of the torus. - gp_Ax1 YAxis() const; - - Standard_EXPORT void Mirror (const gp_Pnt& P); - + gp_Ax1 YAxis() const + { + return gp_Ax1 (pos.Location(), pos.YDirection()); + } + + Standard_EXPORT void Mirror (const gp_Pnt& theP); //! Performs the symmetrical transformation of a torus - //! with respect to the point P which is the center of the + //! with respect to the point theP which is the center of the //! symmetry. - Standard_NODISCARD Standard_EXPORT gp_Torus Mirrored (const gp_Pnt& P) const; - - Standard_EXPORT void Mirror (const gp_Ax1& A1); - + Standard_NODISCARD Standard_EXPORT gp_Torus Mirrored (const gp_Pnt& theP) const; + + Standard_EXPORT void Mirror (const gp_Ax1& theA1); //! Performs the symmetrical transformation of a torus with //! respect to an axis placement which is the axis of the //! symmetry. - Standard_NODISCARD Standard_EXPORT gp_Torus Mirrored (const gp_Ax1& A1) const; - - Standard_EXPORT void Mirror (const gp_Ax2& A2); - + Standard_NODISCARD Standard_EXPORT gp_Torus Mirrored (const gp_Ax1& theA1) const; + + Standard_EXPORT void Mirror (const gp_Ax2& theA2); //! Performs the symmetrical transformation of a torus with respect - //! to a plane. The axis placement A2 locates the plane of the + //! to a plane. The axis placement theA2 locates the plane of the //! of the symmetry : (Location, XDirection, YDirection). - Standard_NODISCARD Standard_EXPORT gp_Torus Mirrored (const gp_Ax2& A2) const; - - void Rotate (const gp_Ax1& A1, const Standard_Real Ang); - + Standard_NODISCARD Standard_EXPORT gp_Torus Mirrored (const gp_Ax2& theA2) const; - //! Rotates a torus. A1 is the axis of the rotation. - //! Ang is the angular value of the rotation in radians. - Standard_NODISCARD gp_Torus Rotated (const gp_Ax1& A1, const Standard_Real Ang) const; - - void Scale (const gp_Pnt& P, const Standard_Real S); - + void Rotate (const gp_Ax1& theA1, const Standard_Real theAng) { pos.Rotate (theA1, theAng); } + + //! Rotates a torus. theA1 is the axis of the rotation. + //! theAng is the angular value of the rotation in radians. + Standard_NODISCARD gp_Torus Rotated (const gp_Ax1& theA1, const Standard_Real theAng) const + { + gp_Torus aC = *this; + aC.pos.Rotate (theA1, theAng); + return aC; + } + + void Scale (const gp_Pnt& theP, const Standard_Real theS); //! Scales a torus. S is the scaling value. //! The absolute value of S is used to scale the torus - Standard_NODISCARD gp_Torus Scaled (const gp_Pnt& P, const Standard_Real S) const; - - void Transform (const gp_Trsf& T); - + Standard_NODISCARD gp_Torus Scaled (const gp_Pnt& theP, const Standard_Real theS) const; - //! Transforms a torus with the transformation T from class Trsf. - Standard_NODISCARD gp_Torus Transformed (const gp_Trsf& T) const; - - void Translate (const gp_Vec& V); - + void Transform (const gp_Trsf& theT); - //! Translates a torus in the direction of the vector V. + //! Transforms a torus with the transformation theT from class Trsf. + Standard_NODISCARD gp_Torus Transformed (const gp_Trsf& theT) const; + + void Translate (const gp_Vec& theV) { pos.Translate (theV); } + + //! Translates a torus in the direction of the vector theV. //! The magnitude of the translation is the vector's magnitude. - Standard_NODISCARD gp_Torus Translated (const gp_Vec& V) const; - - void Translate (const gp_Pnt& P1, const gp_Pnt& P2); - - - //! Translates a torus from the point P1 to the point P2. - Standard_NODISCARD gp_Torus Translated (const gp_Pnt& P1, const gp_Pnt& P2) const; - - - - -protected: - - + Standard_NODISCARD gp_Torus Translated (const gp_Vec& theV) const + { + gp_Torus aC = *this; + aC.pos.Translate (theV); + return aC; + } + void Translate (const gp_Pnt& theP1, const gp_Pnt& theP2) { pos.Translate (theP1, theP2); } + //! Translates a torus from the point theP1 to the point theP2. + Standard_NODISCARD gp_Torus Translated (const gp_Pnt& theP1, const gp_Pnt& theP2) const + { + gp_Torus aC = *this; + aC.pos.Translate (theP1, theP2); + return aC; + } private: - - gp_Ax3 pos; Standard_Real majorRadius; Standard_Real minorRadius; - }; +//======================================================================= +//function : Scale +// purpose : +//======================================================================= +inline void gp_Torus::Scale (const gp_Pnt& theP, + const Standard_Real theS) +{ + pos.Scale (theP, theS); + Standard_Real s = theS; + if (s < 0) + { + s = -s; + } + majorRadius *= s; + minorRadius *= s; +} -#include - - +//======================================================================= +//function : Scaled +// purpose : +//======================================================================= +inline gp_Torus gp_Torus::Scaled (const gp_Pnt& theP, + const Standard_Real theS) const +{ + gp_Torus aC = *this; + aC.pos.Scale (theP, theS); + aC.majorRadius *= theS; + if (aC.majorRadius < 0) + { + aC.majorRadius = -aC.majorRadius; + } + aC.minorRadius *= theS; + if (aC.minorRadius < 0) + { + aC.minorRadius = -aC.minorRadius; + } + return aC; +} +//======================================================================= +//function : Transform +// purpose : +//======================================================================= +inline void gp_Torus::Transform (const gp_Trsf& theT) +{ + pos.Transform (theT); + Standard_Real aT = theT.ScaleFactor(); + if (aT < 0) + { + aT = -aT; + } + minorRadius *= aT; + majorRadius *= aT; +} +//======================================================================= +//function : Transformed +// purpose : +//======================================================================= +inline gp_Torus gp_Torus::Transformed (const gp_Trsf& theT) const +{ + gp_Torus aC = *this; + aC.pos.Transform (theT); + aC.majorRadius *= theT.ScaleFactor(); + if (aC.majorRadius < 0) + { + aC.majorRadius = -aC.majorRadius; + } + aC.minorRadius *= theT.ScaleFactor(); + if (aC.minorRadius < 0) + { + aC.minorRadius = -aC.minorRadius; + } + return aC; +} #endif // _gp_Torus_HeaderFile diff --git a/src/gp/gp_Torus.lxx b/src/gp/gp_Torus.lxx deleted file mode 100644 index 08fdc04f44..0000000000 --- a/src/gp/gp_Torus.lxx +++ /dev/null @@ -1,165 +0,0 @@ -// Copyright (c) 1995-1999 Matra Datavision -// Copyright (c) 1999-2014 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -inline gp_Torus::gp_Torus () : -majorRadius (RealLast()), -minorRadius (RealSmall()) -{ } - -inline gp_Torus::gp_Torus (const gp_Ax3& A3, - const Standard_Real MajorRadius, - const Standard_Real MinorRadius) : - pos(A3), - majorRadius (MajorRadius), - minorRadius (MinorRadius) -{ - Standard_ConstructionError_Raise_if (MinorRadius < 0.0 || MajorRadius < 0.0, - "gp_Torus() - invalid construction parameters"); -} - -inline void gp_Torus::SetAxis (const gp_Ax1& A1) -{ pos.SetAxis (A1); } - -inline void gp_Torus::SetLocation (const gp_Pnt& Loc) -{ pos.SetLocation (Loc); } - -inline void gp_Torus::SetMajorRadius (const Standard_Real MajorRadius) -{ - Standard_ConstructionError_Raise_if (MajorRadius - minorRadius <= gp::Resolution(), - "gp_Torus::SetMajorRadius() - invalid input parameters"); - majorRadius = MajorRadius; -} - -inline void gp_Torus::SetMinorRadius (const Standard_Real MinorRadius) -{ - Standard_ConstructionError_Raise_if (MinorRadius < 0.0 || majorRadius - MinorRadius <= gp::Resolution(), - "gp_Torus::SetMinorRadius() - invalid input parameters"); - minorRadius = MinorRadius; -} - -inline void gp_Torus::SetPosition (const gp_Ax3& A3) -{ pos = A3; } - -inline Standard_Real gp_Torus::Area () const -{ return 4.0 * M_PI * M_PI * minorRadius * majorRadius; } - -inline void gp_Torus::UReverse() -{ pos.YReverse(); } - -inline void gp_Torus::VReverse() -{ pos.ZReverse(); } - -inline Standard_Boolean gp_Torus::Direct() const -{ return pos.Direct(); } - -inline const gp_Ax1& gp_Torus::Axis () const -{ return pos.Axis(); } - -inline const gp_Pnt& gp_Torus::Location () const -{ return pos.Location(); } - -inline const gp_Ax3& gp_Torus::Position () const -{ return pos; } - -inline Standard_Real gp_Torus::MajorRadius () const -{ return majorRadius; } - -inline Standard_Real gp_Torus::MinorRadius () const -{ return minorRadius; } - -inline Standard_Real gp_Torus::Volume () const -{ return (M_PI * minorRadius * minorRadius) * (2.0 * M_PI * majorRadius); } - -inline gp_Ax1 gp_Torus::XAxis () const -{ return gp_Ax1(pos.Location(), pos.XDirection()); } - -inline gp_Ax1 gp_Torus::YAxis () const -{ return gp_Ax1(pos.Location(), pos.YDirection()); } - -inline void gp_Torus::Rotate (const gp_Ax1& A1, - const Standard_Real Ang) -{ pos.Rotate (A1, Ang); } - -inline gp_Torus gp_Torus::Rotated (const gp_Ax1& A1, - const Standard_Real Ang) const -{ - gp_Torus C = *this; - C.pos.Rotate (A1, Ang); - return C; -} - -inline void gp_Torus::Scale (const gp_Pnt& P, - const Standard_Real S) -{ - pos.Scale (P, S); - Standard_Real s = S; - if (s < 0) s = - s; - majorRadius *= s; - minorRadius *= s; -} - -inline gp_Torus gp_Torus::Scaled (const gp_Pnt& P, - const Standard_Real S) const -{ - gp_Torus C = *this; - C.pos.Scale (P, S); - C.majorRadius *= S; - if (C.majorRadius < 0) C.majorRadius = - C.majorRadius; - C.minorRadius *= S; - if (C.minorRadius < 0) C.minorRadius = - C.minorRadius; - return C; -} - -inline void gp_Torus::Transform (const gp_Trsf& T) -{ - pos.Transform (T); - Standard_Real t = T.ScaleFactor(); - if(t < 0 ) t = - t; - minorRadius *= t; - majorRadius *= t; -} - -inline gp_Torus gp_Torus::Transformed (const gp_Trsf& T) const -{ - gp_Torus C = *this; - C.pos.Transform (T); - C.majorRadius *= T.ScaleFactor(); - if (C.majorRadius < 0) C.majorRadius = - C.majorRadius; - C.minorRadius *= T.ScaleFactor(); - if (C.minorRadius < 0) C.minorRadius = - C.minorRadius; - return C; -} - -inline void gp_Torus::Translate (const gp_Vec& V) -{ pos.Translate (V); } - -inline gp_Torus gp_Torus::Translated (const gp_Vec& V) const -{ - gp_Torus C = *this; - C.pos.Translate (V); - return C; -} - -inline void gp_Torus::Translate (const gp_Pnt& P1, - const gp_Pnt& P2) -{ pos.Translate (P1, P2); } - -inline gp_Torus gp_Torus::Translated (const gp_Pnt& P1, - const gp_Pnt& P2) const -{ - gp_Torus C = *this; - C.pos.Translate (P1, P2); - return C; -} - diff --git a/src/gp/gp_Trsf.cxx b/src/gp/gp_Trsf.cxx index b5b7551b15..376e6fd405 100644 --- a/src/gp/gp_Trsf.cxx +++ b/src/gp/gp_Trsf.cxx @@ -19,6 +19,7 @@ #define No_Standard_OutOfRange +#include #include #include @@ -28,7 +29,6 @@ #include #include #include -#include #include #include #include diff --git a/src/gp/gp_Trsf.hxx b/src/gp/gp_Trsf.hxx index 98cb90ac1d..5e726f54f9 100644 --- a/src/gp/gp_Trsf.hxx +++ b/src/gp/gp_Trsf.hxx @@ -19,18 +19,13 @@ #include #include #include -#include -#include -#include -#include -#include +#include #include +#include #include -#include -class Standard_ConstructionError; -class Standard_OutOfRange; class gp_Pnt; +class gp_Trsf2d; class gp_Ax1; class gp_Ax2; class gp_Quaternion; @@ -67,76 +62,70 @@ public: DEFINE_STANDARD_ALLOC - //! Returns the identity transformation. - gp_Trsf(); - - //! Creates a 3D transformation from the 2D transformation T. + gp_Trsf(); + + //! Creates a 3D transformation from the 2D transformation theT. //! The resulting transformation has a homogeneous - //! vectorial part, V3, and a translation part, T3, built from T: + //! vectorial part, V3, and a translation part, T3, built from theT: //! a11 a12 //! 0 a13 //! V3 = a21 a22 0 T3 //! = a23 //! 0 0 1. //! 0 - //! It also has the same scale factor as T. This + //! It also has the same scale factor as theT. This //! guarantees (by projection) that the transformation - //! which would be performed by T in a plane (2D space) + //! which would be performed by theT in a plane (2D space) //! is performed by the resulting transformation in the xOy //! plane of the 3D space, (i.e. in the plane defined by the //! origin (0., 0., 0.) and the vectors DX (1., 0., 0.), and DY //! (0., 1., 0.)). The scale factor is applied to the entire space. - Standard_EXPORT gp_Trsf(const gp_Trsf2d& T); - + Standard_EXPORT gp_Trsf (const gp_Trsf2d& theT); //! Makes the transformation into a symmetrical transformation. - //! P is the center of the symmetry. - void SetMirror (const gp_Pnt& P); - + //! theP is the center of the symmetry. + void SetMirror (const gp_Pnt& theP); //! Makes the transformation into a symmetrical transformation. - //! A1 is the center of the axial symmetry. - Standard_EXPORT void SetMirror (const gp_Ax1& A1); - + //! theA1 is the center of the axial symmetry. + Standard_EXPORT void SetMirror (const gp_Ax1& theA1); //! Makes the transformation into a symmetrical transformation. - //! A2 is the center of the planar symmetry + //! theA2 is the center of the planar symmetry //! and defines the plane of symmetry by its origin, "X //! Direction" and "Y Direction". - Standard_EXPORT void SetMirror (const gp_Ax2& A2); - + Standard_EXPORT void SetMirror (const gp_Ax2& theA2); //! Changes the transformation into a rotation. - //! A1 is the rotation axis and Ang is the angular value of the + //! theA1 is the rotation axis and theAng is the angular value of the //! rotation in radians. - Standard_EXPORT void SetRotation (const gp_Ax1& A1, const Standard_Real Ang); + Standard_EXPORT void SetRotation (const gp_Ax1& theA1, const Standard_Real theAng); //! Changes the transformation into a rotation defined by quaternion. //! Note that rotation is performed around origin, i.e. //! no translation is involved. - Standard_EXPORT void SetRotation (const gp_Quaternion& R); + Standard_EXPORT void SetRotation (const gp_Quaternion& theR); //! Replaces the rotation part with specified quaternion. - Standard_EXPORT void SetRotationPart (const gp_Quaternion& R); + Standard_EXPORT void SetRotationPart (const gp_Quaternion& theR); //! Changes the transformation into a scale. - //! P is the center of the scale and S is the scaling value. - //! Raises ConstructionError If is null. - Standard_EXPORT void SetScale (const gp_Pnt& P, const Standard_Real S); - + //! theP is the center of the scale and theS is the scaling value. + //! Raises ConstructionError If is null. + Standard_EXPORT void SetScale (const gp_Pnt& theP, const Standard_Real theS); //! Modifies this transformation so that it transforms the - //! coordinate system defined by FromSystem1 into the - //! one defined by ToSystem2. After this modification, this + //! coordinate system defined by theFromSystem1 into the + //! one defined by theToSystem2. After this modification, this //! transformation transforms: - //! - the origin of FromSystem1 into the origin of ToSystem2, - //! - the "X Direction" of FromSystem1 into the "X - //! Direction" of ToSystem2, - //! - the "Y Direction" of FromSystem1 into the "Y - //! Direction" of ToSystem2, and - //! - the "main Direction" of FromSystem1 into the "main - //! Direction" of ToSystem2. + //! - the origin of theFromSystem1 into the origin of theToSystem2, + //! - the "X Direction" of theFromSystem1 into the "X + //! Direction" of theToSystem2, + //! - the "Y Direction" of theFromSystem1 into the "Y + //! Direction" of theToSystem2, and + //! - the "main Direction" of theFromSystem1 into the "main + //! Direction" of theToSystem2. //! Warning //! When you know the coordinates of a point in one //! coordinate system and you want to express these @@ -146,28 +135,28 @@ public: //! SetDisplacement and SetTransformation create //! related transformations: the vectorial part of one is the //! inverse of the vectorial part of the other. - Standard_EXPORT void SetDisplacement (const gp_Ax3& FromSystem1, const gp_Ax3& ToSystem2); - + Standard_EXPORT void SetDisplacement (const gp_Ax3& theFromSystem1, const gp_Ax3& theToSystem2); + //! Modifies this transformation so that it transforms the //! coordinates of any point, (x, y, z), relative to a source //! coordinate system into the coordinates (x', y', z') which //! are relative to a target coordinate system, but which //! represent the same point //! The transformation is from the coordinate - //! system "FromSystem1" to the coordinate system "ToSystem2". + //! system "theFromSystem1" to the coordinate system "theToSystem2". //! Example : //! @code - //! gp_Ax3 FromSystem1, ToSystem2; - //! double x1, y1, z1; // are the coordinates of a point in the local system FromSystem1 - //! double x2, y2, z2; // are the coordinates of a point in the local system ToSystem2 + //! gp_Ax3 theFromSystem1, theToSystem2; + //! double x1, y1, z1; // are the coordinates of a point in the local system theFromSystem1 + //! double x2, y2, z2; // are the coordinates of a point in the local system theToSystem2 //! gp_Pnt P1 (x1, y1, z1) //! gp_Trsf T; - //! T.SetTransformation (FromSystem1, ToSystem2); + //! T.SetTransformation (theFromSystem1, theToSystem2); //! gp_Pnt P2 = P1.Transformed (T); //! P2.Coord (x2, y2, z2); //! @endcode - Standard_EXPORT void SetTransformation (const gp_Ax3& FromSystem1, const gp_Ax3& ToSystem2); - + Standard_EXPORT void SetTransformation (const gp_Ax3& theFromSystem1, const gp_Ax3& theToSystem2); + //! Modifies this transformation so that it transforms the //! coordinates of any point, (x, y, z), relative to a source //! coordinate system into the coordinates (x', y', z') which @@ -177,34 +166,31 @@ public: //! @code //! {P(0.,0.,0.), VX (1.,0.,0.), VY (0.,1.,0.), VZ (0., 0. ,1.) } //! @endcode - //! to the local coordinate system defined with the Ax3 ToSystem. + //! to the local coordinate system defined with the Ax3 theToSystem. //! Use in the same way as the previous method. FromSystem1 is //! defaulted to the absolute coordinate system. - Standard_EXPORT void SetTransformation (const gp_Ax3& ToSystem); - + Standard_EXPORT void SetTransformation (const gp_Ax3& theToSystem); //! Sets transformation by directly specified rotation and translation. - Standard_EXPORT void SetTransformation (const gp_Quaternion& R, const gp_Vec& T); - + Standard_EXPORT void SetTransformation (const gp_Quaternion& R, const gp_Vec& theT); //! Changes the transformation into a translation. - //! V is the vector of the translation. - void SetTranslation (const gp_Vec& V); - + //! theV is the vector of the translation. + void SetTranslation (const gp_Vec& theV); //! Makes the transformation into a translation where the translation vector - //! is the vector (P1, P2) defined from point P1 to point P2. - void SetTranslation (const gp_Pnt& P1, const gp_Pnt& P2); - - //! Replaces the translation vector with the vector V. - Standard_EXPORT void SetTranslationPart (const gp_Vec& V); - + //! is the vector (theP1, theP2) defined from point theP1 to point theP2. + void SetTranslation (const gp_Pnt& theP1, const gp_Pnt& theP2); + + //! Replaces the translation vector with the vector theV. + Standard_EXPORT void SetTranslationPart (const gp_Vec& theV); + //! Modifies the scale factor. - //! Raises ConstructionError If S is null. - Standard_EXPORT void SetScaleFactor (const Standard_Real S); - - void SetForm (const gp_TrsfForm P); - + //! Raises ConstructionError If theS is null. + Standard_EXPORT void SetScaleFactor (const Standard_Real theS); + + void SetForm (const gp_TrsfForm theP) { shape = theP; } + //! Sets the coefficients of the transformation. The //! transformation of the point x,y,z is the point //! x',y',z' with : @@ -217,25 +203,22 @@ public: //! Raises ConstructionError if the determinant of the aij is null. //! The matrix is orthogonalized before future using. Standard_EXPORT void SetValues (const Standard_Real a11, const Standard_Real a12, const Standard_Real a13, const Standard_Real a14, const Standard_Real a21, const Standard_Real a22, const Standard_Real a23, const Standard_Real a24, const Standard_Real a31, const Standard_Real a32, const Standard_Real a33, const Standard_Real a34); - + //! Returns true if the determinant of the vectorial part of //! this transformation is negative. - Standard_Boolean IsNegative() const; - + Standard_Boolean IsNegative() const { return (scale < 0.0); } //! Returns the nature of the transformation. It can be: an //! identity transformation, a rotation, a translation, a mirror //! transformation (relative to a point, an axis or a plane), a //! scaling transformation, or a compound transformation. - gp_TrsfForm Form() const; - + gp_TrsfForm Form() const { return shape; } + //! Returns the scale factor. - Standard_Real ScaleFactor() const; - + Standard_Real ScaleFactor() const { return scale; } //! Returns the translation part of the transformation's matrix - const gp_XYZ& TranslationPart() const; - + const gp_XYZ& TranslationPart() const { return loc; } //! Returns the boolean True if there is non-zero rotation. //! In the presence of rotation, the output parameters store the axis @@ -245,16 +228,13 @@ public: //! the transformation; generally you would need to check also the //! translational part to obtain the axis (gp_Ax1) of rotation. Standard_EXPORT Standard_Boolean GetRotation (gp_XYZ& theAxis, Standard_Real& theAngle) const; - //! Returns quaternion representing rotational part of the transformation. Standard_EXPORT gp_Quaternion GetRotation() const; - //! Returns the vectorial part of the transformation. It is //! a 3*3 matrix which includes the scale factor. Standard_EXPORT gp_Mat VectorialPart() const; - //! Computes the homogeneous vectorial part of the transformation. //! It is a 3*3 matrix which doesn't include the scale factor. @@ -262,17 +242,15 @@ public: //! to its homogeneous vectorial part, multiplied by the scale factor. //! The coefficients of this matrix must be multiplied by the //! scale factor to obtain the coefficients of the transformation. - const gp_Mat& HVectorialPart() const; - + const gp_Mat& HVectorialPart() const { return matrix; } //! Returns the coefficients of the transformation's matrix. //! It is a 3 rows * 4 columns matrix. //! This coefficient includes the scale factor. - //! Raises OutOfRanged if Row < 1 or Row > 3 or Col < 1 or Col > 4 - Standard_Real Value (const Standard_Integer Row, const Standard_Integer Col) const; - + //! Raises OutOfRanged if theRow < 1 or theRow > 3 or theCol < 1 or theCol > 4 + Standard_Real Value (const Standard_Integer theRow, const Standard_Integer theCol) const; + Standard_EXPORT void Invert(); - //! Computes the reverse transformation //! Raises an exception if the matrix of the transformation @@ -289,44 +267,52 @@ public: //! gp_Pnt P3 = P1.Transformed(T1); // using T1 then T2 //! P3.Transform(T2); // P3 = P2 !!! //! @endcode - Standard_NODISCARD gp_Trsf Inverted() const; - - Standard_NODISCARD gp_Trsf Multiplied (const gp_Trsf& T) const; - Standard_NODISCARD gp_Trsf operator * (const gp_Trsf& T) const -{ - return Multiplied(T); -} + Standard_NODISCARD gp_Trsf Inverted() const + { + gp_Trsf aT = *this; + aT.Invert(); + return aT; + } + Standard_NODISCARD gp_Trsf Multiplied (const gp_Trsf& theT) const + { + gp_Trsf aTresult (*this); + aTresult.Multiply (theT); + return aTresult; + } + + Standard_NODISCARD gp_Trsf operator * (const gp_Trsf& theT) const { return Multiplied (theT); } + + //! Computes the transformation composed with and theT. + //! = * theT + Standard_EXPORT void Multiply (const gp_Trsf& theT); + + void operator *= (const gp_Trsf& theT) { Multiply (theT); } //! Computes the transformation composed with and T. - //! = * T - Standard_EXPORT void Multiply (const gp_Trsf& T); -void operator *= (const gp_Trsf& T) -{ - Multiply(T); -} - + //! = theT * + Standard_EXPORT void PreMultiply (const gp_Trsf& theT); - //! Computes the transformation composed with and T. - //! = T * - Standard_EXPORT void PreMultiply (const gp_Trsf& T); - - Standard_EXPORT void Power (const Standard_Integer N); - + Standard_EXPORT void Power (const Standard_Integer theN); //! Computes the following composition of transformations - //! * * .......* , N time. - //! if N = 0 = Identity - //! if N < 0 = .Inverse() *...........* .Inverse(). + //! * * .......* , theN time. + //! if theN = 0 = Identity + //! if theN < 0 = .Inverse() *...........* .Inverse(). //! - //! Raises if N < 0 and if the matrix of the transformation not + //! Raises if theN < 0 and if the matrix of the transformation not //! inversible. - Standard_NODISCARD gp_Trsf Powered (const Standard_Integer N) const; - - void Transforms (Standard_Real& X, Standard_Real& Y, Standard_Real& Z) const; - + Standard_NODISCARD gp_Trsf Powered (const Standard_Integer theN) const + { + gp_Trsf aT = *this; + aT.Power (theN); + return aT; + } + + void Transforms (Standard_Real& theX, Standard_Real& theY, Standard_Real& theZ) const; + //! Transformation of a triplet XYZ with a Trsf - void Transforms (gp_XYZ& Coord) const; + void Transforms (gp_XYZ& theCoord) const; //! Convert transformation to 4x4 matrix. template @@ -378,6 +364,108 @@ private: }; -#include +#include +#include +#include + +//======================================================================= +//function : gp_Trsf +// purpose : +//======================================================================= +inline gp_Trsf::gp_Trsf () +: scale (1.0), + shape (gp_Identity), + matrix (1, 0, 0, 0, 1, 0, 0, 0, 1), + loc (0.0, 0.0, 0.0) +{} + +//======================================================================= +//function : SetMirror +// purpose : +//======================================================================= +inline void gp_Trsf::SetMirror (const gp_Pnt& theP) +{ + shape = gp_PntMirror; + scale = -1.0; + loc = theP.XYZ(); + matrix.SetIdentity(); + loc.Multiply (2.0); +} + +//======================================================================= +//function : SetTranslation +// purpose : +//======================================================================= +inline void gp_Trsf::SetTranslation (const gp_Vec& theV) +{ + shape = gp_Translation; + scale = 1.; + matrix.SetIdentity(); + loc = theV.XYZ(); +} + +//======================================================================= +//function : SetTranslation +// purpose : +//======================================================================= +inline void gp_Trsf::SetTranslation (const gp_Pnt& theP1, + const gp_Pnt& theP2) +{ + shape = gp_Translation; + scale = 1.0; + matrix.SetIdentity(); + loc = (theP2.XYZ()).Subtracted (theP1.XYZ()); +} + +//======================================================================= +//function : Value +// purpose : +//======================================================================= +inline Standard_Real gp_Trsf::Value (const Standard_Integer theRow, const Standard_Integer theCol) const +{ + Standard_OutOfRange_Raise_if (theRow < 1 || theRow > 3 || theCol < 1 || theCol > 4, " "); + if (theCol < 4) + { + return scale * matrix.Value (theRow, theCol); + } + else + { + return loc.Coord (theRow); + } +} + +//======================================================================= +//function : Transforms +// purpose : +//======================================================================= +inline void gp_Trsf::Transforms (Standard_Real& theX, + Standard_Real& theY, + Standard_Real& theZ) const +{ + gp_XYZ aTriplet (theX, theY, theZ); + aTriplet.Multiply (matrix); + if (scale != 1.0) + { + aTriplet.Multiply (scale); + } + aTriplet.Add (loc); + theX = aTriplet.X(); + theY = aTriplet.Y(); + theZ = aTriplet.Z(); +} + +//======================================================================= +//function : Transforms +// purpose : +//======================================================================= +inline void gp_Trsf::Transforms (gp_XYZ& theCoord) const +{ + theCoord.Multiply (matrix); + if (scale != 1.0) + { + theCoord.Multiply (scale); + } + theCoord.Add (loc); +} #endif // _gp_Trsf_HeaderFile diff --git a/src/gp/gp_Trsf.lxx b/src/gp/gp_Trsf.lxx deleted file mode 100644 index c502da7a05..0000000000 --- a/src/gp/gp_Trsf.lxx +++ /dev/null @@ -1,126 +0,0 @@ -// Copyright (c) 1995-1999 Matra Datavision -// Copyright (c) 1999-2014 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -// Modif JCV 04/10/90 ajout des methodes Form Scale IsNegative -// Modif JCV 10/12/90 ajout de la methode Translationpart - - -#include -#include -#include -#include - -inline gp_Trsf::gp_Trsf () : -scale(1.0), -shape(gp_Identity), -matrix(1,0,0, 0,1,0, 0,0,1), -loc(0.0, 0.0, 0.0) -{} - -inline void gp_Trsf::SetMirror (const gp_Pnt& P) -{ - shape = gp_PntMirror; - scale = -1.0; - loc = P.XYZ(); - matrix.SetIdentity (); - loc.Multiply(2.0); -} - -inline void gp_Trsf::SetTranslation (const gp_Vec& V) -{ - shape = gp_Translation; - scale = 1.; - matrix.SetIdentity (); - loc = V.XYZ(); -} - -inline void gp_Trsf::SetTranslation(const gp_Pnt& P1, - const gp_Pnt& P2) -{ - shape = gp_Translation; - scale = 1.0; - matrix.SetIdentity (); - loc = (P2.XYZ()).Subtracted (P1.XYZ()); -} - -inline void gp_Trsf::SetForm(const gp_TrsfForm P) -{ - shape = P; -} - -inline Standard_Boolean gp_Trsf::IsNegative() const -{ return (scale < 0.0); } - -inline const gp_XYZ& gp_Trsf::TranslationPart () const -{ return loc; } - -inline const gp_Mat& gp_Trsf::HVectorialPart () const -{ return matrix; } - -inline Standard_Real gp_Trsf::Value (const Standard_Integer Row, - const Standard_Integer Col) const -{ - Standard_OutOfRange_Raise_if - (Row < 1 || Row > 3 || Col < 1 || Col > 4, " "); - if (Col < 4) return scale * matrix.Value (Row, Col); - else return loc.Coord (Row); -} - -inline gp_TrsfForm gp_Trsf::Form () const -{ return shape; } - -inline Standard_Real gp_Trsf::ScaleFactor () const -{ return scale; } - -inline gp_Trsf gp_Trsf::Inverted() const -{ - gp_Trsf T = *this; - T.Invert(); - return T; -} - -inline gp_Trsf gp_Trsf::Multiplied (const gp_Trsf& T) const -{ - gp_Trsf Tresult(*this); - Tresult.Multiply(T); - return Tresult; -} - -inline gp_Trsf gp_Trsf::Powered (const Standard_Integer N) const -{ - gp_Trsf T = *this; - T.Power (N); - return T; -} - -inline void gp_Trsf::Transforms (Standard_Real& X, - Standard_Real& Y, - Standard_Real& Z) const -{ - gp_XYZ Triplet (X, Y, Z); - Triplet.Multiply (matrix); - if (scale != 1.0) Triplet.Multiply (scale); - Triplet.Add(loc); - X = Triplet.X(); - Y = Triplet.Y(); - Z = Triplet.Z(); -} - -inline void gp_Trsf::Transforms (gp_XYZ& Coord) const -{ - Coord.Multiply (matrix); - if (scale != 1.0) Coord.Multiply (scale); - Coord.Add(loc); -} - diff --git a/src/gp/gp_Trsf2d.cxx b/src/gp/gp_Trsf2d.cxx index 2b712cbd43..04586fa11c 100644 --- a/src/gp/gp_Trsf2d.cxx +++ b/src/gp/gp_Trsf2d.cxx @@ -16,6 +16,7 @@ #define No_Standard_OutOfRange +#include #include #include @@ -23,7 +24,6 @@ #include #include #include -#include #include #include #include diff --git a/src/gp/gp_Trsf2d.hxx b/src/gp/gp_Trsf2d.hxx index 99033bf246..143877ae9b 100644 --- a/src/gp/gp_Trsf2d.hxx +++ b/src/gp/gp_Trsf2d.hxx @@ -15,18 +15,12 @@ #ifndef _gp_Trsf2d_HeaderFile #define _gp_Trsf2d_HeaderFile -#include -#include -#include - -#include #include #include #include -#include -#include -class Standard_ConstructionError; -class Standard_OutOfRange; +#include +#include + class gp_GTrsf2d; class gp_Trsf; class gp_Pnt2d; @@ -35,8 +29,6 @@ class gp_Vec2d; class gp_XY; class gp_Mat2d; - - //! Defines a non-persistent transformation in 2D space. //! The following transformations are implemented : //! - Translation, Rotation, Scale @@ -59,150 +51,142 @@ public: DEFINE_STANDARD_ALLOC - //! Returns identity transformation. - gp_Trsf2d(); - + gp_Trsf2d(); + //! Creates a 2d transformation in the XY plane from a //! 3d transformation . - gp_Trsf2d(const gp_Trsf& T); - + gp_Trsf2d (const gp_Trsf& theT); //! Changes the transformation into a symmetrical transformation. - //! P is the center of the symmetry. - void SetMirror (const gp_Pnt2d& P); - + //! theP is the center of the symmetry. + void SetMirror (const gp_Pnt2d& theP); //! Changes the transformation into a symmetrical transformation. - //! A is the center of the axial symmetry. - Standard_EXPORT void SetMirror (const gp_Ax2d& A); - + //! theA is the center of the axial symmetry. + Standard_EXPORT void SetMirror (const gp_Ax2d& theA); //! Changes the transformation into a rotation. - //! P is the rotation's center and Ang is the angular value of the + //! theP is the rotation's center and theAng is the angular value of the //! rotation in radian. - void SetRotation (const gp_Pnt2d& P, const Standard_Real Ang); - + void SetRotation (const gp_Pnt2d& theP, const Standard_Real theAng); //! Changes the transformation into a scale. - //! P is the center of the scale and S is the scaling value. - void SetScale (const gp_Pnt2d& P, const Standard_Real S); - + //! theP is the center of the scale and theS is the scaling value. + void SetScale (const gp_Pnt2d& theP, const Standard_Real theS); //! Changes a transformation allowing passage from the coordinate - //! system "FromSystem1" to the coordinate system "ToSystem2". - Standard_EXPORT void SetTransformation (const gp_Ax2d& FromSystem1, const gp_Ax2d& ToSystem2); - + //! system "theFromSystem1" to the coordinate system "theToSystem2". + Standard_EXPORT void SetTransformation (const gp_Ax2d& theFromSystem1, const gp_Ax2d& theToSystem2); //! Changes the transformation allowing passage from the basic //! coordinate system //! {P(0.,0.,0.), VX (1.,0.,0.), VY (0.,1.,0.)} - //! to the local coordinate system defined with the Ax2d ToSystem. - Standard_EXPORT void SetTransformation (const gp_Ax2d& ToSystem); - + //! to the local coordinate system defined with the Ax2d theToSystem. + Standard_EXPORT void SetTransformation (const gp_Ax2d& theToSystem); //! Changes the transformation into a translation. - //! V is the vector of the translation. - void SetTranslation (const gp_Vec2d& V); - + //! theV is the vector of the translation. + void SetTranslation (const gp_Vec2d& theV); //! Makes the transformation into a translation from - //! the point P1 to the point P2. - void SetTranslation (const gp_Pnt2d& P1, const gp_Pnt2d& P2); - - //! Replaces the translation vector with V. - Standard_EXPORT void SetTranslationPart (const gp_Vec2d& V); - + //! the point theP1 to the point theP2. + void SetTranslation (const gp_Pnt2d& theP1, const gp_Pnt2d& theP2); + + //! Replaces the translation vector with theV. + Standard_EXPORT void SetTranslationPart (const gp_Vec2d& theV); + //! Modifies the scale factor. - Standard_EXPORT void SetScaleFactor (const Standard_Real S); - + Standard_EXPORT void SetScaleFactor (const Standard_Real theS); + //! Returns true if the determinant of the vectorial part of //! this transformation is negative.. - Standard_Boolean IsNegative() const; - + Standard_Boolean IsNegative() const { return (matrix.Determinant() < 0.0); } //! Returns the nature of the transformation. It can be an //! identity transformation, a rotation, a translation, a mirror //! (relative to a point or an axis), a scaling transformation, //! or a compound transformation. - gp_TrsfForm Form() const; - + gp_TrsfForm Form() const { return shape; } + //! Returns the scale factor. - Standard_Real ScaleFactor() const; - + Standard_Real ScaleFactor() const { return scale; } //! Returns the translation part of the transformation's matrix - const gp_XY& TranslationPart() const; - + const gp_XY& TranslationPart() const { return loc; } //! Returns the vectorial part of the transformation. It is a //! 2*2 matrix which includes the scale factor. Standard_EXPORT gp_Mat2d VectorialPart() const; - //! Returns the homogeneous vectorial part of the transformation. //! It is a 2*2 matrix which doesn't include the scale factor. //! The coefficients of this matrix must be multiplied by the //! scale factor to obtain the coefficients of the transformation. - const gp_Mat2d& HVectorialPart() const; - + const gp_Mat2d& HVectorialPart() const { return matrix; } //! Returns the angle corresponding to the rotational component //! of the transformation matrix (operation opposite to SetRotation()). Standard_EXPORT Standard_Real RotationPart() const; - //! Returns the coefficients of the transformation's matrix. //! It is a 2 rows * 3 columns matrix. - //! Raises OutOfRange if Row < 1 or Row > 2 or Col < 1 or Col > 3 - Standard_Real Value (const Standard_Integer Row, const Standard_Integer Col) const; - + //! Raises OutOfRange if theRow < 1 or theRow > 2 or theCol < 1 or theCol > 3 + Standard_Real Value (const Standard_Integer theRow, const Standard_Integer theCol) const; + Standard_EXPORT void Invert(); - //! Computes the reverse transformation. //! Raises an exception if the matrix of the transformation //! is not inversible, it means that the scale factor is lower //! or equal to Resolution from package gp. - Standard_NODISCARD gp_Trsf2d Inverted() const; - - Standard_NODISCARD gp_Trsf2d Multiplied (const gp_Trsf2d& T) const; - Standard_NODISCARD gp_Trsf2d operator * (const gp_Trsf2d& T) const -{ - return Multiplied(T); -} - + Standard_NODISCARD gp_Trsf2d Inverted() const + { + gp_Trsf2d aT = *this; + aT.Invert(); + return aT; + } - //! Computes the transformation composed from and T. - //! = * T - Standard_EXPORT void Multiply (const gp_Trsf2d& T); -void operator *= (const gp_Trsf2d& T) -{ - Multiply(T); -} - + Standard_NODISCARD gp_Trsf2d Multiplied (const gp_Trsf2d& theT) const + { + gp_Trsf2d aTresult (*this); + aTresult.Multiply (theT); + return aTresult; + } - //! Computes the transformation composed from and T. - //! = T * - Standard_EXPORT void PreMultiply (const gp_Trsf2d& T); - - Standard_EXPORT void Power (const Standard_Integer N); - + Standard_NODISCARD gp_Trsf2d operator * (const gp_Trsf2d& theT) const { return Multiplied (theT); } + + //! Computes the transformation composed from and theT. + //! = * theT + Standard_EXPORT void Multiply (const gp_Trsf2d& theT); + + void operator *= (const gp_Trsf2d& theT) { Multiply (theT); } + + //! Computes the transformation composed from and theT. + //! = theT * + Standard_EXPORT void PreMultiply (const gp_Trsf2d& theT); + + Standard_EXPORT void Power (const Standard_Integer theN); //! Computes the following composition of transformations - //! * * .......* , N time. - //! if N = 0 = Identity - //! if N < 0 = .Inverse() *...........* .Inverse(). + //! * * .......* , theN time. + //! if theN = 0 = Identity + //! if theN < 0 = .Inverse() *...........* .Inverse(). //! - //! Raises if N < 0 and if the matrix of the transformation not + //! Raises if theN < 0 and if the matrix of the transformation not //! inversible. - gp_Trsf2d Powered (const Standard_Integer N); - - void Transforms (Standard_Real& X, Standard_Real& Y) const; - + gp_Trsf2d Powered (const Standard_Integer theN) + { + gp_Trsf2d aT = *this; + aT.Power (theN); + return aT; + } + + void Transforms (Standard_Real& theX, Standard_Real& theY) const; + //! Transforms a doublet XY with a Trsf2d - void Transforms (gp_XY& Coord) const; - + void Transforms (gp_XY& theCoord) const; + //! Sets the coefficients of the transformation. The //! transformation of the point x,y is the point //! x',y' with : @@ -215,36 +199,164 @@ void operator *= (const gp_Trsf2d& T) //! If the matrix as not a uniform scale it will be orthogonalized before future using. Standard_EXPORT void SetValues (const Standard_Real a11, const Standard_Real a12, const Standard_Real a13, const Standard_Real a21, const Standard_Real a22, const Standard_Real a23); - friend class gp_GTrsf2d; - protected: - //! Makes orthogonalization of "matrix" Standard_EXPORT void Orthogonalize(); - - - private: - - Standard_Real scale; gp_TrsfForm shape; gp_Mat2d matrix; gp_XY loc; - }; +#include +#include -#include +//======================================================================= +//function : gp_Trsf2d +// purpose : +//======================================================================= +inline gp_Trsf2d::gp_Trsf2d() +{ + shape = gp_Identity; + scale = 1.0; + matrix.SetIdentity(); + loc.SetCoord (0.0, 0.0); +} +//======================================================================= +//function : gp_Trsf2d +// purpose : +//======================================================================= +inline gp_Trsf2d::gp_Trsf2d (const gp_Trsf& theT) +: scale (theT.ScaleFactor()), + shape (theT.Form()), + loc (theT.TranslationPart().X(), theT.TranslationPart().Y()) +{ + const gp_Mat& M = theT.HVectorialPart(); + matrix(1,1) = M(1,1); + matrix(1,2) = M(1,2); + matrix(2,1) = M(2,1); + matrix(2,2) = M(2,2); +} +//======================================================================= +//function : SetRotation +// purpose : +//======================================================================= +inline void gp_Trsf2d::SetRotation (const gp_Pnt2d& theP, + const Standard_Real theAng) +{ + shape = gp_Rotation; + scale = 1.0; + loc = theP.XY (); + loc.Reverse (); + matrix.SetRotation (theAng); + loc.Multiply (matrix); + loc.Add (theP.XY()); +} +//======================================================================= +//function : SetMirror +// purpose : +//======================================================================= +inline void gp_Trsf2d::SetMirror (const gp_Pnt2d& theP) +{ + shape = gp_PntMirror; + scale = -1.0; + matrix.SetIdentity(); + loc = theP.XY(); + loc.Multiply (2.0); +} +//======================================================================= +//function : SetScale +// purpose : +//======================================================================= +inline void gp_Trsf2d::SetScale (const gp_Pnt2d& theP, const Standard_Real theS) +{ + shape = gp_Scale; + scale = theS; + matrix.SetIdentity(); + loc = theP.XY(); + loc.Multiply (1.0 - theS); +} + +//======================================================================= +//function : SetTranslation +// purpose : +//======================================================================= +inline void gp_Trsf2d::SetTranslation (const gp_Vec2d& theV) +{ + shape = gp_Translation; + scale = 1.0; + matrix.SetIdentity(); + loc = theV.XY(); +} + +//======================================================================= +//function : SetTranslation +// purpose : +//======================================================================= +inline void gp_Trsf2d::SetTranslation (const gp_Pnt2d& theP1, const gp_Pnt2d& theP2) +{ + shape = gp_Translation; + scale = 1.0; + matrix.SetIdentity(); + loc = (theP2.XY()).Subtracted (theP1.XY()); +} + +//======================================================================= +//function : Value +// purpose : +//======================================================================= +inline Standard_Real gp_Trsf2d::Value (const Standard_Integer theRow, const Standard_Integer theCol) const +{ + Standard_OutOfRange_Raise_if (theRow < 1 || theRow > 2 || theCol < 1 || theCol > 3, " "); + if (theCol < 3) + { + return scale * matrix.Value (theRow, theCol); + } + else + { + return loc.Coord (theRow); + } +} + +//======================================================================= +//function : Transforms +// purpose : +//======================================================================= +inline void gp_Trsf2d::Transforms (Standard_Real& theX, Standard_Real& theY) const +{ + gp_XY aDoublet(theX, theY); + aDoublet.Multiply (matrix); + if (scale != 1.0) + { + aDoublet.Multiply (scale); + } + aDoublet.Add (loc); + aDoublet.Coord (theX, theY); +} + +//======================================================================= +//function : Transforms +// purpose : +//======================================================================= +inline void gp_Trsf2d::Transforms (gp_XY& theCoord) const +{ + theCoord.Multiply (matrix); + if (scale != 1.0) + { + theCoord.Multiply (scale); + } + theCoord.Add (loc); +} #endif // _gp_Trsf2d_HeaderFile diff --git a/src/gp/gp_Trsf2d.lxx b/src/gp/gp_Trsf2d.lxx deleted file mode 100644 index 0dad11cbce..0000000000 --- a/src/gp/gp_Trsf2d.lxx +++ /dev/null @@ -1,145 +0,0 @@ -// Copyright (c) 1995-1999 Matra Datavision -// Copyright (c) 1999-2014 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -#include -#include - -inline gp_Trsf2d::gp_Trsf2d () { - shape = gp_Identity; - scale = 1.0; - matrix.SetIdentity (); - loc.SetCoord (0.0, 0.0); -} - -inline gp_Trsf2d::gp_Trsf2d (const gp_Trsf& T) : -scale(T.ScaleFactor()), -shape(T.Form()), -loc(T.TranslationPart().X(),T.TranslationPart().Y()) -{ - const gp_Mat& M = T.HVectorialPart(); - matrix(1,1) = M(1,1); - matrix(1,2) = M(1,2); - matrix(2,1) = M(2,1); - matrix(2,2) = M(2,2); -} - -inline void gp_Trsf2d::SetMirror(const gp_Pnt2d& P) -{ - shape = gp_PntMirror; - scale = -1.0; - matrix.SetIdentity (); - loc = P.XY(); - loc.Multiply (2.0); -} - -inline void gp_Trsf2d::SetRotation (const gp_Pnt2d& P, - const Standard_Real Ang) -{ - shape = gp_Rotation; - scale = 1.0; - loc = P.XY (); - loc.Reverse (); - matrix.SetRotation (Ang); - loc.Multiply (matrix); - loc.Add (P.XY()); -} - -inline void gp_Trsf2d::SetScale (const gp_Pnt2d& P, - const Standard_Real S) -{ - shape = gp_Scale; - scale = S; - matrix.SetIdentity (); - loc = P.XY (); - loc.Multiply (1.0 - S); -} - -inline void gp_Trsf2d::SetTranslation(const gp_Vec2d& V) -{ - shape = gp_Translation; - scale = 1.0; - matrix.SetIdentity (); - loc = V.XY (); -} - -inline void gp_Trsf2d::SetTranslation (const gp_Pnt2d& P1, - const gp_Pnt2d& P2) -{ - shape = gp_Translation; - scale = 1.0; - matrix.SetIdentity (); - loc = (P2.XY()).Subtracted (P1.XY()); -} - -inline Standard_Boolean gp_Trsf2d::IsNegative() const -{ return (matrix.Determinant() < 0.0); } - -inline const gp_XY& gp_Trsf2d::TranslationPart () const -{ return loc; } - -inline const gp_Mat2d& gp_Trsf2d::HVectorialPart () const -{ return matrix; } - -inline Standard_Real gp_Trsf2d::Value (const Standard_Integer Row, - const Standard_Integer Col) const -{ - Standard_OutOfRange_Raise_if - (Row < 1 || Row > 2 || Col < 1 || Col > 3, " "); - if (Col < 3) return scale * matrix.Value (Row, Col); - else return loc.Coord (Row); -} - -inline gp_TrsfForm gp_Trsf2d::Form() const -{ return shape; } - -inline Standard_Real gp_Trsf2d::ScaleFactor() const -{ return scale; } - -inline gp_Trsf2d gp_Trsf2d::Inverted() const -{ - gp_Trsf2d T = *this; - T.Invert(); - return T; -} - -inline gp_Trsf2d gp_Trsf2d::Multiplied (const gp_Trsf2d& T) const { - gp_Trsf2d Tresult(*this); - Tresult.Multiply(T); - return Tresult; -} - -inline gp_Trsf2d gp_Trsf2d::Powered (const Standard_Integer N) -{ - gp_Trsf2d T = *this; - T.Power (N); - return T; -} - -inline void gp_Trsf2d::Transforms (Standard_Real& X, - Standard_Real& Y) const -{ - gp_XY Doublet (X, Y); - Doublet.Multiply (matrix); - if (scale != 1.0) Doublet.Multiply (scale); - Doublet.Add(loc); - Doublet.Coord (X, Y); -} - -inline void gp_Trsf2d::Transforms (gp_XY& Coord) const -{ - Coord.Multiply (matrix); - if (scale != 1.0) Coord.Multiply (scale); - Coord.Add(loc); -} - diff --git a/src/gp/gp_Vec.cxx b/src/gp/gp_Vec.cxx index 5b6d0662f2..b77e7a1780 100644 --- a/src/gp/gp_Vec.cxx +++ b/src/gp/gp_Vec.cxx @@ -18,6 +18,7 @@ #define No_Standard_OutOfRange +#include #include #include @@ -25,7 +26,6 @@ #include #include #include -#include #include #include #include diff --git a/src/gp/gp_Vec.hxx b/src/gp/gp_Vec.hxx index b537f560b0..cf17c857b0 100644 --- a/src/gp/gp_Vec.hxx +++ b/src/gp/gp_Vec.hxx @@ -15,27 +15,18 @@ #ifndef _gp_Vec_HeaderFile #define _gp_Vec_HeaderFile -#include -#include -#include - +#include #include -#include -#include -#include -class Standard_ConstructionError; -class Standard_DomainError; -class Standard_OutOfRange; -class gp_VectorWithNullMagnitude; +#include +#include +#include + class gp_Dir; -class gp_XYZ; class gp_Pnt; class gp_Ax1; class gp_Ax2; class gp_Trsf; - - //! Defines a non-persistent vector in 3D space. class gp_Vec { @@ -43,344 +34,485 @@ public: DEFINE_STANDARD_ALLOC - //! Creates a zero vector. - gp_Vec(); - - //! Creates a unitary vector from a direction V. - gp_Vec(const gp_Dir& V); - + gp_Vec() {} + + //! Creates a unitary vector from a direction theV. + gp_Vec (const gp_Dir& theV); + //! Creates a vector with a triplet of coordinates. - gp_Vec(const gp_XYZ& Coord); - + gp_Vec (const gp_XYZ& theCoord) + : coord (theCoord) + {} + //! Creates a point with its three cartesian coordinates. - gp_Vec(const Standard_Real Xv, const Standard_Real Yv, const Standard_Real Zv); - + gp_Vec (const Standard_Real theXv, const Standard_Real theYv, const Standard_Real theZv) + : coord (theXv, theYv, theZv) + {} //! Creates a vector from two points. The length of the vector - //! is the distance between P1 and P2 - gp_Vec(const gp_Pnt& P1, const gp_Pnt& P2); - - //! Changes the coordinate of range Index - //! Index = 1 => X is modified - //! Index = 2 => Y is modified - //! Index = 3 => Z is modified - //! Raised if Index != {1, 2, 3}. - void SetCoord (const Standard_Integer Index, const Standard_Real Xi); - - //! For this vector, assigns - //! - the values Xv, Yv and Zv to its three coordinates. - void SetCoord (const Standard_Real Xv, const Standard_Real Yv, const Standard_Real Zv); - - //! Assigns the given value to the X coordinate of this vector. - void SetX (const Standard_Real X); - - //! Assigns the given value to the X coordinate of this vector. - void SetY (const Standard_Real Y); - - //! Assigns the given value to the X coordinate of this vector. - void SetZ (const Standard_Real Z); - - //! Assigns the three coordinates of Coord to this vector. - void SetXYZ (const gp_XYZ& Coord); - + //! is the distance between theP1 and theP2 + gp_Vec (const gp_Pnt& theP1, const gp_Pnt& theP2); + + //! Changes the coordinate of range theIndex + //! theIndex = 1 => X is modified + //! theIndex = 2 => Y is modified + //! theIndex = 3 => Z is modified + //! Raised if theIndex != {1, 2, 3}. + void SetCoord (const Standard_Integer theIndex, const Standard_Real theXi) { coord.SetCoord (theIndex, theXi); } + + //! For this vector, assigns + //! - the values theXv, theYv and theZv to its three coordinates. + void SetCoord (const Standard_Real theXv, const Standard_Real theYv, const Standard_Real theZv) + { + coord.SetX (theXv); + coord.SetY (theYv); + coord.SetZ (theZv); + } + + //! Assigns the given value to the X coordinate of this vector. + void SetX (const Standard_Real theX) { coord.SetX(theX); } + + //! Assigns the given value to the X coordinate of this vector. + void SetY (const Standard_Real theY) { coord.SetY (theY); } + + //! Assigns the given value to the X coordinate of this vector. + void SetZ (const Standard_Real theZ) { coord.SetZ (theZ); } + + //! Assigns the three coordinates of theCoord to this vector. + void SetXYZ (const gp_XYZ& theCoord) { coord = theCoord; } + + //! Returns the coordinate of range theIndex : + //! theIndex = 1 => X is returned + //! theIndex = 2 => Y is returned + //! theIndex = 3 => Z is returned + //! Raised if theIndex != {1, 2, 3}. + Standard_Real Coord (const Standard_Integer theIndex) const { return coord.Coord (theIndex); } + + //! For this vector returns its three coordinates theXv, theYv, and theZv inline + void Coord (Standard_Real& theXv, Standard_Real& theYv, Standard_Real& theZv) const + { + theXv = coord.X(); + theYv = coord.Y(); + theZv = coord.Z(); + } - //! Returns the coordinate of range Index : - //! Index = 1 => X is returned - //! Index = 2 => Y is returned - //! Index = 3 => Z is returned - //! Raised if Index != {1, 2, 3}. - Standard_Real Coord (const Standard_Integer Index) const; - - //! For this vector returns its three coordinates Xv, Yv, and Zvinline - void Coord (Standard_Real& Xv, Standard_Real& Yv, Standard_Real& Zv) const; - //! For this vector, returns its X coordinate. - Standard_Real X() const; - + Standard_Real X() const { return coord.X(); } + //! For this vector, returns its Y coordinate. - Standard_Real Y() const; - + Standard_Real Y() const { return coord.Y(); } + //! For this vector, returns its Z coordinate. - Standard_Real Z() const; - + Standard_Real Z() const { return coord.Z(); } + //! For this vector, returns //! - its three coordinates as a number triple - const gp_XYZ& XYZ() const; - + const gp_XYZ& XYZ() const { return coord; } //! Returns True if the two vectors have the same magnitude value - //! and the same direction. The precision values are LinearTolerance - //! for the magnitude and AngularTolerance for the direction. - Standard_EXPORT Standard_Boolean IsEqual (const gp_Vec& Other, const Standard_Real LinearTolerance, const Standard_Real AngularTolerance) const; - + //! and the same direction. The precision values are theLinearTolerance + //! for the magnitude and theAngularTolerance for the direction. + Standard_EXPORT Standard_Boolean IsEqual (const gp_Vec& theOther, const Standard_Real theLinearTolerance, const Standard_Real theAngularTolerance) const; - //! Returns True if abs(.Angle(Other) - PI/2.) <= AngularTolerance + //! Returns True if abs(.Angle(theOther) - PI/2.) <= theAngularTolerance + //! Raises VectorWithNullMagnitude if .Magnitude() <= Resolution or + //! theOther.Magnitude() <= Resolution from gp + Standard_Boolean IsNormal (const gp_Vec& theOther, const Standard_Real theAngularTolerance) const; + + //! Returns True if PI - .Angle(theOther) <= theAngularTolerance //! Raises VectorWithNullMagnitude if .Magnitude() <= Resolution or //! Other.Magnitude() <= Resolution from gp - Standard_Boolean IsNormal (const gp_Vec& Other, const Standard_Real AngularTolerance) const; - + Standard_Boolean IsOpposite (const gp_Vec& theOther, const Standard_Real theAngularTolerance) const + { + Standard_Real anAng = M_PI - Angle (theOther); + return anAng <= theAngularTolerance; + } - //! Returns True if PI - .Angle(Other) <= AngularTolerance - //! Raises VectorWithNullMagnitude if .Magnitude() <= Resolution or - //! Other.Magnitude() <= Resolution from gp - Standard_Boolean IsOpposite (const gp_Vec& Other, const Standard_Real AngularTolerance) const; - - - //! Returns True if Angle(, Other) <= AngularTolerance or - //! PI - Angle(, Other) <= AngularTolerance + //! Returns True if Angle(, theOther) <= theAngularTolerance or + //! PI - Angle(, theOther) <= theAngularTolerance //! This definition means that two parallel vectors cannot define //! a plane but two vectors with opposite directions are considered //! as parallel. Raises VectorWithNullMagnitude if .Magnitude() <= Resolution or //! Other.Magnitude() <= Resolution from gp - Standard_Boolean IsParallel (const gp_Vec& Other, const Standard_Real AngularTolerance) const; - + Standard_Boolean IsParallel (const gp_Vec& theOther, const Standard_Real theAngularTolerance) const + { + Standard_Real anAng = Angle (theOther); + return anAng <= theAngularTolerance || M_PI - anAng <= theAngularTolerance; + } - //! Computes the angular value between and + //! Computes the angular value between and //! Returns the angle value between 0 and PI in radian. //! Raises VectorWithNullMagnitude if .Magnitude() <= Resolution from gp or - //! Other.Magnitude() <= Resolution because the angular value is + //! theOther.Magnitude() <= Resolution because the angular value is //! indefinite if one of the vectors has a null magnitude. - Standard_Real Angle (const gp_Vec& Other) const; - + Standard_Real Angle (const gp_Vec& theOther) const; + //! Computes the angle, in radians, between this vector and - //! vector Other. The result is a value between -Pi and Pi. - //! For this, VRef defines the positive sense of rotation: the - //! angular value is positive, if the cross product this ^ Other - //! has the same orientation as VRef relative to the plane - //! defined by the vectors this and Other. Otherwise, the + //! vector theOther. The result is a value between -Pi and Pi. + //! For this, theVRef defines the positive sense of rotation: the + //! angular value is positive, if the cross product this ^ theOther + //! has the same orientation as theVRef relative to the plane + //! defined by the vectors this and theOther. Otherwise, the //! angular value is negative. //! Exceptions //! gp_VectorWithNullMagnitude if the magnitude of this - //! vector, the vector Other, or the vector VRef is less than or + //! vector, the vector theOther, or the vector theVRef is less than or //! equal to gp::Resolution(). - //! Standard_DomainError if this vector, the vector Other, - //! and the vector VRef are coplanar, unless this vector and - //! the vector Other are parallel. - Standard_Real AngleWithRef (const gp_Vec& Other, const gp_Vec& VRef) const; - + //! Standard_DomainError if this vector, the vector theOther, + //! and the vector theVRef are coplanar, unless this vector and + //! the vector theOther are parallel. + Standard_Real AngleWithRef (const gp_Vec& theOther, const gp_Vec& theVRef) const; + //! Computes the magnitude of this vector. - Standard_Real Magnitude() const; - + Standard_Real Magnitude() const { return coord.Modulus(); } + //! Computes the square magnitude of this vector. - Standard_Real SquareMagnitude() const; - + Standard_Real SquareMagnitude() const { return coord.SquareModulus(); } + //! Adds two vectors - void Add (const gp_Vec& Other); - void operator += (const gp_Vec& Other) -{ - Add(Other); -} - + void Add (const gp_Vec& theOther) { coord.Add (theOther.coord); } + + void operator += (const gp_Vec& theOther) { Add (theOther); } + //! Adds two vectors - Standard_NODISCARD gp_Vec Added (const gp_Vec& Other) const; - Standard_NODISCARD gp_Vec operator + (const gp_Vec& Other) const -{ - return Added(Other); -} - + Standard_NODISCARD gp_Vec Added (const gp_Vec& theOther) const + { + gp_Vec aV = *this; + aV.coord.Add (theOther.coord); + return aV; + } + + Standard_NODISCARD gp_Vec operator + (const gp_Vec& theOther) const { return Added (theOther); } + //! Subtracts two vectors - void Subtract (const gp_Vec& Right); - void operator -= (const gp_Vec& Right) -{ - Subtract(Right); -} - + void Subtract (const gp_Vec& theRight) { coord.Subtract (theRight.coord); } + + void operator -= (const gp_Vec& theRight) { Subtract (theRight); } + //! Subtracts two vectors - Standard_NODISCARD gp_Vec Subtracted (const gp_Vec& Right) const; - Standard_NODISCARD gp_Vec operator - (const gp_Vec& Right) const -{ - return Subtracted(Right); -} - + Standard_NODISCARD gp_Vec Subtracted (const gp_Vec& theRight) const + { + gp_Vec aV = *this; + aV.coord.Subtract (theRight.coord); + return aV; + } + + Standard_NODISCARD gp_Vec operator - (const gp_Vec& theRight) const { return Subtracted (theRight); } + //! Multiplies a vector by a scalar - void Multiply (const Standard_Real Scalar); - void operator *= (const Standard_Real Scalar) -{ - Multiply(Scalar); -} - + void Multiply (const Standard_Real theScalar) { coord.Multiply (theScalar); } + + void operator *= (const Standard_Real theScalar) { Multiply (theScalar); } + //! Multiplies a vector by a scalar - Standard_NODISCARD gp_Vec Multiplied (const Standard_Real Scalar) const; - Standard_NODISCARD gp_Vec operator * (const Standard_Real Scalar) const -{ - return Multiplied(Scalar); -} - + Standard_NODISCARD gp_Vec Multiplied (const Standard_Real theScalar) const + { + gp_Vec aV = *this; + aV.coord.Multiply (theScalar); + return aV; + } + + Standard_NODISCARD gp_Vec operator * (const Standard_Real theScalar) const { return Multiplied (theScalar); } + //! Divides a vector by a scalar - void Divide (const Standard_Real Scalar); - void operator /= (const Standard_Real Scalar) -{ - Divide(Scalar); -} - + void Divide (const Standard_Real theScalar) { coord.Divide (theScalar); } + + void operator /= (const Standard_Real theScalar) { Divide (theScalar); } + //! Divides a vector by a scalar - Standard_NODISCARD gp_Vec Divided (const Standard_Real Scalar) const; - Standard_NODISCARD gp_Vec operator / (const Standard_Real Scalar) const -{ - return Divided(Scalar); -} - + Standard_NODISCARD gp_Vec Divided (const Standard_Real theScalar) const + { + gp_Vec aV = *this; + aV.coord.Divide (theScalar); + return aV; + } + + Standard_NODISCARD gp_Vec operator / (const Standard_Real theScalar) const { return Divided (theScalar); } + //! computes the cross product between two vectors - void Cross (const gp_Vec& Right); - void operator ^= (const gp_Vec& Right) -{ - Cross(Right); -} - + void Cross (const gp_Vec& theRight) { coord.Cross (theRight.coord); } + + void operator ^= (const gp_Vec& theRight) { Cross (theRight); } + //! computes the cross product between two vectors - Standard_NODISCARD gp_Vec Crossed (const gp_Vec& Right) const; - Standard_NODISCARD gp_Vec operator ^ (const gp_Vec& Right) const -{ - return Crossed(Right); -} - + Standard_NODISCARD gp_Vec Crossed (const gp_Vec& theRight) const + { + gp_Vec aV = *this; + aV.coord.Cross (theRight.coord); + return aV; + } + + Standard_NODISCARD gp_Vec operator ^ (const gp_Vec& theRight) const { return Crossed (theRight); } //! Computes the magnitude of the cross - //! product between and Right. - //! Returns || ^ Right || - Standard_Real CrossMagnitude (const gp_Vec& Right) const; - + //! product between and theRight. + //! Returns || ^ theRight || + Standard_Real CrossMagnitude (const gp_Vec& theRight) const { return coord.CrossMagnitude (theRight.coord); } //! Computes the square magnitude of - //! the cross product between and Right. - //! Returns || ^ Right ||**2 - Standard_Real CrossSquareMagnitude (const gp_Vec& Right) const; - + //! the cross product between and theRight. + //! Returns || ^ theRight ||**2 + Standard_Real CrossSquareMagnitude (const gp_Vec& theRight) const + { + return coord.CrossSquareMagnitude (theRight.coord); + } + //! Computes the triple vector product. - //! ^= (V1 ^ V2) - void CrossCross (const gp_Vec& V1, const gp_Vec& V2); - + //! ^= (theV1 ^ theV2) + void CrossCross (const gp_Vec& theV1, const gp_Vec& theV2) + { + coord.CrossCross (theV1.coord, theV2.coord); + } + //! Computes the triple vector product. - //! ^ (V1 ^ V2) - Standard_NODISCARD gp_Vec CrossCrossed (const gp_Vec& V1, const gp_Vec& V2) const; - + //! ^ (theV1 ^ theV2) + Standard_NODISCARD gp_Vec CrossCrossed (const gp_Vec& theV1, const gp_Vec& theV2) const + { + gp_Vec aV = *this; + aV.coord.CrossCross (theV1.coord, theV2.coord); + return aV; + } + //! computes the scalar product - Standard_Real Dot (const gp_Vec& Other) const; - Standard_Real operator * (const gp_Vec& Other) const -{ - return Dot(Other); -} - - //! Computes the triple scalar product * (V1 ^ V2). - Standard_Real DotCross (const gp_Vec& V1, const gp_Vec& V2) const; - + Standard_Real Dot (const gp_Vec& theOther) const { return coord.Dot (theOther.coord); } + + Standard_Real operator * (const gp_Vec& theOther) const { return Dot (theOther); } + + //! Computes the triple scalar product * (theV1 ^ theV2). + Standard_Real DotCross (const gp_Vec& theV1, const gp_Vec& theV2) const + { + return coord.DotCross (theV1.coord, theV2.coord); + } + //! normalizes a vector //! Raises an exception if the magnitude of the vector is //! lower or equal to Resolution from gp. - void Normalize(); - + void Normalize() + { + Standard_Real aD = coord.Modulus(); + Standard_ConstructionError_Raise_if (aD <= gp::Resolution(), "gp_Vec::Normalize() - vector has zero norm"); + coord.Divide (aD); + } + //! normalizes a vector //! Raises an exception if the magnitude of the vector is //! lower or equal to Resolution from gp. - Standard_NODISCARD gp_Vec Normalized() const; - + Standard_NODISCARD gp_Vec Normalized() const; + //! Reverses the direction of a vector - void Reverse(); - + void Reverse() { coord.Reverse(); } + //! Reverses the direction of a vector - Standard_NODISCARD gp_Vec Reversed() const; - Standard_NODISCARD gp_Vec operator -() const -{ - return Reversed(); -} - + Standard_NODISCARD gp_Vec Reversed() const + { + gp_Vec aV = *this; + aV.coord.Reverse(); + return aV; + } + + Standard_NODISCARD gp_Vec operator -() const { return Reversed(); } //! is set to the following linear form : - //! A1 * V1 + A2 * V2 + A3 * V3 + V4 - void SetLinearForm (const Standard_Real A1, const gp_Vec& V1, const Standard_Real A2, const gp_Vec& V2, const Standard_Real A3, const gp_Vec& V3, const gp_Vec& V4); - + //! theA1 * theV1 + theA2 * theV2 + theA3 * theV3 + theV4 + void SetLinearForm (const Standard_Real theA1, const gp_Vec& theV1, + const Standard_Real theA2, const gp_Vec& theV2, + const Standard_Real theA3, const gp_Vec& theV3, const gp_Vec& theV4) + { + coord.SetLinearForm (theA1, theV1.coord, theA2, theV2.coord, theA3, theV3.coord, theV4.coord); + } //! is set to the following linear form : - //! A1 * V1 + A2 * V2 + A3 * V3 - void SetLinearForm (const Standard_Real A1, const gp_Vec& V1, const Standard_Real A2, const gp_Vec& V2, const Standard_Real A3, const gp_Vec& V3); - + //! theA1 * theV1 + theA2 * theV2 + theA3 * theV3 + void SetLinearForm (const Standard_Real theA1, const gp_Vec& theV1, + const Standard_Real theA2, const gp_Vec& theV2, + const Standard_Real theA3, const gp_Vec& theV3) + { + coord.SetLinearForm (theA1, theV1.coord, theA2, theV2.coord, theA3, theV3.coord); + } //! is set to the following linear form : - //! A1 * V1 + A2 * V2 + V3 - void SetLinearForm (const Standard_Real A1, const gp_Vec& V1, const Standard_Real A2, const gp_Vec& V2, const gp_Vec& V3); - + //! theA1 * theV1 + theA2 * theV2 + theV3 + void SetLinearForm (const Standard_Real theA1, const gp_Vec& theV1, + const Standard_Real theA2, const gp_Vec& theV2, const gp_Vec& theV3) + { + coord.SetLinearForm (theA1, theV1.coord, theA2, theV2.coord, theV3.coord); + } //! is set to the following linear form : - //! A1 * V1 + A2 * V2 - void SetLinearForm (const Standard_Real A1, const gp_Vec& V1, const Standard_Real A2, const gp_Vec& V2); - + //! theA1 * theV1 + theA2 * theV2 + void SetLinearForm (const Standard_Real theA1, const gp_Vec& theV1, + const Standard_Real theA2, const gp_Vec& theV2) + { + coord.SetLinearForm (theA1, theV1.coord, theA2, theV2.coord); + } - //! is set to the following linear form : A1 * V1 + V2 - void SetLinearForm (const Standard_Real A1, const gp_Vec& V1, const gp_Vec& V2); - + //! is set to the following linear form : theA1 * theV1 + theV2 + void SetLinearForm (const Standard_Real theA1, const gp_Vec& theV1, const gp_Vec& theV2) + { + coord.SetLinearForm (theA1, theV1.coord, theV2.coord); + } - //! is set to the following linear form : V1 + V2 - void SetLinearForm (const gp_Vec& V1, const gp_Vec& V2); - - Standard_EXPORT void Mirror (const gp_Vec& V); - + //! is set to the following linear form : theV1 + theV2 + void SetLinearForm (const gp_Vec& theV1, const gp_Vec& theV2) + { + coord.SetLinearForm (theV1.coord, theV2.coord); + } + + Standard_EXPORT void Mirror (const gp_Vec& theV); //! Performs the symmetrical transformation of a vector - //! with respect to the vector V which is the center of + //! with respect to the vector theV which is the center of //! the symmetry. - Standard_NODISCARD Standard_EXPORT gp_Vec Mirrored (const gp_Vec& V) const; - - Standard_EXPORT void Mirror (const gp_Ax1& A1); - + Standard_NODISCARD Standard_EXPORT gp_Vec Mirrored (const gp_Vec& theV) const; + + Standard_EXPORT void Mirror (const gp_Ax1& theA1); //! Performs the symmetrical transformation of a vector //! with respect to an axis placement which is the axis //! of the symmetry. - Standard_NODISCARD Standard_EXPORT gp_Vec Mirrored (const gp_Ax1& A1) const; - - Standard_EXPORT void Mirror (const gp_Ax2& A2); - + Standard_NODISCARD Standard_EXPORT gp_Vec Mirrored (const gp_Ax1& theA1) const; + + Standard_EXPORT void Mirror (const gp_Ax2& theA2); //! Performs the symmetrical transformation of a vector - //! with respect to a plane. The axis placement A2 locates + //! with respect to a plane. The axis placement theA2 locates //! the plane of the symmetry : (Location, XDirection, YDirection). - Standard_NODISCARD Standard_EXPORT gp_Vec Mirrored (const gp_Ax2& A2) const; - - void Rotate (const gp_Ax1& A1, const Standard_Real Ang); - + Standard_NODISCARD Standard_EXPORT gp_Vec Mirrored (const gp_Ax2& theA2) const; + + void Rotate (const gp_Ax1& theA1, const Standard_Real theAng); + + //! Rotates a vector. theA1 is the axis of the rotation. + //! theAng is the angular value of the rotation in radians. + Standard_NODISCARD gp_Vec Rotated (const gp_Ax1& theA1, const Standard_Real theAng) const + { + gp_Vec aVres = *this; + aVres.Rotate (theA1, theAng); + return aVres; + } + + void Scale (const Standard_Real theS) { coord.Multiply (theS); } + + //! Scales a vector. theS is the scaling value. + Standard_NODISCARD gp_Vec Scaled (const Standard_Real theS) const + { + gp_Vec aV = *this; + aV.coord.Multiply (theS); + return aV; + } + + //! Transforms a vector with the transformation theT. + Standard_EXPORT void Transform (const gp_Trsf& theT); + + //! Transforms a vector with the transformation theT. + Standard_NODISCARD gp_Vec Transformed (const gp_Trsf& theT) const + { + gp_Vec aV = *this; + aV.Transform (theT); + return aV; + } - //! Rotates a vector. A1 is the axis of the rotation. - //! Ang is the angular value of the rotation in radians. - Standard_NODISCARD gp_Vec Rotated (const gp_Ax1& A1, const Standard_Real Ang) const; - - void Scale (const Standard_Real S); - - //! Scales a vector. S is the scaling value. - Standard_NODISCARD gp_Vec Scaled (const Standard_Real S) const; - - //! Transforms a vector with the transformation T. - Standard_EXPORT void Transform (const gp_Trsf& T); - - //! Transforms a vector with the transformation T. - Standard_NODISCARD gp_Vec Transformed (const gp_Trsf& T) const; - //! Dumps the content of me into the stream Standard_EXPORT void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const; - - - -protected: - - - - - private: - - gp_XYZ coord; - }; -#include +#include +#include +#include +#include +//======================================================================= +//function : gp_Vec +// purpose : +//======================================================================= +inline gp_Vec::gp_Vec (const gp_Dir& theV) +{ + coord = theV.XYZ(); +} +//======================================================================= +//function : gp_Vec +// purpose : +//======================================================================= +inline gp_Vec::gp_Vec (const gp_Pnt& theP1, const gp_Pnt& theP2) +{ + coord = theP2.XYZ().Subtracted (theP1.XYZ()); +} +//======================================================================= +//function : IsNormal +// purpose : +//======================================================================= +inline Standard_Boolean gp_Vec::IsNormal (const gp_Vec& theOther, const Standard_Real theAngularTolerance) const +{ + Standard_Real anAng = M_PI / 2.0 - Angle (theOther); + if (anAng < 0) + { + anAng = -anAng; + } + return anAng <= theAngularTolerance; +} +//======================================================================= +//function : Angle +// purpose : +//======================================================================= +inline Standard_Real gp_Vec::Angle (const gp_Vec& theOther) const +{ + gp_VectorWithNullMagnitude_Raise_if (coord.Modulus() <= gp::Resolution() || + theOther.coord.Modulus() <= gp::Resolution(), " "); + return (gp_Dir (coord)).Angle (theOther); +} + +//======================================================================= +//function : AngleWithRef +// purpose : +//======================================================================= +inline Standard_Real gp_Vec::AngleWithRef (const gp_Vec& theOther, const gp_Vec& theVRef) const +{ + gp_VectorWithNullMagnitude_Raise_if (coord.Modulus() <= gp::Resolution() || + theVRef.coord.Modulus() <= gp::Resolution() || + theOther.coord.Modulus() <= gp::Resolution(), " "); + return (gp_Dir (coord)).AngleWithRef (theOther, theVRef); +} + +//======================================================================= +//function : Normalized +// purpose : +//======================================================================= +inline gp_Vec gp_Vec::Normalized() const +{ + Standard_Real aD = coord.Modulus(); + Standard_ConstructionError_Raise_if (aD <= gp::Resolution(), "gp_Vec::Normalized() - vector has zero norm"); + gp_Vec aV = *this; + aV.coord.Divide (aD); + return aV; +} + +//======================================================================= +//function : Rotate +// purpose : +//======================================================================= +inline void gp_Vec::Rotate (const gp_Ax1& theA1, const Standard_Real theAng) +{ + gp_Trsf aT; + aT.SetRotation (theA1, theAng); + coord.Multiply (aT.VectorialPart()); +} + +//======================================================================= +//function : operator* +// purpose : +//======================================================================= +inline gp_Vec operator* (const Standard_Real theScalar, const gp_Vec& theV) +{ + return theV.Multiplied(theScalar); +} #endif // _gp_Vec_HeaderFile diff --git a/src/gp/gp_Vec.lxx b/src/gp/gp_Vec.lxx deleted file mode 100644 index 40283e9469..0000000000 --- a/src/gp/gp_Vec.lxx +++ /dev/null @@ -1,324 +0,0 @@ -// Copyright (c) 1995-1999 Matra Datavision -// Copyright (c) 1999-2014 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -// Modif JCV 07/12/90 introduction classe XYZ dans le package gp -// LPA et JCV 07/92 mise a jour - -#include -#include -#include -#include -#include -#include - -inline gp_Vec::gp_Vec() { } - -inline gp_Vec::gp_Vec (const gp_Dir& V) { coord = V.XYZ(); } - -inline gp_Vec::gp_Vec (const gp_XYZ& Coord) : coord(Coord) { } - -inline gp_Vec::gp_Vec (const Standard_Real Xv, - const Standard_Real Yv, - const Standard_Real Zv) - : coord (Xv, Yv, Zv) { } - -inline gp_Vec::gp_Vec (const gp_Pnt& P1, - const gp_Pnt& P2) -{ coord = P2.XYZ().Subtracted(P1.XYZ()); } - -inline void gp_Vec::SetCoord (const Standard_Integer Index, - const Standard_Real Xi) -{ coord.SetCoord (Index, Xi); } - -inline void gp_Vec::SetCoord (const Standard_Real Xv, - const Standard_Real Yv, - const Standard_Real Zv) -{ - coord.SetX(Xv); - coord.SetY(Yv); - coord.SetZ(Zv); -} - -inline void gp_Vec::SetX (const Standard_Real X) -{ coord.SetX (X); } - -inline void gp_Vec::SetY (const Standard_Real Y) -{ coord.SetY (Y); } - -inline void gp_Vec::SetZ (const Standard_Real Z) -{ coord.SetZ (Z); } - -inline void gp_Vec::SetXYZ (const gp_XYZ& Coord) -{ coord = Coord; } - -inline Standard_Real gp_Vec::Coord (const Standard_Integer Index) const -{ return coord.Coord (Index); } - -inline void gp_Vec::Coord(Standard_Real& Xv, - Standard_Real& Yv, - Standard_Real& Zv) const -{ - Xv = coord.X(); - Yv = coord.Y(); - Zv = coord.Z(); -} - -inline Standard_Real gp_Vec::X() const -{ return coord.X(); } - -inline Standard_Real gp_Vec::Y() const -{ return coord.Y(); } - -inline Standard_Real gp_Vec::Z() const -{ return coord.Z(); } - -inline const gp_XYZ& gp_Vec::XYZ () const -{ return coord; } - -inline Standard_Boolean gp_Vec::IsNormal -(const gp_Vec& Other, - const Standard_Real AngularTolerance) const -{ - Standard_Real Ang = M_PI / 2.0 - Angle(Other); - if (Ang < 0) Ang = - Ang; - return Ang <= AngularTolerance; -} - -inline Standard_Boolean gp_Vec::IsOpposite -(const gp_Vec& Other, - const Standard_Real AngularTolerance) const -{ - Standard_Real Ang = M_PI - Angle(Other); - return Ang <= AngularTolerance; -} - -inline Standard_Boolean gp_Vec::IsParallel -(const gp_Vec& Other, - const Standard_Real AngularTolerance) const -{ - Standard_Real Ang = Angle (Other); - return Ang <= AngularTolerance || M_PI - Ang <= AngularTolerance; -} - -inline Standard_Real gp_Vec::Angle (const gp_Vec& Other) const -{ - // Commentaires : - // Au dessus de 45 degres l'arccos donne la meilleur precision pour le - // calcul de l'angle. Sinon il vaut mieux utiliser l'arcsin. - // Les erreurs commises sont loin d'etre negligeables lorsque l'on est - // proche de zero ou de 90 degres. - // En 3d les valeurs angulaires sont toujours positives et comprises entre - // 0 et Pi. - - gp_VectorWithNullMagnitude_Raise_if - (coord.Modulus() <= gp::Resolution() || - Other.coord.Modulus() <= gp::Resolution(), " "); - return (gp_Dir(coord)).Angle(Other); -} - -inline Standard_Real gp_Vec::AngleWithRef (const gp_Vec& Other, - const gp_Vec& Vref) const -{ - gp_VectorWithNullMagnitude_Raise_if - (coord.Modulus() <= gp::Resolution() || - Vref.coord.Modulus () <= gp::Resolution() || - Other.coord.Modulus() <= gp::Resolution(), " "); - return (gp_Dir(coord)).AngleWithRef(Other,Vref); -} - -inline Standard_Real gp_Vec::Magnitude() const -{ return coord.Modulus(); } - -inline Standard_Real gp_Vec::SquareMagnitude() const -{ return coord.SquareModulus(); } - -inline void gp_Vec::Add (const gp_Vec& Other) -{ coord.Add (Other.coord); } - -inline gp_Vec gp_Vec::Added (const gp_Vec& Other) const -{ - gp_Vec V = *this; - V.coord.Add (Other.coord); - return V; -} - -inline void gp_Vec::Subtract (const gp_Vec& Right) -{ coord.Subtract (Right.coord); } - -inline gp_Vec gp_Vec::Subtracted (const gp_Vec& Right) const -{ - gp_Vec V = *this; - V.coord.Subtract(Right.coord); - return V; -} - -inline void gp_Vec::Multiply (const Standard_Real Scalar) -{ coord.Multiply(Scalar); } - -inline gp_Vec gp_Vec::Multiplied (const Standard_Real Scalar) const -{ - gp_Vec V = *this; - V.coord.Multiply (Scalar); - return V; -} - -inline void gp_Vec::Divide (const Standard_Real Scalar) -{ coord.Divide (Scalar); } - -inline gp_Vec gp_Vec::Divided (const Standard_Real Scalar) const -{ - gp_Vec V = *this; - V.coord.Divide (Scalar); - return V; -} - -inline void gp_Vec::Cross (const gp_Vec& Right) -{ coord.Cross (Right.coord); } - -inline gp_Vec gp_Vec::Crossed (const gp_Vec& Right) const -{ - gp_Vec V = *this; - V.coord.Cross (Right.coord); - return V; -} - -inline Standard_Real gp_Vec::CrossMagnitude -(const gp_Vec& Right) const -{ return coord.CrossMagnitude (Right.coord); } - -inline Standard_Real gp_Vec::CrossSquareMagnitude -(const gp_Vec& Right) const -{ return coord.CrossSquareMagnitude (Right.coord); } - -inline void gp_Vec::CrossCross (const gp_Vec& V1, - const gp_Vec& V2) -{ coord.CrossCross(V1.coord, V2.coord); } - -inline gp_Vec gp_Vec::CrossCrossed (const gp_Vec& V1, - const gp_Vec& V2) const -{ - gp_Vec V = *this; - V.coord.CrossCross(V1.coord, V2.coord); - return V; -} - -inline Standard_Real gp_Vec::Dot (const gp_Vec& Other) const -{ return coord.Dot (Other.coord); } - -inline Standard_Real gp_Vec::DotCross (const gp_Vec& V1, - const gp_Vec& V2) const -{ return coord.DotCross (V1.coord, V2.coord); } - -inline void gp_Vec::Normalize() -{ - Standard_Real D = coord.Modulus(); - Standard_ConstructionError_Raise_if (D <= gp::Resolution(), - "gp_Vec::Normalize() - vector has zero norm"); - coord.Divide (D); -} - -inline gp_Vec gp_Vec::Normalized() const -{ - Standard_Real D = coord.Modulus(); - Standard_ConstructionError_Raise_if (D <= gp::Resolution(), - "gp_Vec::Normalized() - vector has zero norm"); - gp_Vec V = *this; - V.coord.Divide (D); - return V; -} - -inline void gp_Vec::Reverse() -{ coord.Reverse(); } - -inline gp_Vec gp_Vec::Reversed () const -{ - gp_Vec V = *this; - V.coord.Reverse(); - return V; -} - -inline void gp_Vec::SetLinearForm -(const Standard_Real L, - const gp_Vec& Left, - const Standard_Real R, - const gp_Vec& Right) -{ coord.SetLinearForm (L, Left.coord, R, Right.coord); } - -inline void gp_Vec::SetLinearForm -(const Standard_Real L, - const gp_Vec& Left, - const gp_Vec& Right) -{ coord.SetLinearForm (L, Left.coord, Right.coord); } - -inline void gp_Vec::SetLinearForm -(const gp_Vec& Left, - const gp_Vec& Right) -{ coord.SetLinearForm (Left.coord, Right.coord); } - -inline void gp_Vec::SetLinearForm -(const Standard_Real A1, const gp_Vec& V1, - const Standard_Real A2, const gp_Vec& V2, - const Standard_Real A3, const gp_Vec& V3) -{ coord.SetLinearForm (A1, V1.coord, A2, V2.coord, A3, V3.coord); } - -inline void gp_Vec::SetLinearForm -(const Standard_Real A1, const gp_Vec& V1, - const Standard_Real A2, const gp_Vec& V2, - const gp_Vec& V3) -{ coord.SetLinearForm (A1, V1.coord, A2, V2.coord, V3.coord); } - -inline void gp_Vec::SetLinearForm -(const Standard_Real A1, const gp_Vec& V1, - const Standard_Real A2, const gp_Vec& V2, - const Standard_Real A3, const gp_Vec& V3, - const gp_Vec& V4) -{ coord.SetLinearForm(A1,V1.coord,A2,V2.coord,A3,V3.coord,V4.coord); } - -inline void gp_Vec::Rotate (const gp_Ax1& A1, - const Standard_Real Ang) -{ - gp_Trsf T; - T.SetRotation (A1, Ang); - coord.Multiply (T.VectorialPart()); -} - -inline gp_Vec gp_Vec::Rotated (const gp_Ax1& A1, - const Standard_Real Ang) const -{ - gp_Vec Vres = *this; - Vres.Rotate (A1, Ang); - return Vres; -} - -inline void gp_Vec::Scale (const Standard_Real S) -{ coord.Multiply (S); } - -inline gp_Vec gp_Vec::Scaled (const Standard_Real S) const -{ - gp_Vec V = *this; - V.coord.Multiply(S); - return V; -} - -inline gp_Vec gp_Vec::Transformed (const gp_Trsf& T) const -{ - gp_Vec V = *this; - V.Transform(T); - return V; -} - -inline gp_Vec operator* (const Standard_Real Scalar, const gp_Vec& V) { - return V.Multiplied(Scalar); -} - diff --git a/src/gp/gp_Vec2d.cxx b/src/gp/gp_Vec2d.cxx index 21301c228d..227e5191b5 100644 --- a/src/gp/gp_Vec2d.cxx +++ b/src/gp/gp_Vec2d.cxx @@ -16,13 +16,13 @@ #define No_Standard_OutOfRange +#include #include #include #include #include #include -#include #include #include #include diff --git a/src/gp/gp_Vec2d.hxx b/src/gp/gp_Vec2d.hxx index b5745ba024..b1225f0ead 100644 --- a/src/gp/gp_Vec2d.hxx +++ b/src/gp/gp_Vec2d.hxx @@ -15,25 +15,16 @@ #ifndef _gp_Vec2d_HeaderFile #define _gp_Vec2d_HeaderFile -#include -#include -#include - +#include #include -#include -#include -#include -class Standard_ConstructionError; -class Standard_OutOfRange; -class gp_VectorWithNullMagnitude; +#include +#include + class gp_Dir2d; -class gp_XY; class gp_Pnt2d; class gp_Ax2d; class gp_Trsf2d; - - //! Defines a non-persistent vector in 2D space. class gp_Vec2d { @@ -41,284 +32,387 @@ public: DEFINE_STANDARD_ALLOC - //! Creates a zero vector. - gp_Vec2d(); - - //! Creates a unitary vector from a direction V. - gp_Vec2d(const gp_Dir2d& V); - + gp_Vec2d() {} + + //! Creates a unitary vector from a direction theV. + gp_Vec2d (const gp_Dir2d& theV); + //! Creates a vector with a doublet of coordinates. - gp_Vec2d(const gp_XY& Coord); - + gp_Vec2d (const gp_XY& theCoord) + : coord(theCoord) + {} + //! Creates a point with its two Cartesian coordinates. - gp_Vec2d(const Standard_Real Xv, const Standard_Real Yv); - + gp_Vec2d (const Standard_Real theXv, const Standard_Real theYv) + : coord (theXv, theYv) + {} //! Creates a vector from two points. The length of the vector - //! is the distance between P1 and P2 - gp_Vec2d(const gp_Pnt2d& P1, const gp_Pnt2d& P2); - - //! Changes the coordinate of range Index - //! Index = 1 => X is modified - //! Index = 2 => Y is modified - //! Raises OutOfRange if Index != {1, 2}. - void SetCoord (const Standard_Integer Index, const Standard_Real Xi); - - //! For this vector, assigns - //! the values Xv and Yv to its two coordinates - void SetCoord (const Standard_Real Xv, const Standard_Real Yv); - - //! Assigns the given value to the X coordinate of this vector. - void SetX (const Standard_Real X); - - //! Assigns the given value to the Y coordinate of this vector. - void SetY (const Standard_Real Y); - - //! Assigns the two coordinates of Coord to this vector. - void SetXY (const gp_XY& Coord); - + //! is the distance between theP1 and theP2 + gp_Vec2d (const gp_Pnt2d& theP1, const gp_Pnt2d& theP2); + + //! Changes the coordinate of range theIndex + //! theIndex = 1 => X is modified + //! theIndex = 2 => Y is modified + //! Raises OutOfRange if theIndex != {1, 2}. + void SetCoord (const Standard_Integer theIndex, const Standard_Real theXi) { coord.SetCoord (theIndex, theXi); } + + //! For this vector, assigns + //! the values theXv and theYv to its two coordinates + void SetCoord (const Standard_Real theXv, const Standard_Real theYv) { coord.SetCoord (theXv, theYv); } + + //! Assigns the given value to the X coordinate of this vector. + void SetX (const Standard_Real theX) { coord.SetX (theX); } + + //! Assigns the given value to the Y coordinate of this vector. + void SetY (const Standard_Real theY) { coord.SetY (theY); } + + //! Assigns the two coordinates of theCoord to this vector. + void SetXY (const gp_XY& theCoord) { coord = theCoord; } + + //! Returns the coordinate of range theIndex : + //! theIndex = 1 => X is returned + //! theIndex = 2 => Y is returned + //! Raised if theIndex != {1, 2}. + Standard_Real Coord (const Standard_Integer theIndex) const { return coord.Coord (theIndex); } + + //! For this vector, returns its two coordinates theXv and theYv + void Coord (Standard_Real& theXv, Standard_Real& theYv) const { coord.Coord (theXv, theYv); } - //! Returns the coordinate of range Index : - //! Index = 1 => X is returned - //! Index = 2 => Y is returned - //! Raised if Index != {1, 2}. - Standard_Real Coord (const Standard_Integer Index) const; - - //! For this vector, returns its two coordinates Xv and Yv - void Coord (Standard_Real& Xv, Standard_Real& Yv) const; - //! For this vector, returns its X coordinate. - Standard_Real X() const; - + Standard_Real X() const { return coord.X(); } + //! For this vector, returns its Y coordinate. - Standard_Real Y() const; - + Standard_Real Y() const { return coord.Y(); } + //! For this vector, returns its two coordinates as a number pair - const gp_XY& XY() const; - + const gp_XY& XY() const { return coord; } //! Returns True if the two vectors have the same magnitude value - //! and the same direction. The precision values are LinearTolerance - //! for the magnitude and AngularTolerance for the direction. - Standard_EXPORT Standard_Boolean IsEqual (const gp_Vec2d& Other, const Standard_Real LinearTolerance, const Standard_Real AngularTolerance) const; - + //! and the same direction. The precision values are theLinearTolerance + //! for the magnitude and theAngularTolerance for the direction. + Standard_EXPORT Standard_Boolean IsEqual (const gp_Vec2d& theOther, const Standard_Real theLinearTolerance, const Standard_Real theAngularTolerance) const; - //! Returns True if abs(Abs(.Angle(Other)) - PI/2.) - //! <= AngularTolerance + //! Returns True if abs(Abs(.Angle(theOther)) - PI/2.) + //! <= theAngularTolerance //! Raises VectorWithNullMagnitude if .Magnitude() <= Resolution or - //! Other.Magnitude() <= Resolution from gp. - Standard_Boolean IsNormal (const gp_Vec2d& Other, const Standard_Real AngularTolerance) const; - + //! theOther.Magnitude() <= Resolution from gp. + Standard_Boolean IsNormal (const gp_Vec2d& theOther, const Standard_Real theAngularTolerance) const + { + const Standard_Real anAng = Abs (M_PI_2 - Abs (Angle (theOther))); + return !(anAng > theAngularTolerance); + } - //! Returns True if PI - Abs(.Angle(Other)) <= AngularTolerance + //! Returns True if PI - Abs(.Angle(theOther)) <= theAngularTolerance //! Raises VectorWithNullMagnitude if .Magnitude() <= Resolution or - //! Other.Magnitude() <= Resolution from gp. - Standard_Boolean IsOpposite (const gp_Vec2d& Other, const Standard_Real AngularTolerance) const; - + //! theOther.Magnitude() <= Resolution from gp. + Standard_Boolean IsOpposite (const gp_Vec2d& theOther, const Standard_Real theAngularTolerance) const; - //! Returns true if Abs(Angle(, Other)) <= AngularTolerance or - //! PI - Abs(Angle(, Other)) <= AngularTolerance + //! Returns true if Abs(Angle(, theOther)) <= theAngularTolerance or + //! PI - Abs(Angle(, theOther)) <= theAngularTolerance //! Two vectors with opposite directions are considered as parallel. //! Raises VectorWithNullMagnitude if .Magnitude() <= Resolution or - //! Other.Magnitude() <= Resolution from gp - Standard_Boolean IsParallel (const gp_Vec2d& Other, const Standard_Real AngularTolerance) const; - + //! theOther.Magnitude() <= Resolution from gp + Standard_Boolean IsParallel (const gp_Vec2d& theOther, const Standard_Real theAngularTolerance) const; - //! Computes the angular value between and + //! Computes the angular value between and //! returns the angle value between -PI and PI in radian. - //! The orientation is from to Other. The positive sense is the + //! The orientation is from to theOther. The positive sense is the //! trigonometric sense. //! Raises VectorWithNullMagnitude if .Magnitude() <= Resolution from gp or - //! Other.Magnitude() <= Resolution because the angular value is + //! theOther.Magnitude() <= Resolution because the angular value is //! indefinite if one of the vectors has a null magnitude. - Standard_EXPORT Standard_Real Angle (const gp_Vec2d& Other) const; - + Standard_EXPORT Standard_Real Angle (const gp_Vec2d& theOther) const; + //! Computes the magnitude of this vector. - Standard_Real Magnitude() const; - + Standard_Real Magnitude() const { return coord.Modulus(); } + //! Computes the square magnitude of this vector. - Standard_Real SquareMagnitude() const; - - void Add (const gp_Vec2d& Other); - void operator += (const gp_Vec2d& Other) - { - Add(Other); - } - + Standard_Real SquareMagnitude() const { return coord.SquareModulus(); } + + void Add (const gp_Vec2d& theOther) { coord.Add (theOther.coord); } + + void operator += (const gp_Vec2d& theOther) { Add (theOther); } + //! Adds two vectors - Standard_NODISCARD gp_Vec2d Added (const gp_Vec2d& Other) const; - Standard_NODISCARD gp_Vec2d operator + (const gp_Vec2d& Other) const - { - return Added(Other); - } - + Standard_NODISCARD gp_Vec2d Added (const gp_Vec2d& theOther) const + { + gp_Vec2d aV = *this; + aV.coord.Add (theOther.coord); + return aV; + } + + Standard_NODISCARD gp_Vec2d operator + (const gp_Vec2d& theOther) const { return Added (theOther); } + //! Computes the crossing product between two vectors - Standard_NODISCARD Standard_Real Crossed (const gp_Vec2d& Right) const; - Standard_NODISCARD Standard_Real operator ^ (const gp_Vec2d& Right) const - { - return Crossed(Right); - } - + Standard_NODISCARD Standard_Real Crossed (const gp_Vec2d& theRight) const + { + return coord.Crossed (theRight.coord); + } + + Standard_NODISCARD Standard_Real operator ^ (const gp_Vec2d& theRight) const { return Crossed (theRight); } //! Computes the magnitude of the cross product between and - //! Right. Returns || ^ Right || - Standard_Real CrossMagnitude (const gp_Vec2d& Right) const; - + //! theRight. Returns || ^ theRight || + Standard_Real CrossMagnitude (const gp_Vec2d& theRight) const + { + return coord.CrossMagnitude (theRight.coord); + } //! Computes the square magnitude of the cross product between and - //! Right. Returns || ^ Right ||**2 - Standard_Real CrossSquareMagnitude (const gp_Vec2d& Right) const; - - void Divide (const Standard_Real Scalar); - void operator /= (const Standard_Real Scalar) - { - Divide(Scalar); - } - - //! divides a vector by a scalar - Standard_NODISCARD gp_Vec2d Divided (const Standard_Real Scalar) const; - Standard_NODISCARD gp_Vec2d operator / (const Standard_Real Scalar) const - { - return Divided(Scalar); - } - - //! Computes the scalar product - Standard_Real Dot (const gp_Vec2d& Other) const; - Standard_Real operator * (const gp_Vec2d& Other) const - { - return Dot(Other); - } + //! theRight. Returns || ^ theRight ||**2 + Standard_Real CrossSquareMagnitude (const gp_Vec2d& theRight) const + { + return coord.CrossSquareMagnitude (theRight.coord); + } + + void Divide (const Standard_Real theScalar) { coord.Divide (theScalar); } + + void operator /= (const Standard_Real theScalar) { Divide (theScalar); } + + //! divides a vector by a scalar + Standard_NODISCARD gp_Vec2d Divided (const Standard_Real theScalar) const + { + gp_Vec2d aV = *this; + aV.coord.Divide (theScalar); + return aV; + } + + Standard_NODISCARD gp_Vec2d operator / (const Standard_Real theScalar) const { return Divided (theScalar); } + + //! Computes the scalar product + Standard_Real Dot (const gp_Vec2d& theOther) const { return coord.Dot (theOther.coord); } + + Standard_Real operator * (const gp_Vec2d& theOther) const { return Dot (theOther); } + + gp_Vec2d GetNormal() const { return gp_Vec2d (this->Y(), (-1)*this->X()); } + + void Multiply (const Standard_Real theScalar) { coord.Multiply (theScalar); } + + void operator *= (const Standard_Real theScalar) { Multiply (theScalar); } - gp_Vec2d GetNormal() const; - - void Multiply (const Standard_Real Scalar); - void operator *= (const Standard_Real Scalar) - { - Multiply(Scalar); - } - //! Normalizes a vector //! Raises an exception if the magnitude of the vector is //! lower or equal to Resolution from package gp. - Standard_NODISCARD gp_Vec2d Multiplied (const Standard_Real Scalar) const; - Standard_NODISCARD gp_Vec2d operator * (const Standard_Real Scalar) const - { - return Multiplied(Scalar); - } - - void Normalize(); - + Standard_NODISCARD gp_Vec2d Multiplied (const Standard_Real theScalar) const + { + gp_Vec2d aV = *this; + aV.coord.Multiply (theScalar); + return aV; + } + + Standard_NODISCARD gp_Vec2d operator * (const Standard_Real theScalar) const { return Multiplied (theScalar); } + + void Normalize() + { + Standard_Real aD = coord.Modulus(); + Standard_ConstructionError_Raise_if (aD <= gp::Resolution(), "gp_Vec2d::Normalize() - vector has zero norm"); + coord.Divide (aD); + } + //! Normalizes a vector //! Raises an exception if the magnitude of the vector is //! lower or equal to Resolution from package gp. //! Reverses the direction of a vector - Standard_NODISCARD gp_Vec2d Normalized() const; - - void Reverse(); - + Standard_NODISCARD gp_Vec2d Normalized() const; + + void Reverse() { coord.Reverse(); } + //! Reverses the direction of a vector - Standard_NODISCARD gp_Vec2d Reversed() const; - Standard_NODISCARD gp_Vec2d operator -() const - { - return Reversed(); - } - + Standard_NODISCARD gp_Vec2d Reversed() const + { + gp_Vec2d aV = *this; + aV.coord.Reverse(); + return aV; + } + + Standard_NODISCARD gp_Vec2d operator -() const { return Reversed(); } + //! Subtracts two vectors - void Subtract (const gp_Vec2d& Right); - void operator -= (const gp_Vec2d& Right) - { - Subtract(Right); - } - + void Subtract (const gp_Vec2d& theRight) + { + coord.Subtract (theRight.coord); + } + + void operator -= (const gp_Vec2d& theRight) { Subtract (theRight); } + //! Subtracts two vectors - Standard_NODISCARD gp_Vec2d Subtracted (const gp_Vec2d& Right) const; - Standard_NODISCARD gp_Vec2d operator - (const gp_Vec2d& Right) const - { - return Subtracted(Right); - } - + Standard_NODISCARD gp_Vec2d Subtracted (const gp_Vec2d& theRight) const + { + gp_Vec2d aV = *this; + aV.coord.Subtract (theRight.coord); + return aV; + } + + Standard_NODISCARD gp_Vec2d operator - (const gp_Vec2d& theRight) const { return Subtracted (theRight); } //! is set to the following linear form : - //! A1 * V1 + A2 * V2 + V3 - void SetLinearForm (const Standard_Real A1, const gp_Vec2d& V1, const Standard_Real A2, const gp_Vec2d& V2, const gp_Vec2d& V3); - + //! theA1 * theV1 + theA2 * theV2 + theV3 + void SetLinearForm (const Standard_Real theA1, const gp_Vec2d& theV1, + const Standard_Real theA2, const gp_Vec2d& theV2, const gp_Vec2d& theV3) + { + coord.SetLinearForm (theA1, theV1.coord, theA2, theV2.coord, theV3.coord); + } - //! is set to the following linear form : A1 * V1 + A2 * V2 - void SetLinearForm (const Standard_Real A1, const gp_Vec2d& V1, const Standard_Real A2, const gp_Vec2d& V2); - + //! is set to the following linear form : theA1 * theV1 + theA2 * theV2 + void SetLinearForm (const Standard_Real theA1, const gp_Vec2d& theV1, + const Standard_Real theA2, const gp_Vec2d& theV2) + { + coord.SetLinearForm (theA1, theV1.coord, theA2, theV2.coord); + } - //! is set to the following linear form : A1 * V1 + V2 - void SetLinearForm (const Standard_Real A1, const gp_Vec2d& V1, const gp_Vec2d& V2); - + //! is set to the following linear form : theA1 * theV1 + theV2 + void SetLinearForm (const Standard_Real theA1, const gp_Vec2d& theV1, const gp_Vec2d& theV2) + { + coord.SetLinearForm (theA1, theV1.coord, theV2.coord); + } - //! is set to the following linear form : Left + Right - void SetLinearForm (const gp_Vec2d& Left, const gp_Vec2d& Right); - + //! is set to the following linear form : theV1 + theV2 + void SetLinearForm (const gp_Vec2d& theV1, const gp_Vec2d& theV2) + { + coord.SetLinearForm (theV1.coord, theV2.coord); + } //! Performs the symmetrical transformation of a vector - //! with respect to the vector V which is the center of + //! with respect to the vector theV which is the center of //! the symmetry. - Standard_EXPORT void Mirror (const gp_Vec2d& V); - - + Standard_EXPORT void Mirror (const gp_Vec2d& theV); + //! Performs the symmetrical transformation of a vector - //! with respect to the vector V which is the center of + //! with respect to the vector theV which is the center of //! the symmetry. - Standard_NODISCARD Standard_EXPORT gp_Vec2d Mirrored (const gp_Vec2d& V) const; - + Standard_NODISCARD Standard_EXPORT gp_Vec2d Mirrored (const gp_Vec2d& theV) const; //! Performs the symmetrical transformation of a vector //! with respect to an axis placement which is the axis //! of the symmetry. - Standard_EXPORT void Mirror (const gp_Ax2d& A1); - + Standard_EXPORT void Mirror (const gp_Ax2d& theA1); //! Performs the symmetrical transformation of a vector //! with respect to an axis placement which is the axis //! of the symmetry. - Standard_NODISCARD Standard_EXPORT gp_Vec2d Mirrored (const gp_Ax2d& A1) const; - - void Rotate (const Standard_Real Ang); - + Standard_NODISCARD Standard_EXPORT gp_Vec2d Mirrored (const gp_Ax2d& theA1) const; - //! Rotates a vector. Ang is the angular value of the + void Rotate (const Standard_Real theAng); + + //! Rotates a vector. theAng is the angular value of the //! rotation in radians. - Standard_NODISCARD gp_Vec2d Rotated (const Standard_Real Ang) const; - - void Scale (const Standard_Real S); - - //! Scales a vector. S is the scaling value. - Standard_NODISCARD gp_Vec2d Scaled (const Standard_Real S) const; - - Standard_EXPORT void Transform (const gp_Trsf2d& T); - + Standard_NODISCARD gp_Vec2d Rotated (const Standard_Real theAng) const + { + gp_Vec2d aV = *this; + aV.Rotate (theAng); + return aV; + } + + void Scale (const Standard_Real theS) { coord.Multiply (theS); } + + //! Scales a vector. theS is the scaling value. + Standard_NODISCARD gp_Vec2d Scaled (const Standard_Real theS) const + { + gp_Vec2d aV = *this; + aV.coord.Multiply (theS); + return aV; + } + + Standard_EXPORT void Transform (const gp_Trsf2d& theT); + //! Transforms a vector with a Trsf from gp. - Standard_NODISCARD gp_Vec2d Transformed (const gp_Trsf2d& T) const; - - - - -protected: - - - - + Standard_NODISCARD gp_Vec2d Transformed (const gp_Trsf2d& theT) const + { + gp_Vec2d aV = *this; + aV.Transform (theT); + return aV; + } private: - - gp_XY coord; - }; +#include +#include +#include -#include +//======================================================================= +//function : gp_Vec2d +// purpose : +//======================================================================= +inline gp_Vec2d::gp_Vec2d (const gp_Dir2d& theV) +{ + coord = theV.XY(); +} +//======================================================================= +//function : gp_Vec2d +// purpose : +//======================================================================= +inline gp_Vec2d::gp_Vec2d (const gp_Pnt2d& theP1, const gp_Pnt2d& theP2) +{ + coord = theP2.XY().Subtracted (theP1.XY()); +} +//======================================================================= +//function : IsOpposite +// purpose : +//======================================================================= +inline Standard_Boolean gp_Vec2d::IsOpposite (const gp_Vec2d& theOther, const Standard_Real theAngularTolerance) const +{ + Standard_Real anAng = Angle (theOther); + if (anAng < 0) + { + anAng = -anAng; + } + return M_PI - anAng <= theAngularTolerance; +} +//======================================================================= +//function : IsParallel +// purpose : +//======================================================================= +inline Standard_Boolean gp_Vec2d::IsParallel (const gp_Vec2d& theOther, const Standard_Real theAngularTolerance) const +{ + Standard_Real anAng = Angle (theOther); + if (anAng < 0) + { + anAng = -anAng; + } + return anAng <= theAngularTolerance || M_PI - anAng <= theAngularTolerance; +} +//======================================================================= +//function : Normalized +// purpose : +//======================================================================= +inline gp_Vec2d gp_Vec2d::Normalized() const +{ + Standard_Real aD = coord.Modulus(); + Standard_ConstructionError_Raise_if (aD <= gp::Resolution(), "gp_Vec2d::Normalized() - vector has zero norm"); + gp_Vec2d aV = *this; + aV.coord.Divide (aD); + return aV; +} + +//======================================================================= +//function : Rotate +// purpose : +//======================================================================= +inline void gp_Vec2d::Rotate (const Standard_Real theAng) +{ + gp_Trsf2d aT; + aT.SetRotation (gp_Pnt2d(0.0, 0.0), theAng); + coord.Multiply (aT.VectorialPart()); +} + +//======================================================================= +//function : operator* +// purpose : +//======================================================================= +inline gp_Vec2d operator* (const Standard_Real theScalar, + const gp_Vec2d& theV) +{ + return theV.Multiplied (theScalar); +} #endif // _gp_Vec2d_HeaderFile diff --git a/src/gp/gp_Vec2d.lxx b/src/gp/gp_Vec2d.lxx deleted file mode 100644 index 7f0c94bbba..0000000000 --- a/src/gp/gp_Vec2d.lxx +++ /dev/null @@ -1,246 +0,0 @@ -// Copyright (c) 1995-1999 Matra Datavision -// Copyright (c) 1999-2014 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -// Modif JCV 08/01/91 modifs suite a la deuxieme revue de projet -// et introduction des classes XY, Mat2d + nouveau operateurs - -#include -#include -#include - -inline gp_Vec2d::gp_Vec2d() -{} - -inline gp_Vec2d::gp_Vec2d (const gp_Dir2d& V) -{ coord = V.XY(); } - -inline gp_Vec2d::gp_Vec2d (const gp_XY& Coord) : coord(Coord) -{} - -inline gp_Vec2d::gp_Vec2d (const Standard_Real Xv, - const Standard_Real Yv) : coord (Xv, Yv) -{ } - -inline gp_Vec2d::gp_Vec2d (const gp_Pnt2d& P1, - const gp_Pnt2d& P2) -{ coord = P2.XY().Subtracted (P1.XY()); } - -inline void gp_Vec2d::SetCoord (const Standard_Integer Index, - const Standard_Real Xi) -{ coord.SetCoord (Index, Xi); } - -inline void gp_Vec2d::SetCoord (const Standard_Real Xv, - const Standard_Real Yv) -{ coord.SetCoord (Xv, Yv); } - -inline void gp_Vec2d::SetX (const Standard_Real X) -{ coord.SetX (X); } - -inline void gp_Vec2d::SetY (const Standard_Real Y) -{ coord.SetY (Y); } - -inline void gp_Vec2d::SetXY (const gp_XY& Coord) -{ coord = Coord; } - -inline Standard_Real gp_Vec2d::Coord (const Standard_Integer Index) const -{ return coord.Coord(Index); } - -inline void gp_Vec2d::Coord(Standard_Real& Xv, - Standard_Real& Yv) const -{ coord.Coord(Xv, Yv); } - -inline Standard_Real gp_Vec2d::X() const -{ return coord.X(); } - -inline Standard_Real gp_Vec2d::Y() const -{ return coord.Y(); } - -inline const gp_XY& gp_Vec2d::XY () const -{ return coord; } - -inline Standard_Boolean gp_Vec2d::IsNormal -(const gp_Vec2d& theOther, - const Standard_Real theAngularTolerance) const -{ - const Standard_Real anAng = Abs(M_PI_2 - Abs(Angle(theOther))); - return !(anAng > theAngularTolerance); -} - -inline Standard_Boolean gp_Vec2d::IsOpposite -(const gp_Vec2d& Other, - const Standard_Real AngularTolerance) const -{ - Standard_Real Ang = Angle(Other); - if (Ang < 0) Ang = - Ang; - return M_PI - Ang <= AngularTolerance; -} - -inline Standard_Boolean gp_Vec2d::IsParallel -(const gp_Vec2d& Other, - const Standard_Real AngularTolerance) const -{ - Standard_Real Ang = Angle(Other); - if (Ang < 0) Ang = - Ang; - return Ang <= AngularTolerance || M_PI - Ang <= AngularTolerance; -} - -inline Standard_Real gp_Vec2d::Magnitude() const -{ return coord.Modulus(); } - -inline Standard_Real gp_Vec2d::SquareMagnitude() const -{ return coord.SquareModulus(); } - -inline void gp_Vec2d::Add (const gp_Vec2d& Other) -{ coord.Add (Other.coord); } - -inline gp_Vec2d gp_Vec2d::Added (const gp_Vec2d& Other) const -{ - gp_Vec2d V = *this; - V.coord.Add (Other.coord); - return V; -} - -inline Standard_Real gp_Vec2d::Crossed (const gp_Vec2d& Right) const -{ return coord.Crossed (Right.coord); } - -inline Standard_Real gp_Vec2d::CrossMagnitude (const gp_Vec2d& Right) const -{ return coord.CrossMagnitude (Right.coord); } - -inline Standard_Real gp_Vec2d::CrossSquareMagnitude -(const gp_Vec2d& Right) const -{ return coord.CrossSquareMagnitude (Right.coord); } - -inline void gp_Vec2d::Divide (const Standard_Real Scalar) -{ coord.Divide (Scalar); } - -inline gp_Vec2d gp_Vec2d::Divided (const Standard_Real Scalar) const -{ - gp_Vec2d V = *this; - V.coord.Divide(Scalar); - return V; -} - -inline Standard_Real gp_Vec2d::Dot (const gp_Vec2d& Other) const -{ return coord.Dot (Other.coord); } - -inline void gp_Vec2d::Multiply (const Standard_Real Scalar) -{ coord.Multiply (Scalar); } - -inline gp_Vec2d gp_Vec2d::Multiplied (const Standard_Real Scalar) const -{ - gp_Vec2d V = *this; - V.coord.Multiply(Scalar); - return V; -} - -inline void gp_Vec2d::Normalize() -{ - Standard_Real D = coord.Modulus(); - Standard_ConstructionError_Raise_if (D <= gp::Resolution(), - "gp_Vec2d::Normalize() - vector has zero norm"); - coord.Divide (D); -} - -inline gp_Vec2d gp_Vec2d::Normalized() const -{ - Standard_Real D = coord.Modulus(); - Standard_ConstructionError_Raise_if (D <= gp::Resolution(), - "gp_Vec2d::Normalized() - vector has zero norm"); - gp_Vec2d V = *this; - V.coord.Divide (D); - return V; -} - -inline void gp_Vec2d::Reverse() -{ coord.Reverse(); } - -inline gp_Vec2d gp_Vec2d::Reversed() const -{ - gp_Vec2d V = *this; - V.coord.Reverse(); - return V; -} - -inline void gp_Vec2d::Subtract (const gp_Vec2d& Right) -{ coord.Subtract (Right.coord); } - -inline gp_Vec2d gp_Vec2d::Subtracted (const gp_Vec2d& Right) const -{ - gp_Vec2d V = *this; - V.coord.Subtract (Right.coord); - return V; -} - -inline void gp_Vec2d::SetLinearForm (const Standard_Real L, - const gp_Vec2d& Left, - const Standard_Real R, - const gp_Vec2d& Right) -{ coord.SetLinearForm (L, Left.coord, R, Right.coord); } - -inline void gp_Vec2d::SetLinearForm (const Standard_Real L, - const gp_Vec2d& Left, - const gp_Vec2d& Right) -{ coord.SetLinearForm (L, Left.coord, Right.coord); } - -inline void gp_Vec2d::SetLinearForm (const gp_Vec2d& Left, - const gp_Vec2d& Right) -{ coord.SetLinearForm (Left.coord, Right.coord); } - -inline void gp_Vec2d::SetLinearForm (const Standard_Real A1, - const gp_Vec2d& V1, - const Standard_Real A2, - const gp_Vec2d& V2, - const gp_Vec2d& V3) -{ coord.SetLinearForm (A1, V1.coord, A2, V2.coord, V3.coord); } - -inline void gp_Vec2d::Rotate (const Standard_Real Ang) -{ - gp_Trsf2d T; - T.SetRotation (gp_Pnt2d (0.0, 0.0), Ang); - coord.Multiply (T.VectorialPart ()); -} - -inline gp_Vec2d gp_Vec2d::Rotated (const Standard_Real Ang) const -{ - gp_Vec2d V = *this; - V.Rotate (Ang); - return V; -} - -inline void gp_Vec2d::Scale (const Standard_Real S) -{ coord.Multiply (S); } - -inline gp_Vec2d gp_Vec2d::Scaled (const Standard_Real S) const -{ - gp_Vec2d V = *this; - V.coord.Multiply (S); - return V; -} - -inline gp_Vec2d gp_Vec2d::Transformed (const gp_Trsf2d& T) const -{ - gp_Vec2d V = *this; - V.Transform(T); - return V; -} - -inline gp_Vec2d operator* (const Standard_Real Scalar, - const gp_Vec2d& V) -{ return V.Multiplied(Scalar); } - -inline gp_Vec2d gp_Vec2d::GetNormal() const -{ - return gp_Vec2d(this->Y(), (-1)*this->X()); -} - diff --git a/src/gp/gp_XY.cxx b/src/gp/gp_XY.cxx index 5b93d58053..bbe51b26e2 100644 --- a/src/gp/gp_XY.cxx +++ b/src/gp/gp_XY.cxx @@ -12,9 +12,9 @@ // Alternatively, this file may be used under the terms of Open CASCADE // commercial license or contractual agreement. +#include #include -#include #include #include diff --git a/src/gp/gp_XY.hxx b/src/gp/gp_XY.hxx index ecf51eb607..a046cbf948 100644 --- a/src/gp/gp_XY.hxx +++ b/src/gp/gp_XY.hxx @@ -15,18 +15,10 @@ #ifndef _gp_XY_HeaderFile #define _gp_XY_HeaderFile -#include -#include -#include - -#include -#include -#include -class Standard_ConstructionError; -class Standard_OutOfRange; -class gp_Mat2d; - - +#include +#include +#include +#include //! This class describes a cartesian coordinate entity in 2D //! space {X,Y}. This class is non persistent. This entity used @@ -40,287 +32,359 @@ public: DEFINE_STANDARD_ALLOC - //! Creates XY object with zero coordinates (0,0). - gp_XY(); - + gp_XY() + : x (0.), + y (0.) + {} + //! a number pair defined by the XY coordinates - gp_XY(const Standard_Real X, const Standard_Real Y); - + gp_XY (const Standard_Real theX, const Standard_Real theY) + : x (theX), + y (theY) + {} + + //! modifies the coordinate of range theIndex + //! theIndex = 1 => X is modified + //! theIndex = 2 => Y is modified + //! Raises OutOfRange if theIndex != {1, 2}. + inline void SetCoord (const Standard_Integer theIndex, const Standard_Real theXi) + { + Standard_OutOfRange_Raise_if (theIndex < 1 || theIndex > 2, NULL); + (&x)[theIndex - 1] = theXi; + } - //! modifies the coordinate of range Index - //! Index = 1 => X is modified - //! Index = 2 => Y is modified - //! Raises OutOfRange if Index != {1, 2}. - void SetCoord (const Standard_Integer Index, const Standard_Real Xi); - //! For this number pair, assigns - //! the values X and Y to its coordinates - void SetCoord (const Standard_Real X, const Standard_Real Y); - - //! Assigns the given value to the X coordinate of this number pair. - void SetX (const Standard_Real X); - - //! Assigns the given value to the Y coordinate of this number pair. - void SetY (const Standard_Real Y); - + //! the values theX and theY to its coordinates + inline void SetCoord (const Standard_Real theX, const Standard_Real theY) + { + x = theX; + y = theY; + } + + //! Assigns the given value to the X coordinate of this number pair. + void SetX (const Standard_Real theX) { x = theX; } + + //! Assigns the given value to the Y coordinate of this number pair. + void SetY (const Standard_Real theY) { y = theY; } + + //! returns the coordinate of range theIndex : + //! theIndex = 1 => X is returned + //! theIndex = 2 => Y is returned + //! Raises OutOfRange if theIndex != {1, 2}. + inline Standard_Real Coord (const Standard_Integer theIndex) const + { + Standard_OutOfRange_Raise_if (theIndex < 1 || theIndex > 2, NULL); + return (&x)[theIndex - 1]; + } + + inline Standard_Real& ChangeCoord (const Standard_Integer theIndex) + { + Standard_OutOfRange_Raise_if (theIndex < 1 || theIndex > 2, NULL); + return (&x)[theIndex - 1]; + } - //! returns the coordinate of range Index : - //! Index = 1 => X is returned - //! Index = 2 => Y is returned - //! Raises OutOfRange if Index != {1, 2}. - Standard_Real Coord (const Standard_Integer Index) const; - - Standard_Real& ChangeCoord (const Standard_Integer theIndex); - //! For this number pair, returns its coordinates X and Y. - void Coord (Standard_Real& X, Standard_Real& Y) const; - + inline void Coord (Standard_Real& theX, Standard_Real& theY) const + { + theX = x; + theY = y; + } + //! Returns the X coordinate of this number pair. - Standard_Real X() const; - + Standard_Real X() const { return x; } + //! Returns the Y coordinate of this number pair. - Standard_Real Y() const; - + Standard_Real Y() const { return y; } + //! Computes Sqrt (X*X + Y*Y) where X and Y are the two coordinates of this number pair. - Standard_Real Modulus() const; - + Standard_Real Modulus() const { return sqrt (x * x + y * y); } + //! Computes X*X + Y*Y where X and Y are the two coordinates of this number pair. - Standard_Real SquareModulus() const; - + Standard_Real SquareModulus() const { return x * x + y * y; } //! Returns true if the coordinates of this number pair are //! equal to the respective coordinates of the number pair - //! Other, within the specified tolerance Tolerance. I.e.: - //! abs(.X() - Other.X()) <= Tolerance and - //! abs(.Y() - Other.Y()) <= Tolerance and + //! theOther, within the specified tolerance theTolerance. I.e.: + //! abs(.X() - theOther.X()) <= theTolerance and + //! abs(.Y() - theOther.Y()) <= theTolerance and //! computations - Standard_EXPORT Standard_Boolean IsEqual (const gp_XY& Other, const Standard_Real Tolerance) const; - - //! Computes the sum of this number pair and number pair Other + Standard_EXPORT Standard_Boolean IsEqual (const gp_XY& theOther, const Standard_Real theTolerance) const; + + //! Computes the sum of this number pair and number pair theOther //! @code - //! .X() = .X() + Other.X() - //! .Y() = .Y() + Other.Y() - //! @endcode - void Add (const gp_XY& Other); - void operator += (const gp_XY& Other) -{ - Add(Other); -} - - //! Computes the sum of this number pair and number pair Other + //! .X() = .X() + theOther.X() + //! .Y() = .Y() + theOther.Y() + inline void Add (const gp_XY& theOther) + { + x += theOther.x; + y += theOther.y; + } + + void operator+= (const gp_XY& theOther) { Add (theOther); } + + //! Computes the sum of this number pair and number pair theOther //! @code - //! new.X() = .X() + Other.X() - //! new.Y() = .Y() + Other.Y() + //! new.X() = .X() + theOther.X() + //! new.Y() = .Y() + theOther.Y() //! @endcode - Standard_NODISCARD gp_XY Added (const gp_XY& Other) const; - Standard_NODISCARD gp_XY operator + (const gp_XY& Other) const -{ - return Added(Other); -} - + Standard_NODISCARD gp_XY Added (const gp_XY& theOther) const + { + return gp_XY (x + theOther.X(), y + theOther.Y()); + } + + Standard_NODISCARD gp_XY operator+ (const gp_XY& theOther) const { return Added (theOther); } //! @code - //! double D = .X() * Other.Y() - .Y() * Other.X() + //! double D = .X() * theOther.Y() - .Y() * theOther.X() //! @endcode - Standard_NODISCARD Standard_Real Crossed (const gp_XY& Right) const; - Standard_NODISCARD Standard_Real operator ^ (const gp_XY& Right) const -{ - return Crossed(Right); -} - + Standard_NODISCARD Standard_Real Crossed (const gp_XY& theOther) const { return x * theOther.y - y * theOther.x; } + + Standard_NODISCARD Standard_Real operator^ (const gp_XY& theOther) const { return Crossed (theOther); } //! computes the magnitude of the cross product between and - //! Right. Returns || ^ Right || - Standard_Real CrossMagnitude (const gp_XY& Right) const; - + //! theRight. Returns || ^ theRight || + inline Standard_Real CrossMagnitude (const gp_XY& theRight) const + { + Standard_Real aVal = x * theRight.y - y * theRight.x; + return aVal < 0 ? -aVal : aVal; + } //! computes the square magnitude of the cross product between and - //! Right. Returns || ^ Right ||**2 - Standard_Real CrossSquareMagnitude (const gp_XY& Right) const; - + //! theRight. Returns || ^ theRight ||**2 + inline Standard_Real CrossSquareMagnitude (const gp_XY& theRight) const + { + Standard_Real aZresult = x * theRight.y - y * theRight.x; + return aZresult * aZresult; + } + //! divides by a real. - void Divide (const Standard_Real Scalar); - void operator /= (const Standard_Real Scalar) -{ - Divide(Scalar); -} - + void Divide (const Standard_Real theScalar) + { + x /= theScalar; + y /= theScalar; + } + + void operator /= (const Standard_Real theScalar) { Divide (theScalar); } + //! Divides by a real. - Standard_NODISCARD gp_XY Divided (const Standard_Real Scalar) const; - Standard_NODISCARD gp_XY operator / (const Standard_Real Scalar) const -{ - return Divided(Scalar); -} - - //! Computes the scalar product between and Other - Standard_Real Dot (const gp_XY& Other) const; - Standard_Real operator * (const gp_XY& Other) const -{ - return Dot(Other); -} - + Standard_NODISCARD gp_XY Divided (const Standard_Real theScalar) const + { + return gp_XY (x / theScalar, y / theScalar); + } + + Standard_NODISCARD gp_XY operator/ (const Standard_Real theScalar) const { return Divided (theScalar); } + + //! Computes the scalar product between and theOther + Standard_Real Dot (const gp_XY& theOther) const { return x * theOther.x + y * theOther.y; } + + Standard_Real operator* (const gp_XY& theOther) const { return Dot (theOther); } //! @code - //! .X() = .X() * Scalar; - //! .Y() = .Y() * Scalar; - //! @endcode - void Multiply (const Standard_Real Scalar); - void operator *= (const Standard_Real Scalar) -{ - Multiply(Scalar); -} - - //! @code - //! .X() = .X() * Other.X(); - //! .Y() = .Y() * Other.Y(); - //! @endcode - void Multiply (const gp_XY& Other); - void operator *= (const gp_XY& Other) -{ - Multiply(Other); -} + //! .X() = .X() * theScalar; + //! .Y() = .Y() * theScalar; + void Multiply (const Standard_Real theScalar) + { + x *= theScalar; + y *= theScalar; + } + + void operator*= (const Standard_Real theScalar) { Multiply (theScalar); } //! @code - //! = Matrix * - //! @endcode - void Multiply (const gp_Mat2d& Matrix); - void operator *= (const gp_Mat2d& Matrix) -{ - Multiply(Matrix); -} - - //! @code - //! New.X() = .X() * Scalar; - //! New.Y() = .Y() * Scalar; - //! @endcode - Standard_NODISCARD gp_XY Multiplied (const Standard_Real Scalar) const; - Standard_NODISCARD gp_XY operator * (const Standard_Real Scalar) const -{ - return Multiplied(Scalar); -} - - //! @code - //! new.X() = .X() * Other.X(); - //! new.Y() = .Y() * Other.Y(); - //! @endcode - Standard_NODISCARD gp_XY Multiplied (const gp_XY& Other) const; + //! .X() = .X() * theOther.X(); + //! .Y() = .Y() * theOther.Y(); + void Multiply (const gp_XY& theOther) + { + x *= theOther.x; + y *= theOther.y; + } + + void operator*= (const gp_XY& theOther) { Multiply (theOther); } + + //! = theMatrix * + void Multiply (const gp_Mat2d& theMatrix); + + void operator*= (const gp_Mat2d& theMatrix) { Multiply (theMatrix); } //! @code - //! New = Matrix * + //! New.X() = .X() * theScalar; + //! New.Y() = .Y() * theScalar; + Standard_NODISCARD gp_XY Multiplied (const Standard_Real theScalar) const { return gp_XY (x * theScalar, y * theScalar); } + + Standard_NODISCARD gp_XY operator* (const Standard_Real theScalar) const { return Multiplied (theScalar); } + //! @code + //! new.X() = .X() * theOther.X(); + //! new.Y() = .Y() * theOther.Y(); + Standard_NODISCARD gp_XY Multiplied (const gp_XY& theOther) const { return gp_XY (x * theOther.X(), y * theOther.Y()); } + + //! New = theMatrix * //! @endcode - Standard_NODISCARD gp_XY Multiplied (const gp_Mat2d& Matrix) const; - Standard_NODISCARD gp_XY operator * (const gp_Mat2d& Matrix) const -{ - return Multiplied(Matrix); -} - + Standard_NODISCARD gp_XY Multiplied (const gp_Mat2d& theMatrix) const + { + const Standard_Address aM = (Standard_Address) &(theMatrix.Value (1, 1)); + return gp_XY (Mat2d00 * x + Mat2d01 * y, Mat2d10 * x + Mat2d11 * y); + } + + Standard_NODISCARD gp_XY operator* (const gp_Mat2d& theMatrix) const { return Multiplied (theMatrix); } //! @code //! .X() = .X()/ .Modulus() //! .Y() = .Y()/ .Modulus() //! @endcode //! Raises ConstructionError if .Modulus() <= Resolution from gp - void Normalize(); - + void Normalize(); + //! @code //! New.X() = .X()/ .Modulus() //! New.Y() = .Y()/ .Modulus() //! @endcode //! Raises ConstructionError if .Modulus() <= Resolution from gp - Standard_NODISCARD gp_XY Normalized() const; - + Standard_NODISCARD gp_XY Normalized() const + { + Standard_Real aD = Modulus(); + Standard_ConstructionError_Raise_if (aD <= gp::Resolution(), "gp_XY::Normalized() - vector has zero norm"); + return gp_XY (x / aD, y / aD); + } + //! @code //! .X() = -.X() //! .Y() = -.Y() - //! @endcode - void Reverse(); - + inline void Reverse() + { + x = -x; + y = -y; + } + //! @code //! New.X() = -.X() //! New.Y() = -.Y() - //! @endcode - Standard_NODISCARD gp_XY Reversed() const; - Standard_NODISCARD gp_XY operator -() const -{ - return Reversed(); -} - + Standard_NODISCARD gp_XY Reversed() const + { + gp_XY aCoord2D = *this; + aCoord2D.Reverse(); + return aCoord2D; + } + + Standard_NODISCARD gp_XY operator-() const { return Reversed(); } //! Computes the following linear combination and //! assigns the result to this number pair: //! @code - //! A1 * XY1 + A2 * XY2 - //! @endcode - void SetLinearForm (const Standard_Real A1, const gp_XY& XY1, const Standard_Real A2, const gp_XY& XY2); - + //! theA1 * theXY1 + theA2 * theXY2 + inline void SetLinearForm (const Standard_Real theA1, const gp_XY& theXY1, + const Standard_Real theA2, const gp_XY& theXY2) + { + x = theA1 * theXY1.x + theA2 * theXY2.x; + y = theA1 * theXY1.y + theA2 * theXY2.y; + } //! -- Computes the following linear combination and //! assigns the result to this number pair: //! @code - //! A1 * XY1 + A2 * XY2 + XY3 - //! @endcode - void SetLinearForm (const Standard_Real A1, const gp_XY& XY1, const Standard_Real A2, const gp_XY& XY2, const gp_XY& XY3); - + //! theA1 * theXY1 + theA2 * theXY2 + theXY3 + inline void SetLinearForm (const Standard_Real theA1, const gp_XY& theXY1, + const Standard_Real theA2, const gp_XY& theXY2, + const gp_XY& theXY3) + { + x = theA1 * theXY1.x + theA2 * theXY2.x + theXY3.x; + y = theA1 * theXY1.y + theA2 * theXY2.y + theXY3.y; + } //! Computes the following linear combination and //! assigns the result to this number pair: //! @code - //! A1 * XY1 + XY2 - //! @endcode - void SetLinearForm (const Standard_Real A1, const gp_XY& XY1, const gp_XY& XY2); - + //! theA1 * theXY1 + theXY2 + inline void SetLinearForm (const Standard_Real theA1, const gp_XY& theXY1, + const gp_XY& theXY2) + { + x = theA1 * theXY1.x + theXY2.x; + y = theA1 * theXY1.y + theXY2.y; + } //! Computes the following linear combination and //! assigns the result to this number pair: //! @code - //! XY1 + XY2 - //! @endcode - void SetLinearForm (const gp_XY& XY1, const gp_XY& XY2); - - //! @code - //! .X() = .X() - Other.X() - //! .Y() = .Y() - Other.Y() - //! @endcode - void Subtract (const gp_XY& Right); - void operator -= (const gp_XY& Right) -{ - Subtract(Right); -} + //! theXY1 + theXY2 + inline void SetLinearForm (const gp_XY& theXY1, + const gp_XY& theXY2) + { + x = theXY1.x + theXY2.x; + y = theXY1.y + theXY2.y; + } //! @code - //! new.X() = .X() - Other.X() - //! new.Y() = .Y() - Other.Y() + //! .X() = .X() - theOther.X() + //! .Y() = .Y() - theOther.Y() + inline void Subtract (const gp_XY& theOther) + { + x -= theOther.x; + y -= theOther.y; + } + + void operator-= (const gp_XY& theOther) { Subtract (theOther); } + + //! @code + //! new.X() = .X() - theOther.X() + //! new.Y() = .Y() - theOther.Y() //! @endcode - Standard_NODISCARD gp_XY Subtracted (const gp_XY& Right) const; - Standard_NODISCARD gp_XY operator - (const gp_XY& Right) const -{ - return Subtracted(Right); -} - - - - -protected: - - - + Standard_NODISCARD gp_XY Subtracted (const gp_XY& theOther) const + { + gp_XY aCoord2D = *this; + aCoord2D.Subtract (theOther); + return aCoord2D; + } + Standard_NODISCARD gp_XY operator- (const gp_XY& theOther) const { return Subtracted (theOther); } private: - - Standard_Real x; Standard_Real y; - }; +//======================================================================= +//function : Multiply +// purpose : +//======================================================================= +inline void gp_XY::Multiply (const gp_Mat2d& theMatrix) +{ + const Standard_Address aM = (Standard_Address) &(theMatrix.Value (1, 1)); + Standard_Real aXresult = Mat2d00 * x + Mat2d01 * y; + y = Mat2d10 * x + Mat2d11 * y; + x = aXresult; +} -#include - - +//======================================================================= +//function : Normalize +// purpose : +//======================================================================= +inline void gp_XY::Normalize() +{ + Standard_Real aD = Modulus(); + Standard_ConstructionError_Raise_if (aD <= gp::Resolution(), "gp_XY::Normalize() - vector has zero norm"); + x = x / aD; + y = y / aD; +} +//======================================================================= +//function : operator* +// purpose : +//======================================================================= +inline gp_XY operator* (const gp_Mat2d& theMatrix, + const gp_XY& theCoord1) +{ + return theCoord1.Multiplied (theMatrix); +} +//======================================================================= +//function : operator* +// purpose : +//======================================================================= +inline gp_XY operator* (const Standard_Real theScalar, + const gp_XY& theCoord1) +{ + return theCoord1.Multiplied (theScalar); +} #endif // _gp_XY_HeaderFile diff --git a/src/gp/gp_XY.lxx b/src/gp/gp_XY.lxx deleted file mode 100644 index ecd0605719..0000000000 --- a/src/gp/gp_XY.lxx +++ /dev/null @@ -1,229 +0,0 @@ -// Copyright (c) 1995-1999 Matra Datavision -// Copyright (c) 1999-2014 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -// LPA et JCV 07/92 - -#include -#include -#include -#include - -inline gp_XY::gp_XY () : x(0.), y(0.) { } - -inline gp_XY::gp_XY (const Standard_Real X, - const Standard_Real Y) : x (X), y (Y) { } - -inline void gp_XY::SetCoord (const Standard_Integer i, - const Standard_Real X) -{ - Standard_OutOfRange_Raise_if( i < 1 || i > 2,NULL); - (&x)[i-1] = X; -} - -inline void gp_XY::SetCoord (const Standard_Real X, - const Standard_Real Y) -{ x = X; y = Y; } - -inline void gp_XY::SetX (const Standard_Real X) -{ x = X; } - -inline void gp_XY::SetY (const Standard_Real Y) -{ y = Y; } - -inline Standard_Real gp_XY::Coord (const Standard_Integer i) const -{ - Standard_OutOfRange_Raise_if( i < 1 || i > 2,NULL); - return (&x)[i-1]; -} - -inline Standard_Real& gp_XY::ChangeCoord (const Standard_Integer theIndex) -{ - Standard_OutOfRange_Raise_if(theIndex < 1 || theIndex > 2,NULL); - return (&x)[theIndex - 1]; -} - -inline void gp_XY::Coord (Standard_Real& X, - Standard_Real& Y) const -{ X = x; Y = y; } - -inline Standard_Real gp_XY::X () const -{ return x; } - -inline Standard_Real gp_XY::Y () const -{ return y; } - -inline Standard_Real gp_XY::Modulus () const -{ - return sqrt (x * x + y * y); -} - -inline Standard_Real gp_XY::SquareModulus () const -{ - return x * x + y * y; -} - -inline void gp_XY::Add (const gp_XY& Other) { - x += Other.x; - y += Other.y; -} - -inline gp_XY gp_XY::Added (const gp_XY& Other) const { - return gp_XY(x + Other.X(),y + Other.Y()); -} - -inline Standard_Real gp_XY::Crossed (const gp_XY& Right) const { - return x * Right.y - y * Right.x; -} - -inline Standard_Real gp_XY::CrossMagnitude (const gp_XY& Right) const -{ - Standard_Real val = x * Right.y - y * Right.x; - if (val < 0) val = - val; - return val; -} - -inline Standard_Real gp_XY::CrossSquareMagnitude (const gp_XY& Right) const { - Standard_Real Zresult = x * Right.y - y * Right.x; - return Zresult * Zresult; -} - -inline void gp_XY::Divide (const Standard_Real Scalar) -{ - x /= Scalar; - y /= Scalar; -} - -inline gp_XY gp_XY::Divided (const Standard_Real Scalar) const { - return gp_XY(x / Scalar,y / Scalar); -} - -inline Standard_Real gp_XY::Dot (const gp_XY& Other) const -{ - return x * Other.x + y * Other.y; -} - -inline void gp_XY::Multiply (const Standard_Real Scalar) -{ - x *= Scalar; - y *= Scalar; -} - -inline void gp_XY::Multiply (const gp_XY& Other) -{ - x *= Other.x; - y *= Other.y; -} - -inline void gp_XY::Multiply (const gp_Mat2d& Matrix) -{ - const Standard_Address M = (Standard_Address)&(Matrix.matrix[0][0]); - Standard_Real Xresult = Mat2d00 * x + Mat2d01 * y; - y = Mat2d10 * x + Mat2d11 * y; - x = Xresult; -} - -inline gp_XY gp_XY::Multiplied (const Standard_Real Scalar) const { - return gp_XY(x * Scalar,y * Scalar); -} - -inline gp_XY gp_XY::Multiplied (const gp_XY& Other) const { - return(gp_XY(x * Other.X(),y * Other.Y())); -} - -inline gp_XY gp_XY::Multiplied (const gp_Mat2d& Matrix) const -{ - const Standard_Address M = (Standard_Address)&(Matrix.matrix[0][0]); - return gp_XY (Mat2d00 * x + Mat2d01 * y, - Mat2d10 * x + Mat2d11 * y); -} - -inline void gp_XY::Normalize () -{ - Standard_Real D = Modulus(); - Standard_ConstructionError_Raise_if (D <= gp::Resolution(), - "gp_XY::Normalize() - vector has zero norm"); - x = x / D; y = y / D; -} - -inline gp_XY gp_XY::Normalized () const -{ - Standard_Real D = Modulus(); - Standard_ConstructionError_Raise_if (D <= gp::Resolution(), - "gp_XY::Normalized() - vector has zero norm"); - return gp_XY (x / D, y / D); -} - -inline void gp_XY::Reverse () -{ x = - x; y = - y; } - -inline gp_XY gp_XY::Reversed () const -{ - gp_XY Coord2D = *this; - Coord2D.Reverse(); - return Coord2D; -} - -inline void gp_XY::SetLinearForm (const Standard_Real L, - const gp_XY& Left, - const Standard_Real R, - const gp_XY& Right) { - x = L * Left.x + R * Right.x; - y = L * Left.y + R * Right.y; -} - -inline void gp_XY::SetLinearForm (const Standard_Real L, - const gp_XY& Left, - const gp_XY& Right) { - x = L * Left.x + Right.x; - y = L * Left.y + Right.y; -} - -inline void gp_XY::SetLinearForm (const gp_XY& Left, - const gp_XY& Right) { - x = Left.x + Right.x; - y = Left.y + Right.y; -} - -inline void gp_XY::SetLinearForm (const Standard_Real A1, - const gp_XY& XY1, - const Standard_Real A2, - const gp_XY& XY2, - const gp_XY& XY3) { - x = A1 * XY1.x + A2 * XY2.x + XY3.x; - y = A1 * XY1.y + A2 * XY2.y + XY3.y; -} - -inline void gp_XY::Subtract (const gp_XY& Right) -{ - x -= Right.x; - y -= Right.y; -} - -inline gp_XY gp_XY::Subtracted (const gp_XY& Right) const -{ - gp_XY Coord2D = *this; - Coord2D.Subtract(Right); - return Coord2D; -} - -inline gp_XY operator* (const gp_Mat2d& Matrix, - const gp_XY& Coord1) { - return Coord1.Multiplied(Matrix); -} - -inline gp_XY operator* (const Standard_Real Scalar, - const gp_XY& Coord1) { - return Coord1.Multiplied(Scalar); -} - diff --git a/src/gp/gp_XYZ.cxx b/src/gp/gp_XYZ.cxx index 1c85ef60b7..bd0a6a196e 100644 --- a/src/gp/gp_XYZ.cxx +++ b/src/gp/gp_XYZ.cxx @@ -12,9 +12,9 @@ // Alternatively, this file may be used under the terms of Open CASCADE // commercial license or contractual agreement. +#include #include -#include #include #include #include diff --git a/src/gp/gp_XYZ.hxx b/src/gp/gp_XYZ.hxx index ecd05845bb..fa944ab788 100644 --- a/src/gp/gp_XYZ.hxx +++ b/src/gp/gp_XYZ.hxx @@ -15,23 +15,13 @@ #ifndef _gp_XYZ_HeaderFile #define _gp_XYZ_HeaderFile -#include -#include -#include - -#include -#include -#include - +#include +#include +#include +#include #include #include -class Standard_ConstructionError; -class Standard_OutOfRange; -class gp_Mat; - - - //! This class describes a cartesian coordinate entity in //! 3D space {X,Y,Z}. This entity is used for algebraic //! calculation. This entity can be transformed @@ -44,224 +34,253 @@ public: DEFINE_STANDARD_ALLOC - //! Creates an XYZ object with zero coordinates (0,0,0) - gp_XYZ(); - + gp_XYZ() + : x (0.), + y (0.), + z (0.) + {} + //! creates an XYZ with given coordinates - gp_XYZ(const Standard_Real X, const Standard_Real Y, const Standard_Real Z); - + gp_XYZ (const Standard_Real theX, const Standard_Real theY, const Standard_Real theZ) + : x (theX), + y (theY), + z (theZ) + {} + //! For this XYZ object, assigns - //! the values X, Y and Z to its three coordinates - void SetCoord (const Standard_Real X, const Standard_Real Y, const Standard_Real Z); - + //! the values theX, theY and theZ to its three coordinates + void SetCoord (const Standard_Real theX, const Standard_Real theY, const Standard_Real theZ) + { + x = theX; + y = theY; + z = theZ; + } + + //! modifies the coordinate of range theIndex + //! theIndex = 1 => X is modified + //! theIndex = 2 => Y is modified + //! theIndex = 3 => Z is modified + //! Raises OutOfRange if theIndex != {1, 2, 3}. + void SetCoord (const Standard_Integer theIndex, const Standard_Real theXi) + { + Standard_OutOfRange_Raise_if (theIndex < 1 || theIndex > 3, NULL); + (&x)[theIndex - 1] = theXi; + } - //! modifies the coordinate of range Index - //! Index = 1 => X is modified - //! Index = 2 => Y is modified - //! Index = 3 => Z is modified - //! Raises OutOfRange if Index != {1, 2, 3}. - void SetCoord (const Standard_Integer Index, const Standard_Real Xi); - //! Assigns the given value to the X coordinate - void SetX (const Standard_Real X); - + void SetX (const Standard_Real theX) { x = theX; } + //! Assigns the given value to the Y coordinate - void SetY (const Standard_Real Y); - + void SetY (const Standard_Real theY) { y = theY; } + //! Assigns the given value to the Z coordinate - void SetZ (const Standard_Real Z); - + void SetZ (const Standard_Real theZ) { z = theZ; } - //! returns the coordinate of range Index : - //! Index = 1 => X is returned - //! Index = 2 => Y is returned - //! Index = 3 => Z is returned + //! returns the coordinate of range theIndex : + //! theIndex = 1 => X is returned + //! theIndex = 2 => Y is returned + //! theIndex = 3 => Z is returned //! - //! Raises OutOfRange if Index != {1, 2, 3}. - Standard_Real Coord (const Standard_Integer Index) const; - - Standard_Real& ChangeCoord (const Standard_Integer theIndex); - - void Coord (Standard_Real& X, Standard_Real& Y, Standard_Real& Z) const; + //! Raises OutOfRange if theIndex != {1, 2, 3}. + Standard_Real Coord (const Standard_Integer theIndex) const + { + Standard_OutOfRange_Raise_if (theIndex < 1 || theIndex > 3, NULL); + return (&x)[theIndex - 1]; + } - //! Returns a const ptr to coordinates location. - //! Is useful for algorithms, but DOES NOT PERFORM - //! ANY CHECKS! - inline const Standard_Real* GetData() const { return (&x); } + Standard_Real& ChangeCoord (const Standard_Integer theIndex) + { + Standard_OutOfRange_Raise_if (theIndex < 1 || theIndex > 3, NULL); + return (&x)[theIndex - 1]; + } + + void Coord (Standard_Real& theX, Standard_Real& theY, Standard_Real& theZ) const + { + theX = x; + theY = y; + theZ = z; + } + + //! Returns a const ptr to coordinates location. + //! Is useful for algorithms, but DOES NOT PERFORM + //! ANY CHECKS! + const Standard_Real* GetData() const { return (&x); } + + //! Returns a ptr to coordinates location. + //! Is useful for algorithms, but DOES NOT PERFORM + //! ANY CHECKS! + Standard_Real* ChangeData() { return (&x); } - //! Returns a ptr to coordinates location. - //! Is useful for algorithms, but DOES NOT PERFORM - //! ANY CHECKS! - inline Standard_Real* ChangeData() { return (&x); } - //! Returns the X coordinate - Standard_Real X() const; - + Standard_Real X() const { return x; } + //! Returns the Y coordinate - Standard_Real Y() const; - + Standard_Real Y() const { return y; } + //! Returns the Z coordinate - Standard_Real Z() const; - + Standard_Real Z() const { return z; } + //! computes Sqrt (X*X + Y*Y + Z*Z) where X, Y and Z are the three coordinates of this XYZ object. - Standard_Real Modulus() const; - + Standard_Real Modulus() const { return sqrt (x * x + y * y + z * z); } + //! Computes X*X + Y*Y + Z*Z where X, Y and Z are the three coordinates of this XYZ object. - Standard_Real SquareModulus() const; - + Standard_Real SquareModulus() const { return (x * x + y * y + z * z); } //! Returns True if he coordinates of this XYZ object are //! equal to the respective coordinates Other, - //! within the specified tolerance Tolerance. I.e.: - //! abs(.X() - Other.X()) <= Tolerance and - //! abs(.Y() - Other.Y()) <= Tolerance and - //! abs(.Z() - Other.Z()) <= Tolerance. - Standard_EXPORT Standard_Boolean IsEqual (const gp_XYZ& Other, const Standard_Real Tolerance) const; - - //! @code - //! .X() = .X() + Other.X() - //! .Y() = .Y() + Other.Y() - //! .Z() = .Z() + Other.Z() - //! @endcode - void Add (const gp_XYZ& Other); - void operator += (const gp_XYZ& Other) -{ - Add(Other); -} + //! within the specified tolerance theTolerance. I.e.: + //! abs(.X() - theOther.X()) <= theTolerance and + //! abs(.Y() - theOther.Y()) <= theTolerance and + //! abs(.Z() - theOther.Z()) <= theTolerance. + Standard_EXPORT Standard_Boolean IsEqual (const gp_XYZ& theOther, const Standard_Real theTolerance) const; //! @code - //! new.X() = .X() + Other.X() - //! new.Y() = .Y() + Other.Y() - //! new.Z() = .Z() + Other.Z() - //! @endcode - Standard_NODISCARD gp_XYZ Added (const gp_XYZ& Other) const; - Standard_NODISCARD gp_XYZ operator + (const gp_XYZ& Other) const -{ - return Added(Other); -} + //! .X() = .X() + theOther.X() + //! .Y() = .Y() + theOther.Y() + //! .Z() = .Z() + theOther.Z() + void Add (const gp_XYZ& theOther) + { + x += theOther.x; + y += theOther.y; + z += theOther.z; + } + + void operator+= (const gp_XYZ& theOther) { Add (theOther); } //! @code - //! .X() = .Y() * Other.Z() - .Z() * Other.Y() - //! .Y() = .Z() * Other.X() - .X() * Other.Z() - //! .Z() = .X() * Other.Y() - .Y() * Other.X() + //! new.X() = .X() + theOther.X() + //! new.Y() = .Y() + theOther.Y() + //! new.Z() = .Z() + theOther.Z() //! @endcode - void Cross (const gp_XYZ& Right); - void operator ^= (const gp_XYZ& Right) -{ - Cross(Right); -} + Standard_NODISCARD gp_XYZ Added (const gp_XYZ& theOther) const + { + return gp_XYZ (x + theOther.x, y + theOther.y, z + theOther.z); + } + + Standard_NODISCARD gp_XYZ operator + (const gp_XYZ& theOther) const { return Added (theOther); } //! @code - //! new.X() = .Y() * Other.Z() - .Z() * Other.Y() - //! new.Y() = .Z() * Other.X() - .X() * Other.Z() - //! new.Z() = .X() * Other.Y() - .Y() * Other.X() + //! .X() = .Y() * theOther.Z() - .Z() * theOther.Y() + //! .Y() = .Z() * theOther.X() - .X() * theOther.Z() + //! .Z() = .X() * theOther.Y() - .Y() * theOther.X() + void Cross (const gp_XYZ& theOther); + + void operator^= (const gp_XYZ& theOther) { Cross (theOther); } + + //! @code + //! new.X() = .Y() * theOther.Z() - .Z() * theOther.Y() + //! new.Y() = .Z() * theOther.X() - .X() * theOther.Z() + //! new.Z() = .X() * theOther.Y() - .Y() * theOther.X() //! @endcode - Standard_NODISCARD gp_XYZ Crossed (const gp_XYZ& Right) const; - Standard_NODISCARD gp_XYZ operator ^ (const gp_XYZ& Right) const -{ - return Crossed(Right); -} - + Standard_NODISCARD gp_XYZ Crossed (const gp_XYZ& theOther) const + { + return gp_XYZ (y * theOther.z - z * theOther.y, + z * theOther.x - x * theOther.z, + x * theOther.y - y * theOther.x); + } + + Standard_NODISCARD gp_XYZ operator ^ (const gp_XYZ& theOther) const { return Crossed (theOther); } //! Computes the magnitude of the cross product between and - //! Right. Returns || ^ Right || - Standard_Real CrossMagnitude (const gp_XYZ& Right) const; - + //! theRight. Returns || ^ theRight || + Standard_Real CrossMagnitude (const gp_XYZ& theRight) const; //! Computes the square magnitude of the cross product between and - //! Right. Returns || ^ Right ||**2 - Standard_Real CrossSquareMagnitude (const gp_XYZ& Right) const; - + //! theRight. Returns || ^ theRight ||**2 + Standard_Real CrossSquareMagnitude (const gp_XYZ& theRight) const; + //! Triple vector product - //! Computes = .Cross(Coord1.Cross(Coord2)) - void CrossCross (const gp_XYZ& Coord1, const gp_XYZ& Coord2); - + //! Computes = .Cross(theCoord1.Cross(theCoord2)) + void CrossCross (const gp_XYZ& theCoord1, const gp_XYZ& theCoord2); + //! Triple vector product - //! computes New = .Cross(Coord1.Cross(Coord2)) - Standard_NODISCARD gp_XYZ CrossCrossed (const gp_XYZ& Coord1, const gp_XYZ& Coord2) const; - + //! computes New = .Cross(theCoord1.Cross(theCoord2)) + Standard_NODISCARD gp_XYZ CrossCrossed (const gp_XYZ& theCoord1, const gp_XYZ& theCoord2) const + { + gp_XYZ aCoord0 = *this; + aCoord0.CrossCross (theCoord1, theCoord2); + return aCoord0; + } + //! divides by a real. - void Divide (const Standard_Real Scalar); - void operator /= (const Standard_Real Scalar) -{ - Divide(Scalar); -} - + void Divide (const Standard_Real theScalar) + { + x /= theScalar; + y /= theScalar; + z /= theScalar; + } + + void operator/= (const Standard_Real theScalar) { Divide (theScalar); } + //! divides by a real. - Standard_NODISCARD gp_XYZ Divided (const Standard_Real Scalar) const; - Standard_NODISCARD gp_XYZ operator / (const Standard_Real Scalar) const -{ - return Divided(Scalar); -} - - //! computes the scalar product between and Other - Standard_Real Dot (const gp_XYZ& Other) const; - Standard_Real operator * (const gp_XYZ& Other) const -{ - return Dot(Other); -} - + Standard_NODISCARD gp_XYZ Divided (const Standard_Real theScalar) const { return gp_XYZ (x / theScalar, y / theScalar, z / theScalar); } + + Standard_NODISCARD gp_XYZ operator/ (const Standard_Real theScalar) const { return Divided (theScalar); } + + //! computes the scalar product between and theOther + Standard_Real Dot (const gp_XYZ& theOther) const { return(x * theOther.x + y * theOther.y + z * theOther.z); } + + Standard_Real operator* (const gp_XYZ& theOther) const { return Dot (theOther); } + //! computes the triple scalar product - Standard_Real DotCross (const gp_XYZ& Coord1, const gp_XYZ& Coord2) const; + Standard_Real DotCross (const gp_XYZ& theCoord1, const gp_XYZ& theCoord2) const; //! @code - //! .X() = .X() * Scalar; - //! .Y() = .Y() * Scalar; - //! .Z() = .Z() * Scalar; - //! @endcode - void Multiply (const Standard_Real Scalar); - void operator *= (const Standard_Real Scalar) -{ - Multiply(Scalar); -} + //! .X() = .X() * theScalar; + //! .Y() = .Y() * theScalar; + //! .Z() = .Z() * theScalar; + void Multiply (const Standard_Real theScalar) + { + x *= theScalar; + y *= theScalar; + z *= theScalar; + } + + void operator*= (const Standard_Real theScalar) { Multiply (theScalar); } //! @code - //! .X() = .X() * Other.X(); - //! .Y() = .Y() * Other.Y(); - //! .Z() = .Z() * Other.Z(); - //! @endcode - void Multiply (const gp_XYZ& Other); - void operator *= (const gp_XYZ& Other) -{ - Multiply(Other); -} + //! .X() = .X() * theOther.X(); + //! .Y() = .Y() * theOther.Y(); + //! .Z() = .Z() * theOther.Z(); + void Multiply (const gp_XYZ& theOther) + { + x *= theOther.x; + y *= theOther.y; + z *= theOther.z; + } + + void operator*= (const gp_XYZ& theOther) { Multiply (theOther); } + + //! = theMatrix * + void Multiply (const gp_Mat& theMatrix); + + void operator*= (const gp_Mat& theMatrix) { Multiply (theMatrix); } //! @code - //! = Matrix * - //! @endcode - void Multiply (const gp_Mat& Matrix); - void operator *= (const gp_Mat& Matrix) -{ - Multiply(Matrix); -} + //! New.X() = .X() * theScalar; + //! New.Y() = .Y() * theScalar; + //! New.Z() = .Z() * theScalar; + Standard_NODISCARD gp_XYZ Multiplied (const Standard_Real theScalar) const { return gp_XYZ (x * theScalar, y * theScalar, z * theScalar); } + + Standard_NODISCARD gp_XYZ operator* (const Standard_Real theScalar) const { return Multiplied (theScalar); } //! @code - //! New.X() = .X() * Scalar; - //! New.Y() = .Y() * Scalar; - //! New.Z() = .Z() * Scalar; - //! @endcode - Standard_NODISCARD gp_XYZ Multiplied (const Standard_Real Scalar) const; - Standard_NODISCARD gp_XYZ operator * (const Standard_Real Scalar) const -{ - return Multiplied(Scalar); -} + //! new.X() = .X() * theOther.X(); + //! new.Y() = .Y() * theOther.Y(); + //! new.Z() = .Z() * theOther.Z(); + Standard_NODISCARD gp_XYZ Multiplied (const gp_XYZ& theOther) const { return gp_XYZ (x * theOther.x, y * theOther.y, z * theOther.z); } - //! @code - //! new.X() = .X() * Other.X(); - //! new.Y() = .Y() * Other.Y(); - //! new.Z() = .Z() * Other.Z(); + //! New = theMatrix * //! @endcode - Standard_NODISCARD gp_XYZ Multiplied (const gp_XYZ& Other) const; + Standard_NODISCARD gp_XYZ Multiplied (const gp_Mat& theMatrix) const + { + return gp_XYZ (theMatrix.Value (1, 1) * x + theMatrix.Value (1, 2) * y + theMatrix.Value (1, 3) * z, + theMatrix.Value (2, 1) * x + theMatrix.Value (2, 2) * y + theMatrix.Value (2, 3) * z, + theMatrix.Value (3, 1) * x + theMatrix.Value (3, 2) * y + theMatrix.Value (3, 3) * z); + } - //! @code - //! New = Matrix * - //! @endcode - Standard_NODISCARD gp_XYZ Multiplied (const gp_Mat& Matrix) const; - Standard_NODISCARD gp_XYZ operator * (const gp_Mat& Matrix) const -{ - return Multiplied(Matrix); -} + Standard_NODISCARD gp_XYZ operator* (const gp_Mat& theMatrix) const { return Multiplied (theMatrix); } //! @code //! .X() = .X()/ .Modulus() @@ -269,7 +288,7 @@ public: //! .Z() = .Z()/ .Modulus() //! @endcode //! Raised if .Modulus() <= Resolution from gp - void Normalize(); + void Normalize(); //! @code //! New.X() = .X()/ .Modulus() @@ -277,86 +296,119 @@ public: //! New.Z() = .Z()/ .Modulus() //! @endcode //! Raised if .Modulus() <= Resolution from gp - Standard_NODISCARD gp_XYZ Normalized() const; + Standard_NODISCARD gp_XYZ Normalized() const + { + Standard_Real aD = Modulus(); + Standard_ConstructionError_Raise_if (aD <= gp::Resolution(), "gp_XYZ::Normalized() - vector has zero norm"); + return gp_XYZ(x / aD, y / aD, z / aD); + } //! @code //! .X() = -.X() //! .Y() = -.Y() //! .Z() = -.Z() - //! @endcode - void Reverse(); + void Reverse() + { + x = -x; + y = -y; + z = -z; + } //! @code //! New.X() = -.X() //! New.Y() = -.Y() //! New.Z() = -.Z() - //! @endcode - Standard_NODISCARD gp_XYZ Reversed() const; + Standard_NODISCARD gp_XYZ Reversed() const { return gp_XYZ (-x, -y, -z); } //! @code - //! .X() = .X() - Other.X() - //! .Y() = .Y() - Other.Y() - //! .Z() = .Z() - Other.Z() - //! @endcode - void Subtract (const gp_XYZ& Right); - void operator -= (const gp_XYZ& Right) -{ - Subtract(Right); -} + //! .X() = .X() - theOther.X() + //! .Y() = .Y() - theOther.Y() + //! .Z() = .Z() - theOther.Z() + void Subtract (const gp_XYZ& theOther) + { + x -= theOther.x; + y -= theOther.y; + z -= theOther.z; + } + + void operator-= (const gp_XYZ& theOther) { Subtract (theOther); } //! @code - //! new.X() = .X() - Other.X() - //! new.Y() = .Y() - Other.Y() - //! new.Z() = .Z() - Other.Z() - //! @endcode - Standard_NODISCARD gp_XYZ Subtracted (const gp_XYZ& Right) const; - Standard_NODISCARD gp_XYZ operator - (const gp_XYZ& Right) const -{ - return Subtracted(Right); -} - + //! new.X() = .X() - theOther.X() + //! new.Y() = .Y() - theOther.Y() + //! new.Z() = .Z() - theOther.Z() + Standard_NODISCARD gp_XYZ Subtracted (const gp_XYZ& theOther) const { return gp_XYZ (x - theOther.x, y - theOther.y, z - theOther.z); } + + Standard_NODISCARD gp_XYZ operator- (const gp_XYZ& theOther) const { return Subtracted (theOther); } //! is set to the following linear form : //! @code - //! A1 * XYZ1 + A2 * XYZ2 + A3 * XYZ3 + XYZ4 - //! @endcode - void SetLinearForm (const Standard_Real A1, const gp_XYZ& XYZ1, const Standard_Real A2, const gp_XYZ& XYZ2, const Standard_Real A3, const gp_XYZ& XYZ3, const gp_XYZ& XYZ4); - + //! theA1 * theXYZ1 + theA2 * theXYZ2 + theA3 * theXYZ3 + theXYZ4 + void SetLinearForm (const Standard_Real theA1, const gp_XYZ& theXYZ1, + const Standard_Real theA2, const gp_XYZ& theXYZ2, + const Standard_Real theA3, const gp_XYZ& theXYZ3, + const gp_XYZ& theXYZ4) + { + x = theA1 * theXYZ1.x + theA2 * theXYZ2.x + theA3 * theXYZ3.x + theXYZ4.x; + y = theA1 * theXYZ1.y + theA2 * theXYZ2.y + theA3 * theXYZ3.y + theXYZ4.y; + z = theA1 * theXYZ1.z + theA2 * theXYZ2.z + theA3 * theXYZ3.z + theXYZ4.z; + } //! is set to the following linear form : //! @code - //! A1 * XYZ1 + A2 * XYZ2 + A3 * XYZ3 - //! @endcode - void SetLinearForm (const Standard_Real A1, const gp_XYZ& XYZ1, const Standard_Real A2, const gp_XYZ& XYZ2, const Standard_Real A3, const gp_XYZ& XYZ3); - + //! theA1 * theXYZ1 + theA2 * theXYZ2 + theA3 * theXYZ3 + void SetLinearForm (const Standard_Real theA1, const gp_XYZ& theXYZ1, + const Standard_Real theA2, const gp_XYZ& theXYZ2, + const Standard_Real theA3, const gp_XYZ& theXYZ3) + { + x = theA1 * theXYZ1.x + theA2 * theXYZ2.x + theA3 * theXYZ3.x; + y = theA1 * theXYZ1.y + theA2 * theXYZ2.y + theA3 * theXYZ3.y; + z = theA1 * theXYZ1.z + theA2 * theXYZ2.z + theA3 * theXYZ3.z; + } //! is set to the following linear form : //! @code - //! A1 * XYZ1 + A2 * XYZ2 + XYZ3 - //! @endcode - void SetLinearForm (const Standard_Real A1, const gp_XYZ& XYZ1, const Standard_Real A2, const gp_XYZ& XYZ2, const gp_XYZ& XYZ3); - + //! theA1 * theXYZ1 + theA2 * theXYZ2 + theXYZ3 + void SetLinearForm (const Standard_Real theA1, const gp_XYZ& theXYZ1, + const Standard_Real theA2, const gp_XYZ& theXYZ2, + const gp_XYZ& theXYZ3) + { + x = theA1 * theXYZ1.x + theA2 * theXYZ2.x + theXYZ3.x; + y = theA1 * theXYZ1.y + theA2 * theXYZ2.y + theXYZ3.y; + z = theA1 * theXYZ1.z + theA2 * theXYZ2.z + theXYZ3.z; + } //! is set to the following linear form : //! @code - //! A1 * XYZ1 + A2 * XYZ2 - //! @endcode - void SetLinearForm (const Standard_Real A1, const gp_XYZ& XYZ1, const Standard_Real A2, const gp_XYZ& XYZ2); - + //! theA1 * theXYZ1 + theA2 * theXYZ2 + void SetLinearForm (const Standard_Real theA1, const gp_XYZ& theXYZ1, + const Standard_Real theA2, const gp_XYZ& theXYZ2) + { + x = theA1 * theXYZ1.x + theA2 * theXYZ2.x; + y = theA1 * theXYZ1.y + theA2 * theXYZ2.y; + z = theA1 * theXYZ1.z + theA2 * theXYZ2.z; + } //! is set to the following linear form : //! @code - //! A1 * XYZ1 + XYZ2 - //! @endcode - void SetLinearForm (const Standard_Real A1, const gp_XYZ& XYZ1, const gp_XYZ& XYZ2); - + //! theA1 * theXYZ1 + theXYZ2 + void SetLinearForm (const Standard_Real theA1, const gp_XYZ& theXYZ1, + const gp_XYZ& theXYZ2) + { + x = theA1 * theXYZ1.x + theXYZ2.x; + y = theA1 * theXYZ1.y + theXYZ2.y; + z = theA1 * theXYZ1.z + theXYZ2.z; + } //! is set to the following linear form : //! @code - //! XYZ1 + XYZ2 - //! @endcode - void SetLinearForm (const gp_XYZ& XYZ1, const gp_XYZ& XYZ2); - + //! theXYZ1 + theXYZ2 + void SetLinearForm (const gp_XYZ& theXYZ1, const gp_XYZ& theXYZ2) + { + x = theXYZ1.x + theXYZ2.x; + y = theXYZ1.y + theXYZ2.y; + z = theXYZ1.z + theXYZ2.z; + } //! Dumps the content of me into the stream Standard_EXPORT void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const; @@ -364,28 +416,121 @@ public: //! Inits the content of me from the stream Standard_EXPORT Standard_Boolean InitFromJson (const Standard_SStream& theSStream, Standard_Integer& theStreamPos); -protected: - - - - - private: - - Standard_Real x; Standard_Real y; Standard_Real z; - }; +//======================================================================= +//function : Cross +// purpose : +//======================================================================= +inline void gp_XYZ::Cross (const gp_XYZ& theRight) +{ + Standard_Real aXresult = y * theRight.z - z * theRight.y; + Standard_Real aYresult = z * theRight.x - x * theRight.z; + z = x * theRight.y - y * theRight.x; + x = aXresult; + y = aYresult; +} -#include +//======================================================================= +//function : CrossMagnitude +// purpose : +//======================================================================= +inline Standard_Real gp_XYZ::CrossMagnitude (const gp_XYZ& theRight) const +{ + Standard_Real aXresult = y * theRight.z - z * theRight.y; + Standard_Real aYresult = z * theRight.x - x * theRight.z; + Standard_Real aZresult = x * theRight.y - y * theRight.x; + return sqrt (aXresult * aXresult + aYresult * aYresult + aZresult * aZresult); +} +//======================================================================= +//function : CrossSquareMagnitude +// purpose : +//======================================================================= +inline Standard_Real gp_XYZ::CrossSquareMagnitude (const gp_XYZ& theRight) const +{ + Standard_Real aXresult = y * theRight.z - z * theRight.y; + Standard_Real aYresult = z * theRight.x - x * theRight.z; + Standard_Real aZresult = x * theRight.y - y * theRight.x; + return aXresult * aXresult + aYresult * aYresult + aZresult * aZresult; +} +//======================================================================= +//function : CrossCross +// purpose : +//======================================================================= +inline void gp_XYZ::CrossCross (const gp_XYZ& theCoord1, const gp_XYZ& theCoord2) +{ + Standard_Real aXresult = y * (theCoord1.x * theCoord2.y - theCoord1.y * theCoord2.x) - + z * (theCoord1.z * theCoord2.x - theCoord1.x * theCoord2.z); + Standard_Real anYresult = z * (theCoord1.y * theCoord2.z - theCoord1.z * theCoord2.y) - + x * (theCoord1.x * theCoord2.y - theCoord1.y * theCoord2.x); + z = x * (theCoord1.z * theCoord2.x - theCoord1.x * theCoord2.z) - + y * (theCoord1.y * theCoord2.z - theCoord1.z * theCoord2.y); + x = aXresult; + y = anYresult; +} +//======================================================================= +//function : DotCross +// purpose : +//======================================================================= +inline Standard_Real gp_XYZ::DotCross (const gp_XYZ& theCoord1, const gp_XYZ& theCoord2) const +{ + Standard_Real aXresult = theCoord1.y * theCoord2.z - theCoord1.z * theCoord2.y; + Standard_Real anYresult = theCoord1.z * theCoord2.x - theCoord1.x * theCoord2.z; + Standard_Real aZresult = theCoord1.x * theCoord2.y - theCoord1.y * theCoord2.x; + return (x * aXresult + y * anYresult + z * aZresult); +} +//======================================================================= +//function : Multiply +// purpose : +//======================================================================= +inline void gp_XYZ::Multiply (const gp_Mat& theMatrix) +{ + Standard_Real aXresult = theMatrix.Value (1, 1) * x + theMatrix.Value (1, 2) * y + theMatrix.Value (1, 3) * z; + Standard_Real anYresult = theMatrix.Value (2, 1) * x + theMatrix.Value (2, 2) * y + theMatrix.Value (2, 3) * z; + z = theMatrix.Value (3, 1) * x + theMatrix.Value (3, 2) * y + theMatrix.Value (3, 3) * z; + x = aXresult; + y = anYresult; +} + +//======================================================================= +//function : Normalize +// purpose : +//======================================================================= +inline void gp_XYZ::Normalize() +{ + Standard_Real aD = Modulus(); + Standard_ConstructionError_Raise_if (aD <= gp::Resolution(), "gp_XYZ::Normalize() - vector has zero norm"); + x = x / aD; + y = y / aD; + z = z / aD; +} + +//======================================================================= +//function : operator* +// purpose : +//======================================================================= +inline gp_XYZ operator* (const gp_Mat& theMatrix, const gp_XYZ& theCoord1) +{ + return theCoord1.Multiplied (theMatrix); +} + +//======================================================================= +//function : operator* +// purpose : +//======================================================================= +inline gp_XYZ operator* (const Standard_Real theScalar, const gp_XYZ& theCoord1) +{ + return theCoord1.Multiplied (theScalar); +} #endif // _gp_XYZ_HeaderFile diff --git a/src/gp/gp_XYZ.lxx b/src/gp/gp_XYZ.lxx deleted file mode 100644 index f97590738c..0000000000 --- a/src/gp/gp_XYZ.lxx +++ /dev/null @@ -1,313 +0,0 @@ -// Copyright (c) 1995-1999 Matra Datavision -// Copyright (c) 1999-2014 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -// LPA et JCV 07/92 - -#include -#include -#include -#include - -inline gp_XYZ::gp_XYZ () : x(0.), y(0.), z(0.) { } - -inline gp_XYZ::gp_XYZ (const Standard_Real X, - const Standard_Real Y, - const Standard_Real Z) : x(X),y(Y),z(Z) { } - -inline void gp_XYZ::SetCoord (const Standard_Real X, - const Standard_Real Y, - const Standard_Real Z) -{ x = X; y = Y; z = Z; } - -inline void gp_XYZ::SetCoord (const Standard_Integer i, - const Standard_Real X) { - Standard_OutOfRange_Raise_if( i < 1 || i > 3,NULL); - (&x)[i-1] = X; -} - -inline void gp_XYZ::SetX (const Standard_Real X) -{ x = X; } - -inline void gp_XYZ::SetY (const Standard_Real Y) -{ y = Y; } - -inline void gp_XYZ::SetZ (const Standard_Real Z) -{ z = Z; } - -inline Standard_Real gp_XYZ::Coord (const Standard_Integer i) const { - Standard_OutOfRange_Raise_if( i < 1 || i > 3,NULL); - return (&x)[i-1]; -} - -inline Standard_Real& gp_XYZ::ChangeCoord(const Standard_Integer theIndex) -{ - Standard_OutOfRange_Raise_if(theIndex < 1 || theIndex > 3,NULL); - return (&x)[theIndex - 1]; -} - -inline void gp_XYZ::Coord (Standard_Real& X, - Standard_Real& Y, - Standard_Real& Z) const -{ X = x; Y = y; Z = z; } - -inline Standard_Real gp_XYZ::X () const -{ return x; } - -inline Standard_Real gp_XYZ::Y () const -{ return y; } - -inline Standard_Real gp_XYZ::Z () const -{ return z; } - -inline Standard_Real gp_XYZ::Modulus () const { - return sqrt (x * x + y * y + z * z); -} - -inline Standard_Real gp_XYZ::SquareModulus () const { - return (x * x + y * y + z * z); -} - -inline void gp_XYZ::Add (const gp_XYZ& Other) -{ - x += Other.x; - y += Other.y; - z += Other.z; -} - -inline gp_XYZ gp_XYZ::Added (const gp_XYZ& Other) const { - return gp_XYZ(x + Other.x,y + Other.y,z + Other.z); -} - -inline void gp_XYZ::Cross (const gp_XYZ& Right) -{ - Standard_Real Xresult = y * Right.z - z * Right.y; - Standard_Real Yresult = z * Right.x - x * Right.z; - z = x * Right.y - y * Right.x; - x = Xresult; - y = Yresult; -} - -inline gp_XYZ gp_XYZ::Crossed (const gp_XYZ& Right) const -{ - return gp_XYZ (y * Right.z - z * Right.y, - z * Right.x - x * Right.z, - x * Right.y - y * Right.x); -} - -inline Standard_Real gp_XYZ::CrossMagnitude (const gp_XYZ& Right) const -{ - Standard_Real Xresult = y * Right.z - z * Right.y; - Standard_Real Yresult = z * Right.x - x * Right.z; - Standard_Real Zresult = x * Right.y - y * Right.x; - return sqrt(Xresult * Xresult + Yresult * Yresult + Zresult * Zresult); -} - -inline Standard_Real gp_XYZ::CrossSquareMagnitude (const gp_XYZ& Right) const -{ - Standard_Real Xresult = y * Right.z - z * Right.y; - Standard_Real Yresult = z * Right.x - x * Right.z; - Standard_Real Zresult = x * Right.y - y * Right.x; - return Xresult * Xresult + Yresult * Yresult + Zresult * Zresult; -} - -inline void gp_XYZ::CrossCross (const gp_XYZ& Coord1, - const gp_XYZ& Coord2) -{ - Standard_Real Xresult = - y * (Coord1.x * Coord2.y - Coord1.y * Coord2.x) - - z * (Coord1.z * Coord2.x - Coord1.x * Coord2.z); - Standard_Real Yresult = - z * (Coord1.y * Coord2.z - Coord1.z * Coord2.y) - - x * (Coord1.x * Coord2.y - Coord1.y * Coord2.x); - z = - x * (Coord1.z * Coord2.x - Coord1.x * Coord2.z) - - y * (Coord1.y * Coord2.z - Coord1.z * Coord2.y); - x = Xresult; - y = Yresult; -} - -inline gp_XYZ gp_XYZ::CrossCrossed (const gp_XYZ& Coord1, - const gp_XYZ& Coord2) const -{ - gp_XYZ Coord0 = *this; - Coord0.CrossCross (Coord1, Coord2); - return Coord0; -} - -inline void gp_XYZ::Divide (const Standard_Real Scalar) -{ - x /= Scalar; - y /= Scalar; - z /= Scalar; -} - -inline gp_XYZ gp_XYZ::Divided (const Standard_Real Scalar) const { - return gp_XYZ(x / Scalar,y / Scalar,z / Scalar); -} - -inline Standard_Real gp_XYZ::Dot (const gp_XYZ& Other) const { - return(x * Other.x + y * Other.y + z * Other.z); -} - -inline Standard_Real gp_XYZ::DotCross (const gp_XYZ& Coord1, - const gp_XYZ& Coord2) const -{ - Standard_Real Xresult = Coord1.y * Coord2.z - Coord1.z * Coord2.y; - Standard_Real Yresult = Coord1.z * Coord2.x - Coord1.x * Coord2.z; - Standard_Real Zresult = Coord1.x * Coord2.y - Coord1.y * Coord2.x; - return ( x * Xresult + y * Yresult + z * Zresult); -} - -inline void gp_XYZ::Multiply (const Standard_Real Scalar) -{ - x *= Scalar; - y *= Scalar; - z *= Scalar; -} - -inline void gp_XYZ::Multiply (const gp_XYZ& Other) -{ - x *= Other.x; - y *= Other.y; - z *= Other.z; -} - -inline void gp_XYZ::Multiply (const gp_Mat& Matrix) -{ - Standard_Real Xresult = Matrix.matrix[0][0] * x + Matrix.matrix[0][1] * y + Matrix.matrix[0][2] * z; - Standard_Real Yresult = Matrix.matrix[1][0] * x + Matrix.matrix[1][1] * y + Matrix.matrix[1][2] * z; - z = Matrix.matrix[2][0] * x + Matrix.matrix[2][1] * y + Matrix.matrix[2][2] * z; - x = Xresult; - y = Yresult; -} - -inline gp_XYZ gp_XYZ::Multiplied (const Standard_Real Scalar) const { - return gp_XYZ(x * Scalar,y * Scalar,z * Scalar); -} - -inline gp_XYZ gp_XYZ::Multiplied (const gp_XYZ& Other) const { - return gp_XYZ(x * Other.x, y * Other.y, z * Other.z); -} - -inline gp_XYZ gp_XYZ::Multiplied (const gp_Mat& Matrix) const -{ - return gp_XYZ (Matrix.matrix[0][0] * x + Matrix.matrix[0][1] * y + Matrix.matrix[0][2] * z, - Matrix.matrix[1][0] * x + Matrix.matrix[1][1] * y + Matrix.matrix[1][2] * z, - Matrix.matrix[2][0] * x + Matrix.matrix[2][1] * y + Matrix.matrix[2][2] * z); -} - -inline void gp_XYZ::Normalize () -{ - Standard_Real D = Modulus(); - Standard_ConstructionError_Raise_if (D <= gp::Resolution(), - "gp_XYZ::Normalize() - vector has zero norm"); - x = x / D; y = y / D; z = z / D; -} - -inline gp_XYZ gp_XYZ::Normalized () const -{ - Standard_Real D = Modulus(); - Standard_ConstructionError_Raise_if (D <= gp::Resolution(), - "gp_XYZ::Normalized() - vector has zero norm"); - return gp_XYZ (x / D, y / D, z / D); -} - -inline void gp_XYZ::Reverse () -{ - x = - x; - y = - y; - z = - z; -} - -inline gp_XYZ gp_XYZ::Reversed () const -{ - return gp_XYZ(-x, -y, -z); -} - -inline void gp_XYZ::Subtract (const gp_XYZ& Right) -{ - x-=Right.x; - y-=Right.y; - z-=Right.z; -} - -inline gp_XYZ gp_XYZ::Subtracted (const gp_XYZ& Right) const -{ - return gp_XYZ(x - Right.x, y - Right.y, z - Right.z); -} - -inline void gp_XYZ::SetLinearForm (const Standard_Real L, - const gp_XYZ& Left, - const Standard_Real R, - const gp_XYZ& Right) { - - x = L * Left.x + R * Right.x; - y = L * Left.y + R * Right.y; - z = L * Left.z + R * Right.z; -} - -inline void gp_XYZ::SetLinearForm(const Standard_Real L, - const gp_XYZ& Left, - const gp_XYZ& Right) { - x = L * Left.x + Right.x; - y = L * Left.y + Right.y; - z = L * Left.z + Right.z; -} - -inline void gp_XYZ::SetLinearForm (const gp_XYZ& Left, const gp_XYZ& Right) { - x = Left.x + Right.x; - y = Left.y + Right.y; - z = Left.z + Right.z; -} - -inline void gp_XYZ::SetLinearForm (const Standard_Real A1, const gp_XYZ& XYZ1, - const Standard_Real A2, const gp_XYZ& XYZ2, - const Standard_Real A3, const gp_XYZ& XYZ3) { - - x = A1 * XYZ1.x + A2 * XYZ2.x + A3 * XYZ3.x; - y = A1 * XYZ1.y + A2 * XYZ2.y + A3 * XYZ3.y; - z = A1 * XYZ1.z + A2 * XYZ2.z + A3 * XYZ3.z; -} - -inline void gp_XYZ::SetLinearForm (const Standard_Real A1, const gp_XYZ& XYZ1, - const Standard_Real A2, const gp_XYZ& XYZ2, - const gp_XYZ& XYZ3) { - x = A1 * XYZ1.x + A2 * XYZ2.x + XYZ3.x; - y = A1 * XYZ1.y + A2 * XYZ2.y + XYZ3.y; - z = A1 * XYZ1.z + A2 * XYZ2.z + XYZ3.z; -} - -inline void gp_XYZ::SetLinearForm (const Standard_Real A1, const gp_XYZ& XYZ1, - const Standard_Real A2, const gp_XYZ& XYZ2, - const Standard_Real A3, const gp_XYZ& XYZ3, - const gp_XYZ& XYZ4) { - x = A1 * XYZ1.x + A2 * XYZ2.x + A3 * XYZ3.x + XYZ4.x; - y = A1 * XYZ1.y + A2 * XYZ2.y + A3 * XYZ3.y + XYZ4.y; - z = A1 * XYZ1.z + A2 * XYZ2.z + A3 * XYZ3.z + XYZ4.z; - -} - -inline gp_XYZ operator* (const gp_Mat& Matrix, const gp_XYZ& Coord1) { - return Coord1.Multiplied (Matrix); -} - -inline gp_XYZ operator* (const Standard_Real Scalar, const gp_XYZ& Coord1) { - return Coord1.Multiplied (Scalar); -} - - - - - -