forked from Alan502/fast-mingle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEdge.cpp
66 lines (54 loc) · 1.58 KB
/
Edge.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
55
56
57
58
59
60
61
62
63
64
/*
* Implementation file for the Edge class.
*/
#include "Edge.h"
#include "Point.h"
#include "EdgeIdGenerator.h"
Edge::Edge(Point source, Point target, EdgeIdGenerator idGenerator) {
_source = source;
_target = target;
_weight = 1;
_childrenInk = 0;
_parent = nullptr;
_id = idGenerator.generateNewID();
}
Edge::Edge(const Edge &edge, EdgeIdGenerator idGenerator) {
_source = edge._source;
_target = edge._target;
_weight = edge._weight;
_childrenInk = edge._childrenInk;
_parent = edge._parent;
_children = edge._children;
_id = idGenerator.generateNewID();
}
void Edge::addChild(Edge *child) {
if (!isChildWithinAngle(child)) {
throw "Child is not within the limit angle.";
}
_children.push_back(child);
_childrenInk +=
Point::getDistanceBetweenPoints(child->getSource(), getSource()) *
child->getInkWeight();
_childrenInk +=
Point::getDistanceBetweenPoints(child->getTarget(), getTarget()) *
child->getInkWeight();
_weight += child->getWeight();
}
bool Edge::isChildWithinAngle(Edge *child) {
bool isWithinAngle = true;
Point childSource = child->getSource();
Point childTarget = child->getTarget();
if (Point::getCosineOfAngleBetweenVectors(
_target - _source, _source - childSource) < cosineMaximumAngle) {
isWithinAngle = false;
}
if (Point::getCosineOfAngleBetweenVectors(
_source - _target, _target - childTarget) < cosineMaximumAngle) {
isWithinAngle = false;
}
return isWithinAngle;
}
void Edge::clearParent() { _parent = nullptr; }
char *Edge::get_id() const {
return _id;
}