0030754: Coding - the array of weights should begin with Lower, not the constant...
[occt.git] / src / Geom2d / Geom2d_Direction.cxx
1 // Created on: 1993-03-24
2 // Created by: JCV
3 // Copyright (c) 1993-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17
18 #include <Geom2d_Direction.hxx>
19 #include <Geom2d_Geometry.hxx>
20 #include <Geom2d_Vector.hxx>
21 #include <gp.hxx>
22 #include <gp_Dir2d.hxx>
23 #include <gp_Trsf2d.hxx>
24 #include <Standard_ConstructionError.hxx>
25 #include <Standard_Type.hxx>
26
27 IMPLEMENT_STANDARD_RTTIEXT(Geom2d_Direction,Geom2d_Vector)
28
29 typedef Geom2d_Direction         Direction;
30 typedef gp_Ax2d   Ax2d;
31 typedef gp_Pnt2d  Pnt2d;
32 typedef gp_Trsf2d Trsf2d;
33
34
35
36
37
38 Handle(Geom2d_Geometry) Geom2d_Direction::Copy() const {
39
40   Handle(Geom2d_Direction) D;
41   D = new Direction (gpVec2d);
42   return D; 
43 }
44
45
46
47
48
49
50 Geom2d_Direction::Geom2d_Direction (const Standard_Real X, const Standard_Real Y) {
51
52   Standard_Real D = Sqrt (X * X + Y * Y);
53   Standard_ConstructionError_Raise_if (D <= gp::Resolution(),
54                                        "Geom2d_Direction() - input vector has zero length");
55   gpVec2d = gp_Vec2d (X/D, Y/D);
56 }
57
58
59 Geom2d_Direction::Geom2d_Direction (const gp_Dir2d& V) { gpVec2d = V; }
60
61
62 void Geom2d_Direction::SetCoord (const Standard_Real X, const Standard_Real Y) {
63
64   Standard_Real D = Sqrt (X * X + Y * Y);
65   Standard_ConstructionError_Raise_if (D <= gp::Resolution(),
66                                        "Geom2d_Direction::SetCoord() - input vector has zero length");
67   gpVec2d = gp_Vec2d (X/D, Y/D);
68 }
69
70
71 void Geom2d_Direction::SetDir2d (const gp_Dir2d& V) { gpVec2d = V; }
72
73
74 void Geom2d_Direction::SetX (const Standard_Real X) {
75
76   Standard_Real D = Sqrt(X * X + gpVec2d.Y() * gpVec2d.Y());
77   Standard_ConstructionError_Raise_if (D <= gp::Resolution(),
78                                        "Geom2d_Direction::SetX() - input vector has zero length");
79   gpVec2d = gp_Vec2d (X/D, gpVec2d.Y()/D);
80 }
81
82
83 void Geom2d_Direction::SetY (const Standard_Real Y) {
84
85   Standard_Real D = Sqrt (gpVec2d.X() * gpVec2d.X() + Y * Y);
86   Standard_ConstructionError_Raise_if (D <= gp::Resolution(),
87                                        "Geom2d_Direction::SetY() - input vector has zero length");
88   gpVec2d = gp_Vec2d (gpVec2d.X()/D, Y/D);
89 }
90
91
92 gp_Dir2d Geom2d_Direction::Dir2d () const {  return gpVec2d; }
93
94
95 Standard_Real Geom2d_Direction::Magnitude () const { return 1.0; }
96
97
98 Standard_Real Geom2d_Direction::SquareMagnitude () const { return 1.0; }
99
100
101 Standard_Real Geom2d_Direction::Crossed (const Handle(Geom2d_Vector)& Other) const {
102
103    return gpVec2d.Crossed (Other->Vec2d());
104 }
105
106
107 void Geom2d_Direction::Transform (const gp_Trsf2d& T) { 
108
109   gp_Dir2d dir = gpVec2d;
110   dir.Transform (T);
111   gpVec2d = dir;
112 }