summaryrefslogtreecommitdiff
path: root/src/main/CompositeElement.cc
blob: 3b1a7090797fbd3e54f0db1ecb2b70041f3365e7 (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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*
 * CompositeElement.cc
 *
 *  Created on: Mar 23, 2011
 *      Author: jakob
 */

#include "CompositeElement.h"

namespace vhc {

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

CompositeElement::~CompositeElement() {};

bool CompositeElement::hasHit(const Particle& particle) const {
	for (int i(0); i < elements.size(); ++i) {
		if (elements[i]->hasHit(particle)) return true;
	}
	return false;
}

bool CompositeElement::isPast(const Particle& particle) const {
	if (elements[elements.size() - 1]->isPast(particle)) return true;
	else return false;
}

Vector3D CompositeElement::magneticFieldAt(const Vector3D& position) const {
	Vector3D b = Vector3D::Null;
	for (int i(0); i < elements.size(); i++) {
		b = b + elements[i]->magneticFieldAt(position);
	}
	return b;
}

Vector3D CompositeElement::electricFieldAt(const Vector3D& position) const {
	Vector3D e = Vector3D::Null;
	for (int i(0); i < elements.size(); i++) {
		e = e + elements[i]->electricFieldAt(position);
	}
	return e;
}

void CompositeElement::accept(const ElementVisitor& v) const {
	for (int i(0); i < elements.size(); ++i) {
		elements[i]->accept(v);
	}
}

std::string CompositeElement::toString() const {
	std::stringstream s;
	for (int i(0); i < elements.size(); ++i) {
		s << elements[i]->toString() << "\n";
	}
	return s.str();
}


} //vhc