1 // Copyright (C) 2012-2019 The VPaint Developers.
2 // See the COPYRIGHT file at the top-level directory of this distribution
3 // and at https://github.com/dalboris/vpaint/blob/master/COPYRIGHT
4 //
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 
17 #ifndef INSTANTLOOP_H
18 #define INSTANTLOOP_H
19 
20 #include "../TimeDef.h"
21 
22 #include <QList>
23 #include "KeyHalfedge.h"
24 
25 ////////////// Forward declare global serialization operators /////////////////
26 
27 namespace VectorAnimationComplex { class ProperCycle; }
28 QTextStream & operator<<(QTextStream &, const VectorAnimationComplex::ProperCycle &);
29 QTextStream & operator>>(QTextStream &, VectorAnimationComplex::ProperCycle &);
30 
31 ///////////////////////////////////////////////////////////////////////////////
32 
33 namespace VectorAnimationComplex
34 {
35 // A proper path is either a list of n>1 consecutive open halfeges satisfying:
36 //  * no repeated halfedge
37 //  * startVertex() == endVertex()
38 // Or a single closed halfedge
39 class ProperCycle
40 {
41 public:
42     // invalid loop
43     ProperCycle();
44 
45     // edges: unsorted set of instant edges
46     ProperCycle(const KeyEdgeSet & edgeSet);
47 
48     bool isValid() const;
49 
50     // all methods below assume that the loop is valid
51     Time time() const;
52     int size() const;
53     KeyHalfedge operator[](int i) const;
54 
55     // serialization and copy
56     void remapPointers(VAC * newVAC);
57     friend QTextStream & ::operator<<(QTextStream & out, const ProperCycle & loop);
58     friend QTextStream & ::operator>>(QTextStream & in, ProperCycle & loop);
59     void convertTempIdsToPointers(VAC * vac);
60 
61     // Replace pointed edges
62     void replaceEdges(KeyEdge * oldEdge, const KeyEdgeList & newEdges);
63 
64 private:
65     // sorted list of instant edges, guaranted to share the same time
66     QList<KeyHalfedge> halfedges_;
67 };
68 
69 } // end namespace VectorAnimationComplex
70 
71 #endif // INSTANTLOOP_H
72