DYT/Tool/OpenSceneGraph-3.6.5/include/osgEarth/Bounds
2024-12-25 07:49:36 +08:00

62 lines
2.0 KiB
C++

/* -*-c++-*- */
/* osgEarth - Geospatial SDK for OpenSceneGraph
* Copyright 2020 Pelican Mapping
* http://osgearth.org
*
* osgEarth is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
#pragma once
#include <osgEarth/Common>
#include <osg/BoundingBox>
namespace osgEarth
{
using Bounds = osg::BoundingBoxd;
inline double width(const Bounds& b) {
return b.xMax() - b.xMin();
}
inline double height(const Bounds& b) {
return b.yMax() - b.yMin();
}
inline double area2d(const Bounds& b) {
return b.valid() ? width(b) * height(b) : -1.0;
}
inline bool contains(const Bounds& b, double x, double y) {
return
b.valid() &&
x >= b.xMin() && x <= b.xMax() &&
y >= b.yMin() && y <= b.yMax();
}
inline bool intersects2d(const Bounds& lhs, const Bounds& rhs) {
return
lhs.xMax() >= rhs.xMin() && lhs.xMin() <= rhs.xMax() &&
lhs.yMax() >= rhs.yMin() && lhs.yMin() <= rhs.yMax();
}
extern OSGEARTH_EXPORT bool contains(const Bounds& lhs, const Bounds& rhs);
extern OSGEARTH_EXPORT Bounds intersectionOf(const Bounds& lhs, const Bounds& rhs);
extern OSGEARTH_EXPORT Bounds unionOf(const Bounds& lhs, const Bounds& rhs);
}