From fc46d20e8411fe4b67269733f69d8a9dded4a42f Mon Sep 17 00:00:00 2001 From: Andreas Grois Date: Tue, 10 Nov 2015 13:39:56 +0100 Subject: Add angle sets (disjoint ranges) - initial support MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit By adding a new angleset class, things get much easier to read. Also, the part of the previous commit that dealt with combining the individual ranges was kind of stupid. Things missing: o) functions to remove angle ranges from a set o) deferred add functions, that allow adding multiple ranges without calling the O(n²) function angleset::combine() in between. --- anglerange.h | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) (limited to 'anglerange.h') diff --git a/anglerange.h b/anglerange.h index ab98cbc..6d6d286 100644 --- a/anglerange.h +++ b/anglerange.h @@ -38,14 +38,22 @@ #define ANGLERANGE_H #include "angleclass.h" +#include class anglerange { +public: + typedef enum sorttype {SRT_LOWER,SRT_UPPER,SRT_SIZE} sorttype; private: angleclass lowerborder; angleclass upperborder; bool upperset; bool lowerset; + bool fullcircle; + sorttype sortby; //for comparison operators + //default value: SRT_SIZE + //lower means sort by lower border, upper sort by upper border, and size sort by (upper-lower) + //only size cares about zero-crossing, the others just compare numeric values. public: //Default constructor: Both limits 0.0, marked as empty anglerange(); @@ -54,9 +62,18 @@ public: void setupper(const angleclass &newupper); void setempty(); //marks the range as empty. + //to change sort field + void setsorttype(const sorttype value); + const sorttype getsorttype(); + bool isempty() const; //returns true when the range is empty (or when one limit isn't set) - angleclass getlower() const; //warning: Does not check if empty - angleclass getupper() const; //warning: Does not check if empty + angleclass getlower() const; //warning: Does not check if empty, does not check if circle + angleclass getupper() const; //warning: Does not check if empty, does not check if circle + bool isinside(const angleclass &val) const; //check if angleclas val is in the range. + + //to deal with full circles: + void setcircle(bool value); + bool iscircle() const; //this function calculates the overlap between this anglerange and another one, returning it as //a new anglerange. @@ -66,6 +83,16 @@ public: //if they are disjoint, an empty range is given back. anglerange combine(const anglerange &other); + bool operator<(const anglerange &other) const; + bool operator>(const anglerange &other) const; + bool operator<=(const anglerange &other) const; + bool operator>=(const anglerange &other) const; + + //these operators don't use sort order. They really compare by element! + //also: Two empty ranges are considered equal! + bool operator==(const anglerange &other) const; + bool operator!=(const anglerange &other) const; + }; #endif // ANGLERANGE_H -- cgit v1.2.3