| 1 |
#include "LineSet.h" |
| 2 |
|
| 3 |
LineSet::LineSet() |
| 4 |
{ |
| 5 |
m_bbx_set=false; |
| 6 |
} |
| 7 |
|
| 8 |
|
| 9 |
int LineSet::isCrossing(const Vector3& p1, const Vector3& p2) const |
| 10 |
{ |
| 11 |
int res=-1; |
| 12 |
|
| 13 |
vector<LineSegment2D>::const_iterator iter=m_segments.begin(); |
| 14 |
while((iter!=m_segments.end()) && (res==-1)){ |
| 15 |
if(iter->crosses(p1,p2)) res=iter->getTag(); |
| 16 |
iter++; |
| 17 |
} |
| 18 |
|
| 19 |
return res; |
| 20 |
} |
| 21 |
|
| 22 |
void LineSet::addLineSegment(const Vector3& p1, const Vector3& p2,int tag) |
| 23 |
{ |
| 24 |
LineSegment2D L=LineSegment2D(p1,p2,tag); |
| 25 |
Vector3 tmin=L.getMinPoint(); |
| 26 |
Vector3 tmax=L.getMaxPoint(); |
| 27 |
m_segments.push_back(L); |
| 28 |
// update bounding box |
| 29 |
if(m_bbx_set){ // already have bbx -> update |
| 30 |
m_pmin.X()=(m_pmin.X() < tmin.X()) ? m_pmin.X() : tmin.X(); |
| 31 |
m_pmin.Y()=(m_pmin.Y() < tmin.Y()) ? m_pmin.Y() : tmin.Y(); |
| 32 |
m_pmax.X()=(m_pmax.X() > tmax.X()) ? m_pmax.X() : tmax.X(); |
| 33 |
m_pmax.Y()=(m_pmax.Y() > tmax.Y()) ? m_pmax.Y() : tmax.Y(); |
| 34 |
} else { // no bbx yet -> initialize |
| 35 |
m_pmin=tmin; |
| 36 |
m_pmax=tmax; |
| 37 |
m_bbx_set=true; |
| 38 |
} |
| 39 |
} |