Commit a9066f58 authored by Paul Ramsey's avatar Paul Ramsey

Use std::array instead of std::vector in TopologyLocation.cpp

parent b0bff6d0
Pipeline #82112610 failed with stage
in 1 minute and 28 seconds
......@@ -11,6 +11,7 @@ Changes in 3.6.4
- Invalid union result from valid polygon inputs (#838)
- Static library does not contain C API (#878)
- Prevent crash when querying empty STRtree (#730)
- Overlay performance improvement (Paul Ramsey)
Changes in 3.6.3
......
......@@ -25,6 +25,7 @@
#include <geos/inline.h>
#include <vector>
#include <array>
#include <string>
#ifdef _MSC_VER
......@@ -65,8 +66,6 @@ public:
~TopologyLocation();
TopologyLocation(const std::vector<int> &newLocation);
/** \brief
* Constructs a TopologyLocation specifying how points on, to the
* left of, and to the right of some GraphComponent relate to some
......@@ -115,7 +114,7 @@ public:
void setLocation(int locValue);
/// Warning: returns reference to owned memory
const std::vector<int> &getLocations() const;
const std::array<int, 3>& getLocations() const;
void setLocations(int on, int left, int right);
......@@ -131,7 +130,8 @@ public:
private:
std::vector<int> location;
std::array<int, 3> location;
std::size_t locationSize;
};
std::ostream& operator<< (std::ostream&, const TopologyLocation&);
......
......@@ -26,17 +26,11 @@
#include <iostream>
#include <cassert>
using namespace std;
using namespace geos::geom;
namespace geos {
namespace geomgraph { // geos.geomgraph
/*public*/
TopologyLocation::TopologyLocation(const vector<int> &newLocation):
location(newLocation.size(), Location::UNDEF)
{
}
/*public*/
TopologyLocation::TopologyLocation()
......@@ -50,7 +44,7 @@ TopologyLocation::~TopologyLocation()
/*public*/
TopologyLocation::TopologyLocation(int on, int left, int right):
location(3)
locationSize(3)
{
location[Position::ON]=on;
location[Position::LEFT]=left;
......@@ -59,15 +53,17 @@ TopologyLocation::TopologyLocation(int on, int left, int right):
/*public*/
TopologyLocation::TopologyLocation(int on):
location(1, on)
locationSize(1)
{
//(*location)[Position::ON]=on;
location.fill(Location::UNDEF);
location[Position::ON] = on;
}
/*public*/
TopologyLocation::TopologyLocation(const TopologyLocation &gl)
:
location(gl.location)
location(gl.location),
locationSize(gl.locationSize)
{
}
......@@ -76,6 +72,7 @@ TopologyLocation&
TopologyLocation::operator= (const TopologyLocation &gl)
{
location = gl.location;
locationSize = gl.locationSize;
return *this;
}
......@@ -84,7 +81,7 @@ int
TopologyLocation::get(size_t posIndex) const
{
// should be an assert() instead ?
if (posIndex<location.size()) return location[posIndex];
if (posIndex<locationSize) return location[posIndex];
return Location::UNDEF;
}
......@@ -92,7 +89,7 @@ TopologyLocation::get(size_t posIndex) const
bool
TopologyLocation::isNull() const
{
for (size_t i=0, sz=location.size(); i<sz; ++i) {
for (size_t i=0; i<locationSize; ++i) {
if (location[i]!=Location::UNDEF) return false;
}
return true;
......@@ -102,7 +99,7 @@ TopologyLocation::isNull() const
bool
TopologyLocation::isAnyNull() const
{
for (size_t i=0, sz=location.size(); i<sz; ++i) {
for (size_t i=0; i<locationSize; ++i) {
if (location[i]==Location::UNDEF) return true;
}
return false;
......@@ -119,21 +116,21 @@ TopologyLocation::isEqualOnSide(const TopologyLocation &le, int locIndex) const
bool
TopologyLocation::isArea() const
{
return location.size()>1;
return locationSize>1;
}
/*public*/
bool
TopologyLocation::isLine() const
{
return location.size()==1;
return locationSize==1;
}
/*public*/
void
TopologyLocation::flip()
{
if (location.size()<=1) return;
if (locationSize<=1) return;
int temp=location[Position::LEFT];
location[Position::LEFT]=location[Position::RIGHT];
location[Position::RIGHT] = temp;
......@@ -143,16 +140,14 @@ TopologyLocation::flip()
void
TopologyLocation::setAllLocations(int locValue)
{
for (size_t i=0, sz=location.size(); i<sz; ++i) {
location[i]=locValue;
}
location.fill(locValue);
}
/*public*/
void
TopologyLocation::setAllLocationsIfNull(int locValue)
{
for (size_t i=0, sz=location.size(); i<sz; ++i) {
for (size_t i=0; i<locationSize; ++i) {
if (location[i]==Location::UNDEF) location[i]=locValue;
}
}
......@@ -172,7 +167,7 @@ TopologyLocation::setLocation(int locValue)
}
/*public*/
const vector<int> &
const std::array<int, 3>&
TopologyLocation::getLocations() const
{
return location;
......@@ -182,7 +177,7 @@ TopologyLocation::getLocations() const
void
TopologyLocation::setLocations(int on, int left, int right)
{
assert(location.size() >= 3);
assert(locationSize >= 3);
location[Position::ON]=on;
location[Position::LEFT]=left;
location[Position::RIGHT]=right;
......@@ -192,7 +187,7 @@ TopologyLocation::setLocations(int on, int left, int right)
bool
TopologyLocation::allPositionsEqual(int loc) const
{
for (size_t i=0, sz=location.size(); i<sz; ++i) {
for (size_t i=0; i<locationSize; ++i) {
if (location[i]!=loc) return false;
}
return true;
......@@ -203,32 +198,32 @@ void
TopologyLocation::merge(const TopologyLocation &gl)
{
// if the src is an Area label & and the dest is not, increase the dest to be an Area
size_t sz=location.size();
size_t glsz=gl.location.size();
size_t sz=locationSize;
size_t glsz=gl.locationSize;
if (glsz>sz) {
location.resize(3);
locationSize = 3;
location[Position::LEFT]=Location::UNDEF;
location[Position::RIGHT]=Location::UNDEF;
}
for (size_t i=0; i<sz; ++i) {
for (size_t i=0; i<locationSize; ++i) {
if (location[i]==Location::UNDEF && i<glsz)
location[i]=gl.location[i];
}
}
string
std::string
TopologyLocation::toString() const
{
stringstream ss;
std::stringstream ss;
ss << *this;
return ss.str();
}
std::ostream& operator<< (std::ostream& os, const TopologyLocation& tl)
{
if (tl.location.size()>1) os << Location::toLocationSymbol(tl.location[Position::LEFT]);
if (tl.locationSize>1) os << Location::toLocationSymbol(tl.location[Position::LEFT]);
os << Location::toLocationSymbol(tl.location[Position::ON]);
if (tl.location.size()>1) os << Location::toLocationSymbol(tl.location[Position::RIGHT]);
if (tl.locationSize>1) os << Location::toLocationSymbol(tl.location[Position::RIGHT]);
return os;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment