diff options
| author | Andreas Grois <andreas.grois@jku.at> | 2015-11-06 13:45:57 +0100 |
|---|---|---|
| committer | Andreas Grois <andreas.grois@jku.at> | 2015-11-06 13:45:57 +0100 |
| commit | 4aa67d78e9238a65eb94a762328465e2541fd4c4 (patch) | |
| tree | 3711d160e87be100f8f31ba806a47b7efa600e56 /anglerange.cpp | |
| parent | 05714900ad7c1638237749e88faae3ecdb19649e (diff) | |
Combine and sort results
This change introduces (experimental and not very clean) combining of results. It might be worth writing a disjoint angle range class to get cleaner code here, as the while loops at the end are quite far from being beautiful.
In addition the output ranges are sorted by their lower border. I'm using Lambda expressions for this, so C+11 is required.
Also, this is currently completely untested.
Diffstat (limited to 'anglerange.cpp')
| -rw-r--r-- | anglerange.cpp | 84 |
1 files changed, 83 insertions, 1 deletions
diff --git a/anglerange.cpp b/anglerange.cpp index f6b8264..7dda2e9 100644 --- a/anglerange.cpp +++ b/anglerange.cpp @@ -98,7 +98,7 @@ anglerange anglerange::overlap(const anglerange &other) //Here we need to take care to always follow the counter-clockwise convention. //This leaves us with four possibilities: //a) Both ranges contain the zero-line - //b) This range contains the zero-line, the other doesn'T + //b) This range contains the zero-line, the other doesn't //c) Vice versa //d) Both ranges are regular. @@ -170,3 +170,85 @@ anglerange anglerange::overlap(const anglerange &other) } return(retval); } + +anglerange anglerange::combine(const anglerange &other) +{ + anglerange retval; + //check if any of the ranges is empty. If yes: return an empty range as well. + if(!(isempty()) && !(other.isempty())){ + //Here we need to take care to always follow the counter-clockwise convention. + //This leaves us with four possibilities: + //a) Both ranges contain the zero-line + //b) This range contains the zero-line, the other doesn't + //c) Vice versa + //d) Both ranges are regular. + + //first check if this range contains the zero-line + if(lowerborder>upperborder) + { + //ok, this range is around zero. Let's check the other one too: + if(other.getlower()>other.getupper()) + { + //ok, both ranges contain the zero-line. + retval.setlower(fmin(lowerborder.getval(),other.getlower().getval())); + retval.setupper(fmax(upperborder.getval(),other.getupper().getval())); + } + else + { + //this contains zero, other doesn't. + //This cannot fully lie within other, but other can lie fully within this. + //The result does obviously contain zero. + //Let's check if other is within this. + if(other.getupper()<=upperborder || other.getlower()>=lowerborder){ + retval.setlower(lowerborder); + retval.setupper(upperborder); + } + else if(other.getupper()>=lowerborder) //not >, as per definition upperborder is inside range + { + retval.setlower(other.getlower()); + retval.setupper(upperborder); + } + else if(other.getlower()<=upperborder) //not <, as again upperborder is inside. + { + retval.setlower(lowerborder); + retval.setupper(other.getupper()); + } + } + } + else + { + //this is regular, is other as well? + if(other.getlower()>other.getupper()) + { + //so, other cannot lie in this, but this can be in other. + //Let's check for that. + if(upperborder<=other.getupper() || lowerborder>=other.getlower()){ + retval.setlower(other.getlower()); + retval.setupper(other.getupper()); + } + else if(lowerborder <= other.getupper()) + { + retval.setlower(other.getlower()); + retval.setupper(upperborder); + } + else if(upperborder >= other.getlower()) + { + retval.setlower(lowerborder); + retval.setupper(other.getupper()); + } + } + else //both ranges regular + { + //check if there's an overlap + double curmax = fmin(other.getupper().getval(),upperborder.getval()); + double curmin = fmax(other.getlower().getval(),lowerborder.getval()); + if(curmax>=curmin){ + //there is an overlap - set limits + retval.setlower(fmin(other.getlower().getval(),lowerborder.getval())); + retval.setupper(fmax(other.getupper().getval(),upperborder.getval())); + } + } + } + } + return(retval); +} |
