-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMPI_ParticleSegment.cpp
54 lines (41 loc) · 2.18 KB
/
MPI_ParticleSegment.cpp
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
//
// MPI_ParticleSegment.cpp
//
#include "MPI_ParticleSegment.h"
#include "MPI_IsctWithParticleSegmentVisitor.h"
#include "MPI_IntersectionElement.h"
MPI_ParticleSegment::MPI_ParticleSegment( MPI_Workspace &workspace, MPI_IntersectionPolyLine &intersectionpolyline, MPI_Point2D const &firstpoint, MPI_Point2D const &secondpoint, MPI_OneSpace &onespace, float const firstposition, float const secondposition, MPI_ElementFactory const& elementfactory ) :
MPI_Segment( workspace, intersectionpolyline, firstpoint, secondpoint ),
onespace_( onespace ),
firstposition_( firstposition ),
secondposition_( secondposition ),
elementfactory_( elementfactory )
{
// empty
}
void MPI_ParticleSegment::acceptVisitor( MPI_SegmentVisitor const& visitor )
{
visitor.visitParticleSegment( *this );
}
MPI_SegmentIntersectionVisitor* MPI_ParticleSegment::allocateIntersectionVisitor( void )
{
return new MPI_IsctWithParticleSegmentVisitor( *this );
}
void MPI_ParticleSegment::addParticleSegIntersection( MPI_ParticleSegment &otherseg, float thissegpos, float othersegpos )
{
// Add an intersection between this segment and otherseg at the parameter
// positions thissegpos and othersegpos.
// The intersection and parameter positions are assumed to be valid.
// The parameter positions are assumed to be given in local segment
// coordinates (0.0,1.0) as is returned by findIntersection().
// All we need to do is create an intersection pair linking the two
// onespaces that underlie the two particle segments.
// The static method createIntersectionPair() does this work for us.
// convert between local segment coordinates (0.0,1.0) to onespace
// coordinates using linear interpolation.
float thisonespacepos = thissegpos * (secondposition_ - firstposition_) + firstposition_;
float otheronespacepos = othersegpos * (otherseg.secondposition_ - otherseg.firstposition_) + otherseg.firstposition_;
// create the intersection pair linking the two onespaces
MPI_IntersectionElement::createIntersectionPair( onespace_, elementfactory_, thisonespacepos, otherseg.onespace_, otherseg.elementfactory_, otheronespacepos );
}
// vim:sw=4:et:cindent: