File Envelope.h
File List > src > Envelope.h
Go to the documentation of this file
// Copyright (c) 2012-2013, IGN France.
// Copyright (c) 2012-2022, Oslandia.
// SPDX-License-Identifier: LGPL-2.0-or-later
#ifndef _SFCGAL_ENVELOPE_H_
#define _SFCGAL_ENVELOPE_H_
#include <boost/assert.hpp>
#include <memory>
#include <CGAL/Bbox_2.h>
#include <CGAL/Bbox_3.h>
#include "SFCGAL/config.h"
#include "SFCGAL/Coordinate.h"
#include "SFCGAL/detail/Interval.h"
namespace SFCGAL {
class LineString;
class Polygon;
class Solid;
class PolyhedralSurface;
class SFCGAL_API Envelope {
public:
Envelope();
Envelope(const double &xmin, const double &xmax, const double &ymin,
const double &ymax);
Envelope(const double &xmin, const double &xmax, const double &ymin,
const double &ymax, const double &zmin, const double &zmax);
Envelope(const Coordinate &p);
Envelope(const Coordinate &p1, const Coordinate &p2);
Envelope(const Envelope &other);
Envelope &
operator=(const Envelope &other);
~Envelope();
bool
isEmpty() const;
bool
is3D() const;
void
expandToInclude(const Coordinate &coordinate);
inline const double &
xMin() const
{
return _bounds[0].lower();
}
inline const double &
yMin() const
{
return _bounds[1].lower();
}
inline const double &
zMin() const
{
return _bounds[2].lower();
}
inline const double &
xMax() const
{
return _bounds[0].upper();
}
inline const double &
yMax() const
{
return _bounds[1].upper();
}
inline const double &
zMax() const
{
return _bounds[2].upper();
}
inline detail::Interval &
boundsN(const size_t &n)
{
BOOST_ASSERT(n < 3);
return _bounds[n];
}
inline const detail::Interval &
boundsN(const size_t &n) const
{
BOOST_ASSERT(n < 3);
return _bounds[n];
}
inline CGAL::Bbox_2
toBbox_2() const
{
BOOST_ASSERT(!isEmpty());
return CGAL::Bbox_2(_bounds[0].lower(), _bounds[1].lower(),
_bounds[0].upper(), _bounds[1].upper());
}
inline CGAL::Bbox_3
toBbox_3() const
{
if (is3D()) {
return CGAL::Bbox_3(_bounds[0].lower(), _bounds[1].lower(),
_bounds[2].lower(), _bounds[0].upper(),
_bounds[1].upper(), _bounds[2].upper());
}
return CGAL::Bbox_3(_bounds[0].lower(), _bounds[1].lower(), 0.0,
_bounds[0].upper(), _bounds[1].upper(), 0.0);
}
static bool
contains(const Envelope &a, const Envelope &b);
static bool
overlaps(const Envelope &a, const Envelope &b);
//-- helpers
std::unique_ptr<LineString>
toRing() const;
std::unique_ptr<Polygon>
toPolygon() const;
std::unique_ptr<PolyhedralSurface>
toShell() const;
std::unique_ptr<Solid>
toSolid() const;
/*
* Display method
*/
std::ostream &
print(std::ostream &) const;
private:
detail::Interval _bounds[3];
};
SFCGAL_API bool
operator==(const Envelope &, const Envelope &);
} // namespace SFCGAL
#endif