-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathHILine.cpp
More file actions
129 lines (110 loc) · 2.71 KB
/
HILine.cpp
File metadata and controls
129 lines (110 loc) · 2.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
// HILine.cpp
// Copyright (c) 2009, Dan Heeks
// This program is released under the BSD license. See the file COPYING for details.
#include "stdafx.h"
#include "HILine.h"
#include "HLine.h"
#include "HArc.h"
#include "HCircle.h"
#include "HPoint.h"
HILine::HILine(const HILine &line):EndedObject(){
operator=(line);
}
HILine::HILine(const gp_Pnt &a, const gp_Pnt &b, const HeeksColor* col):EndedObject(){
A = a;
B = b;
SetColor(*col);
}
HILine::~HILine(){
}
const HILine& HILine::operator=(const HILine &b){
EndedObject::operator=(b);
return *this;
}
HeeksObj *HILine::MakeACopy(void)const{
HILine *new_object = new HILine(*this);
return new_object;
}
void HILine::GetBox(CBox &box){
box.Insert(A.X(), A.Y(), A.Z());
box.Insert(B.X(), B.Y(), B.Z());
}
bool HILine::FindNearPoint(const double* ray_start, const double* ray_direction, double *point){
gp_Lin ray(make_point(ray_start), make_vector(ray_direction));
gp_Pnt p1, p2;
ClosestPointsOnLines(GetLine(), ray, p1, p2);
extract(p1, point);
return true;
}
bool HILine::FindPossTangentPoint(const double* ray_start, const double* ray_direction, double *point){
// any point on this line is a possible tangent point
return FindNearPoint(ray_start, ray_direction, point);
}
gp_Lin HILine::GetLine()const{
gp_Vec v(A,B);
return gp_Lin(A, v);
}
int HILine::Intersects(const HeeksObj *object, std::list< double > *rl)const{
int numi = 0;
switch(object->GetType())
{
case SketchType:
return( ((CSketch *)object)->Intersects( this, rl ));
case LineType:
{
gp_Pnt pnt;
if(intersect(GetLine(), ((HLine*)object)->GetLine(), pnt))
{
if(((HLine*)object)->Intersects(pnt)){
if(rl)add_pnt_to_doubles(pnt, *rl);
numi++;
}
}
}
break;
case ILineType:
{
gp_Pnt pnt;
if(intersect(GetLine(), ((HILine*)object)->GetLine(), pnt))
{
if(rl)add_pnt_to_doubles(pnt, *rl);
numi++;
}
}
break;
case ArcType:
{
std::list<gp_Pnt> plist;
intersect(GetLine(), ((HArc*)object)->GetCircle(), plist);
for(std::list<gp_Pnt>::iterator It = plist.begin(); It != plist.end(); It++)
{
gp_Pnt& pnt = *It;
if(((HArc*)object)->Intersects(pnt))
{
if(rl)add_pnt_to_doubles(pnt, *rl);
numi++;
}
}
}
break;
case CircleType:
{
std::list<gp_Pnt> plist;
intersect(GetLine(), ((HCircle*)object)->GetCircle(), plist);
if(rl)convert_pnts_to_doubles(plist, *rl);
numi += plist.size();
}
break;
}
return numi;
}
bool HILine::GetStartPoint(double* pos)
{
extract(A, pos);
return true;
}
bool HILine::GetEndPoint(double* pos)
{
extract(B, pos);
return true;
}