summaryrefslogtreecommitdiff
path: root/src/main/StraightElement.cc
blob: 24d63aa92fe6f01b676f5667d700334e609610ea (plain) (blame)
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
/*
 * StraightElement.cc
 *
 *  Created on: Mar 22, 2011
 *      Author: jakob
 */

#include "StraightElement.h"

namespace vhc {

StraightElement::StraightElement(const Vector3D& entry, const Vector3D& exit, double sectionRadius, Element* next):
		Element(entry, exit, sectionRadius, next)
	{};

StraightElement::~StraightElement() {};

bool StraightElement::isBefore(const Vector3D& position) const {
	const Vector3D v(position - exitPosition);
	return (-getDiagonal()).dot(v) > getDiagonal().normSquare();
}

bool StraightElement::isBeside(const Vector3D& position) const {
	Vector3D X = Vector3D(position - entryPosition);
	Vector3D d = getDiagonal().unit();
	return (X - X.dot(d) * d).norm() > sectionRadius;
};

bool StraightElement::isAfter(const Vector3D& position) const {
	const Vector3D v(position - entryPosition);
	return getDiagonal().dot(v) > getDiagonal().normSquare();
}

std::string StraightElement::getType() const {return "Straight Element";}
std::string StraightElement::toString() const {
	std::stringstream s;
	s << Element::toString();
	return s.str();
}

void StraightElement::accept(const ElementVisitor& v) const {v.visit(this);}

StraightElement* StraightElement::clone() const {return new StraightElement(getEntryPosition(), getExitPosition(), getSectionRadius());}

}