operation/intersection/Rectangle.h
/**********************************************************************
*
* GEOS - Geometry Engine Open Source
* http://geos.osgeo.org
*
* Copyright (C) 2014 Mika Heiskanen <mika.heiskanen@fmi.fi>
*
* This is free software; you can redistribute and/or modify it under
* the terms of the GNU Lesser General Public Licence as published
* by the Free Software Foundation.
* See the COPYING file for more information.
*
**********************************************************************/
#pragma once
#include <geos/export.h>
#include <memory>
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
#endif
// Forward declarations
namespace geos {
namespace geom {
class GeometryFactory;
class Geometry;
class Polygon;
class LinearRing;
}
}
namespace geos {
namespace operation { // geos::operation
namespace intersection { // geos::operation::intersection
class GEOS_DLL Rectangle {
public:
Rectangle(double x1, double y1, double x2, double y2);
double
xmin() const
{
return xMin;
}
double
ymin() const
{
return yMin;
}
double
xmax() const
{
return xMax;
}
double
ymax() const
{
return yMax;
}
std::unique_ptr<geom::Polygon> toPolygon(const geom::GeometryFactory& f) const;
std::unique_ptr<geom::LinearRing> toLinearRing(const geom::GeometryFactory& f) const;
enum Position {
Inside = 1,
Outside = 2,
Left = 4,
Top = 8,
Right = 16,
Bottom = 32,
TopLeft = Top | Left, // 12
TopRight = Top | Right, // 24
BottomLeft = Bottom | Left, // 36
BottomRight = Bottom | Right // 48
};
static bool
onEdge(Position pos)
{
return (pos > Outside);
}
static bool
onSameEdge(Position pos1, Position pos2)
{
return onEdge(Position(pos1 & pos2));
}
Position
position(double x, double y) const
{
// We assume the point to be inside and test it first
if(x > xMin && x < xMax && y > yMin && y < yMax) {
return Inside;
}
// Next we assume the point to be outside and test it next
if(x < xMin || x > xMax || y < yMin || y > yMax) {
return Outside;
}
// Slower cases
unsigned int pos = 0;
if(x == xMin) {
pos |= Left;
}
else if(x == xMax) {
pos |= Right;
}
if(y == yMin) {
pos |= Bottom;
}
else if(y == yMax) {
pos |= Top;
}
return Position(pos);
}
static Position
nextEdge(Position pos)
{
switch(pos) {
case BottomLeft:
case Left:
return Top;
case TopLeft:
case Top:
return Right;
case TopRight:
case Right:
return Bottom;
case BottomRight:
case Bottom:
return Left;
/* silences compiler warnings, Inside & Outside are not handled explicitly */
default:
return pos;
}
}
private:
Rectangle();
double xMin;
double yMin;
double xMax;
double yMax;
}; // class RectangleIntersection
} // namespace geos::operation::intersection
} // namespace geos::operation
} // namespace geos
geos::geom::GeometryFactory
Supplies a set of utility methods for building Geometry objects from CoordinateSequence or other Geom...
Definition GeometryFactory.h:70
geos::geom::Geometry
Basic implementation of Geometry, constructed and destructed by GeometryFactory.
Definition Geometry.h:196
geos::geom::LinearRing
Models an OGC SFS LinearRing. A LinearRing is a LineString which is both closed and simple.
Definition LinearRing.h:54
geos::geom::Polygon
Represents a linear polygon, which may include holes.
Definition Polygon.h:61
geos::operation::intersection::Rectangle
Clipping rectangle.
Definition operation/intersection/Rectangle.h:51
geos::operation::intersection::Rectangle::xmax
double xmax() const
Definition operation/intersection/Rectangle.h:91
geos::operation::intersection::Rectangle::Rectangle
Rectangle(double x1, double y1, double x2, double y2)
Construct a clipping rectangle.
geos::operation::intersection::Rectangle::nextEdge
static Position nextEdge(Position pos)
Next edge in clock-wise direction.
Definition operation/intersection/Rectangle.h:202
geos::operation::intersection::Rectangle::toPolygon
std::unique_ptr< geom::Polygon > toPolygon(const geom::GeometryFactory &f) const
geos::operation::intersection::Rectangle::onEdge
static bool onEdge(Position pos)
Test if the given position is on a Rectangle edge.
Definition operation/intersection/Rectangle.h:142
geos::operation::intersection::Rectangle::position
Position position(double x, double y) const
Establish position of coordinate with respect to a Rectangle.
Definition operation/intersection/Rectangle.h:168
geos::operation::intersection::Rectangle::onSameEdge
static bool onSameEdge(Position pos1, Position pos2)
Test if the given positions are on the same Rectangle edge.
Definition operation/intersection/Rectangle.h:155
geos::operation::intersection::Rectangle::xmin
double xmin() const
Definition operation/intersection/Rectangle.h:70
geos::operation::intersection::Rectangle::ymin
double ymin() const
Definition operation/intersection/Rectangle.h:80
geos::operation::intersection::Rectangle::ymax
double ymax() const
Definition operation/intersection/Rectangle.h:102
geos::operation::intersection::Rectangle::Position
Position
Position with respect to a clipping rectangle.
Definition operation/intersection/Rectangle.h:120
geos::geom
Definition Angle.h:26
geos::operation::intersection
Provides classes for computing the intersection of a Geometry and a clipping Rectangle.
Definition namespaces.h:189
geos::operation
Provides classes for implementing operations on geometries.
Definition CleanCoverage.h:34
geos
Basic namespace for all GEOS functionalities.
Definition geos.h:38