diff options
| -rw-r--r-- | anglerange.cpp | 4 | ||||
| -rw-r--r-- | anglerange.h | 6 | ||||
| -rw-r--r-- | angleset.cpp | 18 |
3 files changed, 21 insertions, 7 deletions
diff --git a/anglerange.cpp b/anglerange.cpp index c62f760..99e6718 100644 --- a/anglerange.cpp +++ b/anglerange.cpp @@ -144,7 +144,7 @@ bool anglerange::isinside(const angleclass &val) const } } -anglerange anglerange::overlap(const anglerange &other) +anglerange anglerange::overlap(const anglerange &other) const { //storage for the return value: anglerange retval; //anglerange constructor without arguments: emtpy range [0:0] @@ -239,7 +239,7 @@ anglerange anglerange::overlap(const anglerange &other) return(retval); } -anglerange anglerange::combine(const anglerange &other) +anglerange anglerange::combine(const anglerange &other) const { anglerange retval; retval.setsorttype(sortby); //return value inherits current sorttype. diff --git a/anglerange.h b/anglerange.h index 6d6d286..f0c9eec 100644 --- a/anglerange.h +++ b/anglerange.h @@ -77,11 +77,13 @@ public: //this function calculates the overlap between this anglerange and another one, returning it as //a new anglerange. - anglerange overlap(const anglerange &other); + anglerange overlap(const anglerange &other) const; //this function does the opposite of overlap: Both ranges are combined into one bigger range. //if they are disjoint, an empty range is given back. - anglerange combine(const anglerange &other); + anglerange combine(const anglerange &other) const; + + //a subtract function is not possible at this level, as single angle ranges could get disjoint by it. bool operator<(const anglerange &other) const; bool operator>(const anglerange &other) const; diff --git a/angleset.cpp b/angleset.cpp index fc759b8..24d5b62 100644 --- a/angleset.cpp +++ b/angleset.cpp @@ -114,9 +114,10 @@ void angleset::add(const anglerange &value) //this means: we *should not reuse* this function for adding anglesets. if(!value.isempty()) { + consistent=false; storage.push_back(value); storage.back().setsorttype(anglerange::SRT_LOWER); - combine(); + //combine(); } } @@ -125,14 +126,16 @@ void angleset::add(const angleset &value) storage.reserve(storage.size()+value.storage.size()); storage.insert(storage.end(),value.storage.begin(),value.storage.end()); //if value is a valid angleset, sort order is set to SRT_LOWER for all fields. - combine(); + consistent=false; + //combine(); } void angleset::add(const double &lower, const double &upper) { storage.push_back(anglerange(lower,upper)); storage.back().setsorttype(anglerange::SRT_LOWER); - combine(); + consistent=false; + //combine(); } @@ -164,25 +167,34 @@ angleset angleset::overlap(const angleset &other) retval.add(overlap(i)); } ); + if(!other.consistent) + retval.combine(); return(retval); } std::vector<anglerange> angleset::getranges() { + if(!consistent) + combine(); return storage; } const std::vector<anglerange>& angleset::getrangesref() { + if(!consistent) + combine(); return storage; } void angleset::clear() { storage.clear(); + consistent=true; } void angleset::sort() { + if(!consistent) + combine(); std::sort(storage.begin(),storage.end()); } |
