b311480e |
1 | // Created on: 1993-03-24 |
2 | // Created by: JCV |
3 | // Copyright (c) 1993-1999 Matra Datavision |
973c2be1 |
4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
5 | // |
973c2be1 |
6 | // This file is part of Open CASCADE Technology software library. |
b311480e |
7 | // |
d5f74e42 |
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 |
973c2be1 |
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. |
b311480e |
13 | // |
973c2be1 |
14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. |
7fd59977 |
16 | |
42cf5bc1 |
17 | |
18 | #include <Geom2d_Direction.hxx> |
19 | #include <Geom2d_Geometry.hxx> |
20 | #include <Geom2d_Vector.hxx> |
7fd59977 |
21 | #include <gp.hxx> |
42cf5bc1 |
22 | #include <gp_Dir2d.hxx> |
23 | #include <gp_Trsf2d.hxx> |
7fd59977 |
24 | #include <Standard_ConstructionError.hxx> |
42cf5bc1 |
25 | #include <Standard_Type.hxx> |
7fd59977 |
26 | |
27 | typedef Geom2d_Direction Direction; |
7fd59977 |
28 | typedef gp_Ax2d Ax2d; |
29 | typedef gp_Pnt2d Pnt2d; |
30 | typedef gp_Trsf2d Trsf2d; |
31 | |
32 | |
33 | |
34 | |
35 | |
36 | Handle(Geom2d_Geometry) Geom2d_Direction::Copy() const { |
37 | |
c04c30b3 |
38 | Handle(Geom2d_Direction) D; |
7fd59977 |
39 | D = new Direction (gpVec2d); |
40 | return D; |
41 | } |
42 | |
43 | |
44 | |
45 | |
46 | |
47 | |
48 | Geom2d_Direction::Geom2d_Direction (const Standard_Real X, const Standard_Real Y) { |
49 | |
50 | Standard_Real D = Sqrt (X * X + Y * Y); |
51 | Standard_ConstructionError_Raise_if (D <= gp::Resolution(), ""); |
52 | gpVec2d = gp_Vec2d (X/D, Y/D); |
53 | } |
54 | |
55 | |
56 | Geom2d_Direction::Geom2d_Direction (const gp_Dir2d& V) { gpVec2d = V; } |
57 | |
58 | |
59 | void Geom2d_Direction::SetCoord (const Standard_Real X, const Standard_Real Y) { |
60 | |
61 | Standard_Real D = Sqrt (X * X + Y * Y); |
62 | Standard_ConstructionError_Raise_if (D <= gp::Resolution(), ""); |
63 | gpVec2d = gp_Vec2d (X/D, Y/D); |
64 | } |
65 | |
66 | |
67 | void Geom2d_Direction::SetDir2d (const gp_Dir2d& V) { gpVec2d = V; } |
68 | |
69 | |
70 | void Geom2d_Direction::SetX (const Standard_Real X) { |
71 | |
72 | Standard_Real D = Sqrt(X * X + gpVec2d.Y() * gpVec2d.Y()); |
73 | Standard_ConstructionError_Raise_if (D <= gp::Resolution(), ""); |
74 | gpVec2d = gp_Vec2d (X/D, gpVec2d.Y()/D); |
75 | } |
76 | |
77 | |
78 | void Geom2d_Direction::SetY (const Standard_Real Y) { |
79 | |
80 | Standard_Real D = Sqrt (gpVec2d.X() * gpVec2d.X() + Y * Y); |
81 | Standard_ConstructionError_Raise_if (D <= gp::Resolution(), ""); |
82 | gpVec2d = gp_Vec2d (gpVec2d.X()/D, Y/D); |
83 | } |
84 | |
85 | |
86 | gp_Dir2d Geom2d_Direction::Dir2d () const { return gpVec2d; } |
87 | |
88 | |
89 | Standard_Real Geom2d_Direction::Magnitude () const { return 1.0; } |
90 | |
91 | |
92 | Standard_Real Geom2d_Direction::SquareMagnitude () const { return 1.0; } |
93 | |
94 | |
c04c30b3 |
95 | Standard_Real Geom2d_Direction::Crossed (const Handle(Geom2d_Vector)& Other) const { |
7fd59977 |
96 | |
97 | return gpVec2d.Crossed (Other->Vec2d()); |
98 | } |
99 | |
100 | |
101 | void Geom2d_Direction::Transform (const gp_Trsf2d& T) { |
102 | |
103 | gp_Dir2d dir = gpVec2d; |
104 | dir.Transform (T); |
105 | gpVec2d = dir; |
106 | } |