Skip to content

Commit

Permalink
Fix min/max conflicts with microsoft windows C++ api.
Browse files Browse the repository at this point in the history
  • Loading branch information
furby-tm committed Aug 28, 2024
1 parent e1711a2 commit 73fcb0d
Show file tree
Hide file tree
Showing 22 changed files with 53 additions and 53 deletions.
12 changes: 6 additions & 6 deletions Sources/Draco/include/draco/attributes/geometry_attribute.h
Original file line number Diff line number Diff line change
Expand Up @@ -354,8 +354,8 @@ class GeometryAttribute {
// is able to represent. Perform the check only for integral types.
if (!std::is_same<T, bool>::value && std::is_integral<T>::value) {
static constexpr OutT kOutMin =
std::is_signed<T>::value ? std::numeric_limits<OutT>::min() : 0;
if (in_value < kOutMin || in_value > std::numeric_limits<OutT>::max()) {
std::is_signed<T>::value ? (std::numeric_limits<OutT>::min)() : 0;
if (in_value < kOutMin || in_value > (std::numeric_limits<OutT>::max)()) {
return false;
}
}
Expand Down Expand Up @@ -383,8 +383,8 @@ class GeometryAttribute {

// Make sure the floating point |in_value| fits within the range of
// values that integral type OutT is able to represent.
if (in_value < std::numeric_limits<OutT>::min() ||
in_value >= std::numeric_limits<OutT>::max()) {
if (in_value < (std::numeric_limits<OutT>::min)() ||
in_value >= (std::numeric_limits<OutT>::max)()) {
return false;
}
}
Expand All @@ -395,7 +395,7 @@ class GeometryAttribute {
// When converting integer to floating point, normalize the value if
// necessary.
*out_value = static_cast<OutT>(in_value);
*out_value /= static_cast<OutT>(std::numeric_limits<T>::max());
*out_value /= static_cast<OutT>((std::numeric_limits<T>::max)());
} else if (std::is_floating_point<T>::value &&
std::is_integral<OutT>::value && normalized) {
// Converting from floating point to a normalized integer.
Expand All @@ -413,7 +413,7 @@ class GeometryAttribute {
// nearest representable value. Use doubles for the math to ensure the
// integer values are represented properly during the conversion process.
*out_value = static_cast<OutT>(std::floor(
in_value * static_cast<double>(std::numeric_limits<OutT>::max()) +
in_value * static_cast<double>((std::numeric_limits<OutT>::max)()) +
0.5));
} else {
*out_value = static_cast<OutT>(in_value);
Expand Down
10 changes: 5 additions & 5 deletions Sources/Draco/include/draco/attributes/geometry_indices.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ DEFINE_NEW_DRACO_INDEX_TYPE(uint32_t, FaceIndex)

// Constants denoting invalid indices.
static constexpr AttributeValueIndex kInvalidAttributeValueIndex(
std::numeric_limits<uint32_t>::max());
(std::numeric_limits<uint32_t>::max)());
static constexpr PointIndex kInvalidPointIndex(
std::numeric_limits<uint32_t>::max());
(std::numeric_limits<uint32_t>::max)());
static constexpr VertexIndex kInvalidVertexIndex(
std::numeric_limits<uint32_t>::max());
(std::numeric_limits<uint32_t>::max)());
static constexpr CornerIndex kInvalidCornerIndex(
std::numeric_limits<uint32_t>::max());
(std::numeric_limits<uint32_t>::max)());
static constexpr FaceIndex kInvalidFaceIndex(
std::numeric_limits<uint32_t>::max());
(std::numeric_limits<uint32_t>::max)());

