-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconnector_pos.cpp
103 lines (83 loc) · 1.56 KB
/
connector_pos.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// SPDX-License-Identifier: GPL-2.0
#include "connector_pos.hpp"
#include <cassert>
ConnectorType::ConnectorType(int n_)
: n(n_)
{
}
ConnectorType::ConnectorType()
: n(-5)
{
}
ConnectorType ConnectorType::input_connector(int id)
{
assert(id >= 0);
return id * 2 + 1;
}
ConnectorType ConnectorType::output_connector(int id)
{
assert(id >= 0);
return id * 2;
}
ConnectorType ConnectorType::corner(int id)
{
assert(id >= 0 && id < 4);
return -id - 1;
}
bool ConnectorType::is_connector() const
{
return n >= 0;
}
bool ConnectorType::is_input_connector() const
{
return n >= 0 && (n % 2 != 0);
}
bool ConnectorType::is_output_connector() const
{
return n >= 0 && (n % 2 == 0);
}
bool ConnectorType::is_corner() const
{
return n < 0;
}
int ConnectorType::input_connector_id() const
{
assert(is_input_connector());
return (n - 1) / 2;
}
int ConnectorType::output_connector_id() const
{
assert(is_output_connector());
return n / 2;
}
int ConnectorType::corner_id() const
{
assert(is_corner());
return -n - 1;
}
bool ConnectorType::operator==(ConnectorType t) const
{
return n == t.n;
}
bool ConnectorType::operator!=(ConnectorType t) const
{
return n != t.n;
}
ConnectorPos::ConnectorPos(ConnectorType type_, const QPointF &pos_)
: type(type_)
, pos(pos_)
{
}
ConnectorDesc::ConnectorDesc(Operator *op_, ConnectorType type_)
: op(op_)
, type(type_)
{
}
bool ConnectorDesc::operator==(const ConnectorDesc &c) const
{
return op == c.op && type == c.type;
}
bool ConnectorDesc::operator!=(const ConnectorDesc &c) const
{
return op != c.op || type != c.type;
}