Sat, 17 Mar 2018 12:29:52 +0200
Added a new tool for clamping vertices
1251
e75cc5bff076
Converted magic wand mode and other selection stuff to mvc
Santeri Piippo
parents:
diff
changeset
|
1 | /* |
e75cc5bff076
Converted magic wand mode and other selection stuff to mvc
Santeri Piippo
parents:
diff
changeset
|
2 | * LDForge: LDraw parts authoring CAD |
e75cc5bff076
Converted magic wand mode and other selection stuff to mvc
Santeri Piippo
parents:
diff
changeset
|
3 | * Copyright (C) 2013 - 2017 Teemu Piippo |
e75cc5bff076
Converted magic wand mode and other selection stuff to mvc
Santeri Piippo
parents:
diff
changeset
|
4 | * |
e75cc5bff076
Converted magic wand mode and other selection stuff to mvc
Santeri Piippo
parents:
diff
changeset
|
5 | * This program is free software: you can redistribute it and/or modify |
e75cc5bff076
Converted magic wand mode and other selection stuff to mvc
Santeri Piippo
parents:
diff
changeset
|
6 | * it under the terms of the GNU General Public License as published by |
e75cc5bff076
Converted magic wand mode and other selection stuff to mvc
Santeri Piippo
parents:
diff
changeset
|
7 | * the Free Software Foundation, either version 3 of the License, or |
e75cc5bff076
Converted magic wand mode and other selection stuff to mvc
Santeri Piippo
parents:
diff
changeset
|
8 | * (at your option) any later version. |
e75cc5bff076
Converted magic wand mode and other selection stuff to mvc
Santeri Piippo
parents:
diff
changeset
|
9 | * |
e75cc5bff076
Converted magic wand mode and other selection stuff to mvc
Santeri Piippo
parents:
diff
changeset
|
10 | * This program is distributed in the hope that it will be useful, |
e75cc5bff076
Converted magic wand mode and other selection stuff to mvc
Santeri Piippo
parents:
diff
changeset
|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
e75cc5bff076
Converted magic wand mode and other selection stuff to mvc
Santeri Piippo
parents:
diff
changeset
|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
e75cc5bff076
Converted magic wand mode and other selection stuff to mvc
Santeri Piippo
parents:
diff
changeset
|
13 | * GNU General Public License for more details. |
e75cc5bff076
Converted magic wand mode and other selection stuff to mvc
Santeri Piippo
parents:
diff
changeset
|
14 | * |
e75cc5bff076
Converted magic wand mode and other selection stuff to mvc
Santeri Piippo
parents:
diff
changeset
|
15 | * You should have received a copy of the GNU General Public License |
e75cc5bff076
Converted magic wand mode and other selection stuff to mvc
Santeri Piippo
parents:
diff
changeset
|
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
e75cc5bff076
Converted magic wand mode and other selection stuff to mvc
Santeri Piippo
parents:
diff
changeset
|
17 | */ |
e75cc5bff076
Converted magic wand mode and other selection stuff to mvc
Santeri Piippo
parents:
diff
changeset
|
18 | |
e75cc5bff076
Converted magic wand mode and other selection stuff to mvc
Santeri Piippo
parents:
diff
changeset
|
19 | #include "linesegment.h" |
e75cc5bff076
Converted magic wand mode and other selection stuff to mvc
Santeri Piippo
parents:
diff
changeset
|
20 | |
e75cc5bff076
Converted magic wand mode and other selection stuff to mvc
Santeri Piippo
parents:
diff
changeset
|
21 | /* |
e75cc5bff076
Converted magic wand mode and other selection stuff to mvc
Santeri Piippo
parents:
diff
changeset
|
22 | * Returns the vertices of this line segment as a QPair. |
e75cc5bff076
Converted magic wand mode and other selection stuff to mvc
Santeri Piippo
parents:
diff
changeset
|
23 | */ |
e75cc5bff076
Converted magic wand mode and other selection stuff to mvc
Santeri Piippo
parents:
diff
changeset
|
24 | QPair<Vertex, Vertex> LineSegment::toPair() const |
e75cc5bff076
Converted magic wand mode and other selection stuff to mvc
Santeri Piippo
parents:
diff
changeset
|
25 | { |
e75cc5bff076
Converted magic wand mode and other selection stuff to mvc
Santeri Piippo
parents:
diff
changeset
|
26 | return {this->v_1, this->v_2}; |
e75cc5bff076
Converted magic wand mode and other selection stuff to mvc
Santeri Piippo
parents:
diff
changeset
|
27 | } |
e75cc5bff076
Converted magic wand mode and other selection stuff to mvc
Santeri Piippo
parents:
diff
changeset
|
28 | |
e75cc5bff076
Converted magic wand mode and other selection stuff to mvc
Santeri Piippo
parents:
diff
changeset
|
29 | /* |
e75cc5bff076
Converted magic wand mode and other selection stuff to mvc
Santeri Piippo
parents:
diff
changeset
|
30 | * Possibly swaps the vertices of given line segment so that equivalent line segments become equal. |
e75cc5bff076
Converted magic wand mode and other selection stuff to mvc
Santeri Piippo
parents:
diff
changeset
|
31 | */ |
e75cc5bff076
Converted magic wand mode and other selection stuff to mvc
Santeri Piippo
parents:
diff
changeset
|
32 | LineSegment normalized(const LineSegment& segment) |
e75cc5bff076
Converted magic wand mode and other selection stuff to mvc
Santeri Piippo
parents:
diff
changeset
|
33 | { |
e75cc5bff076
Converted magic wand mode and other selection stuff to mvc
Santeri Piippo
parents:
diff
changeset
|
34 | LineSegment result = segment; |
e75cc5bff076
Converted magic wand mode and other selection stuff to mvc
Santeri Piippo
parents:
diff
changeset
|
35 | |
e75cc5bff076
Converted magic wand mode and other selection stuff to mvc
Santeri Piippo
parents:
diff
changeset
|
36 | if (result.v_2 < result.v_1) |
e75cc5bff076
Converted magic wand mode and other selection stuff to mvc
Santeri Piippo
parents:
diff
changeset
|
37 | qSwap(result.v_1, result.v_2); |
e75cc5bff076
Converted magic wand mode and other selection stuff to mvc
Santeri Piippo
parents:
diff
changeset
|
38 | |
e75cc5bff076
Converted magic wand mode and other selection stuff to mvc
Santeri Piippo
parents:
diff
changeset
|
39 | return result; |
e75cc5bff076
Converted magic wand mode and other selection stuff to mvc
Santeri Piippo
parents:
diff
changeset
|
40 | } |
e75cc5bff076
Converted magic wand mode and other selection stuff to mvc
Santeri Piippo
parents:
diff
changeset
|
41 | |
e75cc5bff076
Converted magic wand mode and other selection stuff to mvc
Santeri Piippo
parents:
diff
changeset
|
42 | /* |
e75cc5bff076
Converted magic wand mode and other selection stuff to mvc
Santeri Piippo
parents:
diff
changeset
|
43 | * Overload of qHash for line segments. |
e75cc5bff076
Converted magic wand mode and other selection stuff to mvc
Santeri Piippo
parents:
diff
changeset
|
44 | */ |
e75cc5bff076
Converted magic wand mode and other selection stuff to mvc
Santeri Piippo
parents:
diff
changeset
|
45 | unsigned int qHash(const LineSegment& segment) |
e75cc5bff076
Converted magic wand mode and other selection stuff to mvc
Santeri Piippo
parents:
diff
changeset
|
46 | { |
e75cc5bff076
Converted magic wand mode and other selection stuff to mvc
Santeri Piippo
parents:
diff
changeset
|
47 | return qHash(normalized(segment).toPair()); |
e75cc5bff076
Converted magic wand mode and other selection stuff to mvc
Santeri Piippo
parents:
diff
changeset
|
48 | } |
e75cc5bff076
Converted magic wand mode and other selection stuff to mvc
Santeri Piippo
parents:
diff
changeset
|
49 | |
e75cc5bff076
Converted magic wand mode and other selection stuff to mvc
Santeri Piippo
parents:
diff
changeset
|
50 | /* |
e75cc5bff076
Converted magic wand mode and other selection stuff to mvc
Santeri Piippo
parents:
diff
changeset
|
51 | * Comparison operator definition to allow line segments to be used in QSets. |
e75cc5bff076
Converted magic wand mode and other selection stuff to mvc
Santeri Piippo
parents:
diff
changeset
|
52 | */ |
e75cc5bff076
Converted magic wand mode and other selection stuff to mvc
Santeri Piippo
parents:
diff
changeset
|
53 | bool operator<(const LineSegment& one, const LineSegment& other) |
e75cc5bff076
Converted magic wand mode and other selection stuff to mvc
Santeri Piippo
parents:
diff
changeset
|
54 | { |
e75cc5bff076
Converted magic wand mode and other selection stuff to mvc
Santeri Piippo
parents:
diff
changeset
|
55 | return normalized(one).toPair() < normalized(other).toPair(); |
e75cc5bff076
Converted magic wand mode and other selection stuff to mvc
Santeri Piippo
parents:
diff
changeset
|
56 | } |
e75cc5bff076
Converted magic wand mode and other selection stuff to mvc
Santeri Piippo
parents:
diff
changeset
|
57 | |
e75cc5bff076
Converted magic wand mode and other selection stuff to mvc
Santeri Piippo
parents:
diff
changeset
|
58 | /* |
e75cc5bff076
Converted magic wand mode and other selection stuff to mvc
Santeri Piippo
parents:
diff
changeset
|
59 | * Checks whether two line segments are equal. |
e75cc5bff076
Converted magic wand mode and other selection stuff to mvc
Santeri Piippo
parents:
diff
changeset
|
60 | */ |
e75cc5bff076
Converted magic wand mode and other selection stuff to mvc
Santeri Piippo
parents:
diff
changeset
|
61 | bool operator==(const LineSegment& one, const LineSegment& other) |
e75cc5bff076
Converted magic wand mode and other selection stuff to mvc
Santeri Piippo
parents:
diff
changeset
|
62 | { |
e75cc5bff076
Converted magic wand mode and other selection stuff to mvc
Santeri Piippo
parents:
diff
changeset
|
63 | return (one.v_1 == other.v_1 and one.v_2 == other.v_2) |
e75cc5bff076
Converted magic wand mode and other selection stuff to mvc
Santeri Piippo
parents:
diff
changeset
|
64 | or (one.v_2 == other.v_1 and one.v_1 == other.v_2); |
e75cc5bff076
Converted magic wand mode and other selection stuff to mvc
Santeri Piippo
parents:
diff
changeset
|
65 | } |