// TODO(ostava): Add strongly typed indices for attribute id and unique
// attribute id.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ bool KdTreeAttributesDecoder::TransformAttributeBackToSignedType(
// Up-cast |unsigned_val| to int32_t to ensure we don't overflow it for
// smaller data types. But first check that the up-casting does not cause
// signed integer overflow.
if (unsigned_val[c] > std::numeric_limits<int32_t>::max()) {
if (unsigned_val[c] > (std::numeric_limits<int32_t>::max)()) {
return false;
}
signed_val[c] = static_cast<SignedDataTypeT>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ bool KdTreeAttributesEncoder::TransformAttributesToPortableFormat() {
// values are going to be used to transform the attribute values to
// unsigned integers that can be processed by the core kd tree algorithm.
std::vector<int32_t> min_value(att->num_components(),
std::numeric_limits<int32_t>::max());
(std::numeric_limits<int32_t>::max)());
std::vector<int32_t> act_value(att->num_components());
for (AttributeValueIndex avi(0); avi < static_cast<uint32_t>(att->size());
++avi) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,23 +161,23 @@ bool MeshPredictionSchemeTexCoordsPortablePredictor<
// x_uv = X_UV * PN.Norm2Squared()
//
const int64_t n_uv_absmax_element =
std::max(std::abs(n_uv[0]), std::abs(n_uv[1]));
(std::max)(std::abs(n_uv[0]), std::abs(n_uv[1]));
if (n_uv_absmax_element >
std::numeric_limits<int64_t>::max() / pn_norm2_squared) {
(std::numeric_limits<int64_t>::max)() / pn_norm2_squared) {
// Return false if the below multiplication would overflow.
return false;
}
const int64_t pn_uv_absmax_element =
std::max(std::abs(pn_uv[0]), std::abs(pn_uv[1]));
(std::max)(std::abs(pn_uv[0]), std::abs(pn_uv[1]));
if (cn_dot_pn >
std::numeric_limits<int64_t>::max() / pn_uv_absmax_element) {
(std::numeric_limits<int64_t>::max)() / pn_uv_absmax_element) {
// Return false if squared length calculation would overflow.
return false;
}
const Vec2 x_uv = n_uv * pn_norm2_squared + (cn_dot_pn * pn_uv);
const int64_t pn_absmax_element =
std::max(std::max(std::abs(pn[0]), std::abs(pn[1])), std::abs(pn[2]));
if (cn_dot_pn > std::numeric_limits<int64_t>::max() / pn_absmax_element) {
(std::max)((std::max)(std::abs(pn[0]), std::abs(pn[1])), std::abs(pn[2]));
if (cn_dot_pn > (std::numeric_limits<int64_t>::max)() / pn_absmax_element) {
// Return false if squared length calculation would overflow.
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class PredictionSchemeWrapTransformBase {
bool InitCorrectionBounds() {
const int64_t dif =
static_cast<int64_t>(max_value_) - static_cast<int64_t>(min_value_);
if (dif < 0 || dif >= std::numeric_limits<DataTypeT>::max()) {
if (dif < 0 || dif >= (std::numeric_limits<DataTypeT>::max)()) {
return false;
}
max_dif_ = 1 + static_cast<DataTypeT>(dif);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class EncoderOptionsBase : public DracoOptions<AttributeKeyT> {
int GetSpeed() const {
const int encoding_speed = this->GetGlobalInt("encoding_speed", -1);
const int decoding_speed = this->GetGlobalInt("decoding_speed", -1);
const int max_speed = std::max(encoding_speed, decoding_speed);
const int max_speed = (std::max)(encoding_speed, decoding_speed);
if (max_speed == -1) {
return 5; // Default value.
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ bool EncodeSymbols(const uint32_t *symbols, int num_values, int num_components,
// The maximum bit length of a single entry value that we can encode using
// the raw scheme.
const int max_value_bit_length =
MostSignificantBit(std::max(1u, max_value)) + 1;
MostSignificantBit((std::max)(1u, max_value)) + 1;

int method = -1;
if (options != nullptr && options->IsOptionSet("symbol_encoding_method")) {
Expand Down Expand Up @@ -307,8 +307,8 @@ bool EncodeRawSymbols(const uint32_t *symbols, int num_values,
unique_symbols_bit_length += 1;
}
// Clamp the bit_length to a valid range.
unique_symbols_bit_length = std::min(std::max(1, unique_symbols_bit_length),
kMaxRawEncodingBitLength);
unique_symbols_bit_length = (std::min)((std::max)(1, unique_symbols_bit_length),
kMaxRawEncodingBitLength);
target_buffer->Encode(static_cast<uint8_t>(unique_symbols_bit_length));
// Use appropriate symbol encoder based on the maximum symbol bit length.
switch (unique_symbols_bit_length) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ bool MeshEdgebreakerDecoderImpl<TraversalDecoder>::DecodeConnectivity() {
return false;
}
}
if (num_faces > std::numeric_limits<CornerIndex::ValueType>::max() / 3) {
if (num_faces > (std::numeric_limits<CornerIndex::ValueType>::max)() / 3) {
return false; // Draco cannot handle this many faces.
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ template <int compression_level_t>
template <class OutputIteratorT>
bool DynamicIntegerPointsKdTreeDecoder<compression_level_t>::DecodePoints(
DecoderBuffer *buffer, OutputIteratorT &&oit) {
return DecodePoints(buffer, oit, std::numeric_limits<uint32_t>::max());
return DecodePoints(buffer, oit, (std::numeric_limits<uint32_t>::max)());
}

template <int compression_level_t>
Expand All @@ -176,7 +176,7 @@ template <int compression_level_t>
template <class OutputIteratorT>
bool DynamicIntegerPointsKdTreeDecoder<compression_level_t>::DecodePoints(
DecoderBuffer *buffer, OutputIteratorT &oit) {
return DecodePoints(buffer, oit, std::numeric_limits<uint32_t>::max());
return DecodePoints(buffer, oit, (std::numeric_limits<uint32_t>::max)());
}

template <int compression_level_t>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ DynamicIntegerPointsKdTreeEncoder<compression_level_t>::GetAndEncodeAxis(
for (auto it = begin; it != end; ++it) {
deviations_[i] += ((*it)[i] < split);
}
deviations_[i] = std::max(size - deviations_[i], deviations_[i]);
deviations_[i] = (std::max)(size - deviations_[i], deviations_[i]);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ uint32_t IntegerPointsKdTreeEncoder<PointDiT, compression_level_t>::GetAxis(
}
}
for (int i = 0; i < D; i++) {
deviations[i] = std::max(size - deviations[i], deviations[i]);
deviations[i] = (std::max)(size - deviations[i], deviations[i]);
}

uint32_t max_value = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ OutputIterator QuantizePoints3(const PointIterator &begin,

float max_range = 0;
for (auto it = begin; it != end; ++it) {
max_range = std::max(std::fabs((*it)[0]), max_range);
max_range = std::max(std::fabs((*it)[1]), max_range);
max_range = std::max(std::fabs((*it)[2]), max_range);
max_range = (std::max)(std::fabs((*it)[0]), max_range);
max_range = (std::max)(std::fabs((*it)[1]), max_range);
max_range = (std::max)(std::fabs((*it)[2]), max_range);
}

const uint32_t max_quantized_value((1u << info->quantization_bits) - 1);
Expand Down
12 changes: 6 additions & 6 deletions Sources/Draco/include/draco/core/bounding_box.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
namespace draco {

BoundingBox::BoundingBox()
: BoundingBox(Vector3f(std::numeric_limits<float>::max(),
std::numeric_limits<float>::max(),
std::numeric_limits<float>::max()),
: BoundingBox(Vector3f((std::numeric_limits<float>::max)(),
(std::numeric_limits<float>::max)(),
(std::numeric_limits<float>::max)()),
Vector3f(std::numeric_limits<float>::lowest(),
std::numeric_limits<float>::lowest(),
std::numeric_limits<float>::lowest())) {}
Expand All @@ -28,9 +28,9 @@ BoundingBox::BoundingBox(const Vector3f &min_point, const Vector3f &max_point)
: min_point_(min_point), max_point_(max_point) {}

const bool BoundingBox::IsValid() const {
return GetMinPoint()[0] != std::numeric_limits<float>::max() &&
GetMinPoint()[1] != std::numeric_limits<float>::max() &&
GetMinPoint()[2] != std::numeric_limits<float>::max() &&
return GetMinPoint()[0] != (std::numeric_limits<float>::max)() &&
GetMinPoint()[1] != (std::numeric_limits<float>::max)() &&
GetMinPoint()[2] != (std::numeric_limits<float>::max)() &&
GetMaxPoint()[0] != std::numeric_limits<float>::lowest() &&
GetMaxPoint()[1] != std::numeric_limits<float>::lowest() &&
GetMaxPoint()[2] != std::numeric_limits<float>::lowest();
Expand Down
2 changes: 1 addition & 1 deletion Sources/Draco/include/draco/core/hash_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ uint64_t FingerprintString(const char *s, size_t len) {
hash = HashCombine(new_hash, hash);
}

if (hash < std::numeric_limits<uint64_t>::max() - 1) {
if (hash < (std::numeric_limits<uint64_t>::max)() - 1) {
hash += 2;
}
return hash;
Expand Down
2 changes: 1 addition & 1 deletion Sources/Draco/include/draco/material/material.cc
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ void Material::Clear() {
clearcoat_roughness_factor_ = 0.f;
has_volume_ = false;
thickness_factor_ = 0.f;
attenuation_distance_ = std::numeric_limits<float>::max(); // Infinity.
attenuation_distance_ = (std::numeric_limits<float>::max)(); // Infinity.
attenuation_color_ = Vector3f(1.f, 1.f, 1.f);
has_ior_ = false;
ior_ = 1.5f;
Expand Down
2 changes: 1 addition & 1 deletion Sources/Draco/include/draco/mesh/corner_table.cc
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ bool CornerTable::Reset(int num_faces, int num_vertices) {
}
const unsigned int num_faces_unsigned = num_faces;
if (num_faces_unsigned >
std::numeric_limits<CornerIndex::ValueType>::max() / 3) {
(std::numeric_limits<CornerIndex::ValueType>::max)() / 3) {
return false;
}
corner_to_vertex_map_.assign(num_faces_unsigned * 3, kInvalidVertexIndex);
Expand Down
2 changes: 1 addition & 1 deletion Sources/Draco/include/draco/mesh/mesh_indices.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ DEFINE_NEW_DRACO_INDEX_TYPE(uint32_t, MeshFeaturesIndex)

// Constants denoting invalid indices.
static constexpr MeshFeaturesIndex kInvalidMeshFeaturesIndex(
std::numeric_limits<uint32_t>::max());
(std::numeric_limits<uint32_t>::max)());

} // namespace draco

Expand Down
2 changes: 1 addition & 1 deletion Sources/Draco/include/draco/mesh/valence_cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class ValenceCache {
vertex_valence_cache_8_bit_.resize(vertex_count.value());
for (VertexIndex v = VertexIndex(0); v < vertex_count; v += 1) {
vertex_valence_cache_8_bit_[v] = static_cast<int8_t>(
(std::min)(static_cast<int32_t>(std::numeric_limits<int8_t>::max()),
(std::min)(static_cast<int32_t>((std::numeric_limits<int8_t>::max)()),
table_.Valence(v)));
}
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/Draco/include/draco/point_cloud/point_cloud.cc
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ std::unique_ptr<PointAttribute> PointCloud::CreateAttribute(
pa->SetExplicitMapping(num_points_);
} else {
pa->SetIdentityMapping();
num_attribute_values = std::max(num_points_, num_attribute_values);
num_attribute_values = (std::max)(num_points_, num_attribute_values);
}
if (num_attribute_values > 0) {
pa->Reset(num_attribute_values);
Expand Down
2 changes: 1 addition & 1 deletion Sources/Draco/include/draco/scene/light.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Light::Light()
: color_(1.0f, 1.0f, 1.0f),
intensity_(1.0),
type_(POINT),
range_(std::numeric_limits<float>::max()), // Infinity.
range_((std::numeric_limits<float>::max)()), // Infinity.
inner_cone_angle_(0.0),
outer_cone_angle_(DRACO_PI / 4.0) {}

Expand Down
16 changes: 8 additions & 8 deletions Sources/Draco/include/draco/scene/scene_indices.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,21 @@ DEFINE_NEW_DRACO_INDEX_TYPE(uint32_t, InstanceArrayIndex)

// Constants denoting invalid indices.
static constexpr MeshIndex kInvalidMeshIndex(
std::numeric_limits<uint32_t>::max());
(std::numeric_limits<uint32_t>::max)());
static constexpr MeshInstanceIndex kInvalidMeshInstanceIndex(
std::numeric_limits<uint32_t>::max());
(std::numeric_limits<uint32_t>::max)());
static constexpr MeshGroupIndex kInvalidMeshGroupIndex(
std::numeric_limits<uint32_t>::max());
(std::numeric_limits<uint32_t>::max)());
static constexpr SceneNodeIndex kInvalidSceneNodeIndex(
std::numeric_limits<uint32_t>::max());
(std::numeric_limits<uint32_t>::max)());
static constexpr AnimationIndex kInvalidAnimationIndex(
std::numeric_limits<uint32_t>::max());
(std::numeric_limits<uint32_t>::max)());
static constexpr SkinIndex kInvalidSkinIndex(
std::numeric_limits<uint32_t>::max());
(std::numeric_limits<uint32_t>::max)());
static constexpr LightIndex kInvalidLightIndex(
std::numeric_limits<uint32_t>::max());
(std::numeric_limits<uint32_t>::max)());
static constexpr InstanceArrayIndex kInvalidInstanceArrayIndex(
std::numeric_limits<uint32_t>::max());
(std::numeric_limits<uint32_t>::max)());

} // namespace draco

Expand Down

0 comments on commit 73fcb0d

Please sign in to comment.