Skip to content

Commit

Permalink
Paren-ify max/min for Windows so as not to bleed into people's code that
Browse files Browse the repository at this point in the history
uses ours.
  • Loading branch information
abellgithub committed May 1, 2018
1 parent b4013f1 commit 90bc2cc
Show file tree
Hide file tree
Showing 55 changed files with 176 additions and 170 deletions.
2 changes: 1 addition & 1 deletion examples/writing-reader/MyReader.cpp
Expand Up @@ -62,7 +62,7 @@ namespace pdal
m_stream.reset(new ILeStream(m_filename));

size_t HEADERSIZE(1);
size_t skip_lines(std::max(HEADERSIZE, (size_t)m_index));
size_t skip_lines((std::max)(HEADERSIZE, (size_t)m_index));
size_t line_no(1);
for (std::string line; std::getline(*m_stream->stream(), line); line_no++)
{
Expand Down
4 changes: 2 additions & 2 deletions filters/DecimationFilter.cpp
Expand Up @@ -57,7 +57,7 @@ void DecimationFilter::addArgs(ProgramArgs& args)
args.add("offset", "Index of first point to consider including in output",
m_offset);
args.add("limit", "Index of last point to consider including in output",
m_limit, std::numeric_limits<point_count_t>::max());
m_limit, (std::numeric_limits<point_count_t>::max)());
}

PointViewSet DecimationFilter::run(PointViewPtr inView)
Expand All @@ -84,7 +84,7 @@ bool DecimationFilter::processOne(PointRef& point)

void DecimationFilter::decimate(PointView& input, PointView& output)
{
PointId last_idx = std::min(m_limit, input.size());
PointId last_idx = (std::min)(m_limit, input.size());
for (PointId idx = m_offset; idx < last_idx; idx += m_step)
output.appendPoint(input, idx);
}
Expand Down
2 changes: 1 addition & 1 deletion filters/GreedyProjection.cpp
Expand Up @@ -135,7 +135,7 @@ void GreedyProjection::filter(PointView& view)
const double sqr_mu = mu_ * mu_;
const double sqr_max_edge = search_radius_*search_radius_;

nnn_ = (int)std::min((point_count_t)nnn_, view.size());
nnn_ = (int)(std::min)((point_count_t)nnn_, view.size());

// Variables to hold the results of nearest neighbor searches
std::vector<PointId> nnIdx(nnn_);
Expand Down
2 changes: 1 addition & 1 deletion filters/HeadFilter.hpp
Expand Up @@ -66,7 +66,7 @@ class PDAL_DLL HeadFilter : public Filter
<< ") exceeds number of available points.\n";
PointViewSet viewSet;
PointViewPtr outView = view->makeNew();
for (PointId i = 0; i < std::min(m_count, view->size()); ++i)
for (PointId i = 0; i < (std::min)(m_count, view->size()); ++i)
outView->appendPoint(*view, i);
viewSet.insert(outView);
return viewSet;
Expand Down
2 changes: 1 addition & 1 deletion filters/LOFFilter.cpp
Expand Up @@ -109,7 +109,7 @@ void LOFFilter::filter(PointView& view)
for (PointId j = 0; j < indices.size(); ++j)
{
double k = view.getFieldAs<double>(m_kdist, indices[j]);
double reachdist = std::max(k, std::sqrt(sqr_dists[j]));
double reachdist = (std::max)(k, std::sqrt(sqr_dists[j]));
M1 += (reachdist - M1) / ++n;
}
view.setField(m_lrd, i, 1.0 / M1);
Expand Down
2 changes: 1 addition & 1 deletion filters/LocateFilter.cpp
Expand Up @@ -76,7 +76,7 @@ PointViewSet LocateFilter::run(PointViewPtr inView)
return viewSet;

PointId minidx, maxidx;
double minval = std::numeric_limits<double>::max();
double minval = (std::numeric_limits<double>::max)();
double maxval = std::numeric_limits<double>::lowest();

for (PointId idx = 0; idx < inView->size(); idx++)
Expand Down
10 changes: 5 additions & 5 deletions filters/MongusFilter.cpp
Expand Up @@ -143,7 +143,7 @@ std::vector<PointId> MongusFilter::processGround(PointViewPtr view)
cy.setConstant(std::numeric_limits<double>::quiet_NaN());

