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