// 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); }