MatrixXd cz(m_numRows, m_numCols);
cz.setConstant(std::numeric_limits<double>::max());
cz.setConstant((std::numeric_limits<double>::max)());

// find initial set of Z minimums at native resolution
for (point_count_t i = 0; i < np; ++i)
Expand Down Expand Up @@ -250,7 +250,7 @@ std::vector<PointId> MongusFilter::processGround(PointViewPtr view)

double sum = 0.0;
double maxcoeff = std::numeric_limits<double>::lowest();
double mincoeff = std::numeric_limits<double>::max();
double mincoeff = (std::numeric_limits<double>::max)();
for (auto i = 0; i < R.size(); ++i)
{
if (std::isnan(R(i)))
Expand Down Expand Up @@ -322,7 +322,7 @@ std::vector<PointId> MongusFilter::processGround(PointViewPtr view)

sum = 0.0;
maxcoeff = std::numeric_limits<double>::lowest();
mincoeff = std::numeric_limits<double>::max();
mincoeff = (std::numeric_limits<double>::max)();
for (auto i = 0; i < M.size(); ++i)
{
if (std::isnan(M(i)))
Expand Down Expand Up @@ -477,13 +477,13 @@ void MongusFilter::downsampleMin(Eigen::MatrixXd *cx, Eigen::MatrixXd *cy,
dcy->setConstant(std::numeric_limits<double>::quiet_NaN());

dcz->resize(nr, nc);
dcz->setConstant(std::numeric_limits<double>::max());
dcz->setConstant((std::numeric_limits<double>::max)());

for (auto c = 0; c < cz->cols(); ++c)
{
for (auto r = 0; r < cz->rows(); ++r)
{
if ((*cz)(r, c) == std::numeric_limits<double>::max())
if ((*cz)(r, c) == (std::numeric_limits<double>::max)())
continue;

int rr = std::floor(r/cell_size);
Expand Down
2 changes: 1 addition & 1 deletion filters/SMRFilter.cpp
Expand Up @@ -577,7 +577,7 @@ std::vector<int> SMRFilter::progressiveFilter(std::vector<double> const& ZImin,
return (x > threshold) ? int(1) : int(0);
});
std::transform(Obj.begin(), Obj.end(), foo.begin(), Obj.begin(),
[](int a, int b) { return std::max(a, b); });
[](int a, int b) { return (std::max)(a, b); });

// "The algorithm then proceeds to the next window radius (up to the
// maximum), and proceeds as above with the last opened surface acting
Expand Down
2 changes: 1 addition & 1 deletion filters/TailFilter.hpp
Expand Up @@ -66,7 +66,7 @@ class PDAL_DLL TailFilter : public Filter
<< ") exceeds number of available points.\n";
PointViewSet viewSet;
PointViewPtr outView = view->makeNew();
for (PointId i = view->size() - std::min(m_count, view->size());
for (PointId i = view->size() - (std::min)(m_count, view->size());
i < view->size(); ++i)
outView->appendPoint(*view, i);
viewSet.insert(outView);
Expand Down
4 changes: 2 additions & 2 deletions filters/private/DimRange.cpp
Expand Up @@ -95,7 +95,7 @@ std::string::size_type DimRange::subParse(const std::string& r)
start = r.data() + pos;
ub = std::strtod(start, &end);
if (start == end)
ub = std::numeric_limits<double>::max();
ub = (std::numeric_limits<double>::max)();
pos += (end - start);

count = Utils::extractSpaces(r, pos);
Expand Down Expand Up @@ -159,7 +159,7 @@ std::ostream& operator<<(std::ostream& out, const DimRange& r)
if (r.m_lower_bound != std::numeric_limits<double>::lowest())
out << r.m_lower_bound;
out << ':';
if (r.m_upper_bound != std::numeric_limits<double>::max())
if (r.m_upper_bound != (std::numeric_limits<double>::max)())
out << r.m_upper_bound;
out << (r.m_inclusive_upper_bound ? ']' : ')');
return out;
Expand Down
2 changes: 1 addition & 1 deletion io/BpfHeader.cpp
Expand Up @@ -373,7 +373,7 @@ bool BpfUlemFile::write(OLeStream& stream)
char buf[MAX_BLOCKSIZE];
while (len)
{
uint32_t blocksize = std::min(MAX_BLOCKSIZE, len);
uint32_t blocksize = (std::min)(MAX_BLOCKSIZE, len);
in.read(buf, blocksize);
stream.put(buf, blocksize);
len -= blocksize;
Expand Down
2 changes: 1 addition & 1 deletion io/BpfReader.cpp
Expand Up @@ -563,7 +563,7 @@ point_count_t BpfReader::readByteMajor(PointViewPtr data, point_count_t count)
uint32_t u32;
};
std::unique_ptr<union uu> uArr(
new uu[std::min(count, numPoints() - m_index)]);
new uu[(std::min)(count, numPoints() - m_index)]);

for (size_t d = 0; d < m_dims.size(); ++d)
{
Expand Down
4 changes: 2 additions & 2 deletions io/BpfWriter.cpp
Expand Up @@ -353,8 +353,8 @@ double BpfWriter::getAdjustedValue(const PointView* data,
BpfDimension& bpfDim, PointId idx)
{
double d = data->getFieldAs<double>(bpfDim.m_id, idx);
bpfDim.m_min = std::min(bpfDim.m_min, d);
bpfDim.m_max = std::max(bpfDim.m_max, d);
bpfDim.m_min = (std::min)(bpfDim.m_min, d);
bpfDim.m_max = (std::max)(bpfDim.m_max, d);

if (bpfDim.m_id == Dimension::Id::X)
d /= m_scaling.m_xXform.m_scale.m_val;
Expand Down
36 changes: 18 additions & 18 deletions io/GDALGrid.cpp
Expand Up @@ -48,20 +48,20 @@ GDALGrid::GDALGrid(size_t width, size_t height, double edgeLength,
m_width(width), m_height(height), m_windowSize(windowSize),
m_edgeLength(edgeLength), m_radius(radius), m_outputTypes(outputTypes)
{
if (width > std::numeric_limits<int>::max() ||
height > std::numeric_limits<int>::max())
if (width > (std::numeric_limits<int>::max)() ||
height > (std::numeric_limits<int>::max)())
{
std::ostringstream oss;
oss << "Grid width or height is too large. Width and height are "
"limited to " << std::numeric_limits<int>::max() << " cells."
"limited to " << (std::numeric_limits<int>::max)() << " cells."
"Try setting bounds or increasing resolution.";
throw error(oss.str());
}
size_t size(width * height);

m_count.reset(new DataVec(size));
if (m_outputTypes & statMin)
m_min.reset(new DataVec(size, std::numeric_limits<double>::max()));
m_min.reset(new DataVec(size, (std::numeric_limits<double>::max)()));
if (m_outputTypes & statMax)
m_max.reset(new DataVec(size, std::numeric_limits<double>::lowest()));
if (m_outputTypes & statIdw)
Expand Down Expand Up @@ -119,7 +119,7 @@ void GDALGrid::expand(size_t width, size_t height, size_t xshift, size_t yshift)

moveVec(m_count, 0);
if (m_outputTypes & statMin)
moveVec(m_min, std::numeric_limits<double>::max());
moveVec(m_min, (std::numeric_limits<double>::max)());
if (m_outputTypes & statMax)
moveVec(m_max, std::numeric_limits<double>::lowest());
if (m_outputTypes & statIdw)
Expand Down Expand Up @@ -211,8 +211,8 @@ void GDALGrid::addPoint(double x, double y, double z)
int i, j;
int iStart, jStart;
// First quadrant;
i = iStart = std::max(0, iOrigin + 1);
j = std::min(jOrigin, int(m_height - 1));
i = iStart = (std::max)(0, iOrigin + 1);
j = (std::min)(jOrigin, int(m_height - 1));
while (i < (int)m_width && j >= 0)
{
double d = distance(i, j, x, y);
Expand All @@ -231,8 +231,8 @@ void GDALGrid::addPoint(double x, double y, double z)
}

// Second quadrant;
i = std::min(iOrigin, int(m_width - 1));
j = jStart = std::min(jOrigin - 1, int(m_height - 1));
i = (std::min)(iOrigin, int(m_width - 1));
j = jStart = (std::min)(jOrigin - 1, int(m_height - 1));
while (i >= 0 && j >= 0)
{
double d = distance(i, j, x, y);
Expand All @@ -251,8 +251,8 @@ void GDALGrid::addPoint(double x, double y, double z)
}

// Third quadrant;
i = iStart = std::min(iOrigin - 1, int(m_width - 1));
j = std::max(jOrigin, 0);
i = iStart = (std::min)(iOrigin - 1, int(m_width - 1));
j = (std::max)(jOrigin, 0);
while (i >= 0 && j < (int)m_height)
{
double d = distance(i, j, x, y);
Expand All @@ -270,8 +270,8 @@ void GDALGrid::addPoint(double x, double y, double z)
}
}
// Fourth quadrant;
i = std::max(iOrigin, 0);
j = jStart = std::max(jOrigin + 1, 0);
i = (std::max)(iOrigin, 0);
j = jStart = (std::max)(jOrigin + 1, 0);
while (i < (int)m_width && j < (int)m_height)
{
double d = distance(i, j, x, y);
Expand Down Expand Up @@ -318,13 +318,13 @@ void GDALGrid::update(size_t i, size_t j, double val, double dist)
if (m_min)
{
double& min = (*m_min)[offset];
min = std::min(val, min);
min = (std::min)(val, min);
}

if (m_max)
{
double& max = (*m_max)[offset];
max = std::max(val, max);
max = (std::max)(val, max);
}

if (m_mean)
Expand Down Expand Up @@ -410,9 +410,9 @@ void GDALGrid::fillNodata(size_t i)
void GDALGrid::windowFill(size_t dstI, size_t dstJ)
{
size_t istart = dstI > m_windowSize ? dstI - m_windowSize : (size_t)0;
size_t iend = std::min(width(), dstI + m_windowSize + 1);
size_t iend = (std::min)(width(), dstI + m_windowSize + 1);
size_t jstart = dstJ > m_windowSize ? dstJ - m_windowSize : (size_t)0;
size_t jend = std::min(height(), dstJ + m_windowSize + 1);
size_t jend = (std::min)(height(), dstJ + m_windowSize + 1);

double distSum = 0;
size_t dstIdx = index(dstI, dstJ);
Expand All @@ -432,7 +432,7 @@ void GDALGrid::windowFill(size_t dstI, size_t dstJ)
continue;
// The ternaries just avoid underflow UB. We're just trying to
// find the distance from j to dstJ or i to dstI.
double distance = (double)std::max(j > dstJ ? j - dstJ : dstJ - j,
double distance = (double)(std::max)(j > dstJ ? j - dstJ : dstJ - j,
i > dstI ? i - dstI : dstI - i);
windowFillCell(srcIdx, dstIdx, distance);
distSum += (1 / distance);
Expand Down
2 changes: 1 addition & 1 deletion io/GDALReader.cpp
Expand Up @@ -128,7 +128,7 @@ void GDALReader::ready(PointTableRef table)

point_count_t GDALReader::read(PointViewPtr view, point_count_t num)
{
point_count_t count = std::min(num, m_count - m_index);
point_count_t count = (std::min)(num, m_count - m_index);
PointId nextId = view->size();

std::array<double, 2> coords;
Expand Down
4 changes: 2 additions & 2 deletions io/HeaderVal.hpp
Expand Up @@ -61,7 +61,7 @@ virtual void print(const std::string& s)
};

template <typename T, T MIN = std::numeric_limits<T>::lowest(),
T MAX = std::numeric_limits<T>::max()>
T MAX = (std::numeric_limits<T>::max)()>
class NumHeaderVal : public BaseHeaderVal<T>
{
public:
Expand Down Expand Up @@ -160,7 +160,7 @@ class StringHeaderVal : public BaseHeaderVal<std::string>
m_valSet = true;
m_val = val;
if (LEN > 0)
m_val.resize(std::min(m_val.length(), LEN));
m_val.resize((std::min)(m_val.length(), LEN));
return (LEN == 0 || val.length() <= LEN);
}

Expand Down
2 changes: 1 addition & 1 deletion io/LasHeader.cpp
Expand Up @@ -435,7 +435,7 @@ OLeStream& operator<<(OLeStream& out, const LasHeader& h)

for (size_t i = 0; i < LasHeader::LEGACY_RETURN_COUNT; ++i)
{
uint32_t legacyReturnCount = std::min(h.m_pointCountByReturn[i],
uint32_t legacyReturnCount = (std::min)(h.m_pointCountByReturn[i],
(uint64_t)(std::numeric_limits<uint32_t>::max)());
out << legacyReturnCount;
}
Expand Down
9 changes: 4 additions & 5 deletions io/LasReader.cpp
Expand Up @@ -115,7 +115,7 @@ QuickInfo LasReader::inspect()
for (auto di = dims.begin(); di != dims.end(); ++di)
qi.m_dimNames.push_back(layout->dimName(*di));
if (!Utils::numericCast(m_header.pointCount(), qi.m_pointCount))
qi.m_pointCount = std::numeric_limits<point_count_t>::max();
qi.m_pointCount = (std::numeric_limits<point_count_t>::max)();
qi.m_bounds = m_header.getBounds();
qi.m_srs = getSpatialReference();
qi.m_valid = true;
Expand Down Expand Up @@ -619,7 +619,7 @@ bool LasReader::processOne(PointRef& point)
point_count_t LasReader::read(PointViewPtr view, point_count_t count)
{
size_t pointLen = m_header.pointLen();
count = std::min(count, getNumPoints() - m_index);
count = (std::min)(count, getNumPoints() - m_index);

PointId i = 0;
if (m_header.compressed())
Expand All @@ -646,8 +646,7 @@ point_count_t LasReader::read(PointViewPtr view, point_count_t count)
point_count_t remaining = count;

// Make a buffer at most a meg.
size_t bufsize = std::min<size_t>((point_count_t)1000000,
count * pointLen);
size_t bufsize = (std::min)((point_count_t)1000000, count * pointLen);
std::vector<char> buf(bufsize);
try
{
Expand Down Expand Up @@ -686,7 +685,7 @@ point_count_t LasReader::readFileBlock(std::vector<char>& buf,
size_t ptLen = m_header.pointLen();
point_count_t blockpoints = buf.size() / ptLen;

blockpoints = std::min(maxpoints, blockpoints);
blockpoints = (std::min)(maxpoints, blockpoints);
if (stream->eof())
throw invalid_stream("stream is done");

Expand Down
4 changes: 2 additions & 2 deletions io/LasWriter.cpp
Expand Up @@ -836,7 +836,7 @@ void LasWriter::writeView(const PointViewPtr view)
else
{
// Make a buffer of at most a meg.
m_pointBuf.resize(std::min((point_count_t)1000000,
m_pointBuf.resize((std::min)((point_count_t)1000000,
pointLen * view->size()));

const PointView& viewRef(*view.get());
Expand Down Expand Up @@ -1125,7 +1125,7 @@ point_count_t LasWriter::fillWriteBuf(const PointView& view,
PointId startId, std::vector<char>& buf)
{
point_count_t blocksize = buf.size() / m_lasHeader.pointLen();
blocksize = std::min(blocksize, view.size() - startId);
blocksize = (std::min)(blocksize, view.size() - startId);
PointId lastId = startId + blocksize;

LeInserter ostream(buf.data(), buf.size());
Expand Down
2 changes: 1 addition & 1 deletion io/LasWriter.hpp
Expand Up @@ -111,7 +111,7 @@ class PDAL_DLL LasWriter : public FlexWriter, public Streamable
NumHeaderVal<uint8_t, 1, 1> m_majorVersion;
NumHeaderVal<uint8_t, 1, 4> m_minorVersion;
NumHeaderVal<uint8_t, 0, 10> m_dataformatId;
// MSVC doesn't see numeric_limits::max() as constexpr do doesn't allow
// MSVC doesn't see numeric_limits::max() as constexpr so doesn't allow
// it as defaults for templates. Remove when possible.
NumHeaderVal<uint16_t, 0, 65535> m_filesourceId;
NumHeaderVal<uint16_t, 0, 31> m_globalEncoding;
Expand Down
4 changes: 2 additions & 2 deletions io/OptechReader.cpp
Expand Up @@ -239,8 +239,8 @@ point_count_t OptechReader::read(PointViewPtr data,

size_t OptechReader::fillBuffer()
{
size_t numRecords = std::min<size_t>(m_header.numRecords - m_recordIndex,
MaxNumRecordsInBuffer);
size_t numRecords = (std::min)(m_header.numRecords - m_recordIndex,
MaxNumRecordsInBuffer);

buffer_size_t bufferSize = NumBytesInRecord * numRecords;
m_buffer.resize(bufferSize);
Expand Down

0 comments on commit 90bc2cc

Please sign in to comment.