bool great_circle::arc::may_intersect(const great_circle::arc& target) const { double self_begin_longitude = begin_coordinates_.longitude; double self_end_longitude = end_coordinates_.longitude; double other_begin_longitude = target.begin_coordinates_.longitude; double other_end_longitude = target.end_coordinates_.longitude; // if either self or target wraps longitude over 180, unwrap bool wrap_self = false; if ( std::abs( self_end_longitude - self_begin_longitude ) > M_PI ) { self_end_longitude += two_pi; wrap_self = true; } bool wrap_other = false; if ( std::abs( other_end_longitude - other_begin_longitude ) > M_PI ) { other_end_longitude += two_pi; wrap_other = true; } // double conv = 180.0/M_PI; // std::cerr << std::setprecision(12) << "self: [" << begin_coordinates_.longitude*conv << "," << end_coordinates_.longitude*conv << "], [" << self_begin_longitude*conv << "," << self_end_longitude*conv << "], " << wrap_self << std::endl; // std::cerr << std::setprecision(12) << "other: [" << target.begin_coordinates_.longitude*conv << "," << target.end_coordinates_.longitude*conv << "], [" << other_begin_longitude*conv << "," << other_end_longitude*conv << "], " << wrap_self << std::endl; // now both intervals are unwrapped; the may overlap directly or with a shift if ( has_overlap( other_begin_longitude, other_end_longitude, self_begin_longitude, self_end_longitude ) ) return true; if ( wrap_self && has_overlap( other_begin_longitude + two_pi, other_end_longitude + two_pi, self_begin_longitude, self_end_longitude ) ) return true; if ( wrap_other && has_overlap( other_begin_longitude, other_end_longitude, self_begin_longitude + two_pi, self_end_longitude + two_pi ) ) return true; return false; }
bool great_circle::arc::may_intersect(const great_circle::arc& target) const { coordinates c1 = begin_coordinates_; coordinates c2 = end_coordinates_; coordinates d1 = target.begin_coordinates_; coordinates d2 = target.end_coordinates_; // if (!aero::has_overlap(c1.latitude, c2.latitude, d1.latitude, d2.latitude)) // { return false; } if (c1.longitude > M_PI_2 && c2.longitude < -M_PI_2) { c2.longitude += two_pi; if (d1.longitude < -M_PI_2) d1.longitude += two_pi; if (d2.longitude < -M_PI_2) d2.longitude += two_pi; } else if (c1.longitude < -M_PI_2 && c2.longitude > M_PI_2) { c1.longitude += two_pi; if (d1.longitude < -M_PI_2) d1.longitude += two_pi; if (d2.longitude < -M_PI_2) d2.longitude += two_pi; } if (d1.longitude > M_PI_2 && d2.longitude < -M_PI_2) { d2.longitude += two_pi; if (c1.longitude < -M_PI_2) c1.longitude += two_pi; if (c2.longitude < -M_PI_2) c2.longitude += two_pi; } else if (d1.longitude < -M_PI_2 && d2.longitude > M_PI_2) { d1.longitude += two_pi; if (c1.longitude < -M_PI_2) c1.longitude += two_pi; if (c2.longitude < -M_PI_2) c2.longitude += two_pi; } bool result = has_overlap(d1.longitude, d2.longitude, c1.longitude, c2.longitude); // if( result ) { ++count.accepted; } else { ++count.rejected; } return result; }
bool is_local(const std::string& name) { return has_overlap(get_local_ips(), get_ips(name)); }