Skip to content

Commit

Permalink
Format
Browse files Browse the repository at this point in the history
  • Loading branch information
azrogers committed Feb 3, 2025
1 parent e55a7d8 commit 02347aa
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 95 deletions.
35 changes: 23 additions & 12 deletions CesiumGltf/include/CesiumGltf/PropertyArrayView.h
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,9 @@ template <> class PropertyArrayView<PropertyEnumValue> {
/**
* @brief The underlying component type of this enum value.
*/
PropertyComponentType componentType() const noexcept { return _enumValueType; }
PropertyComponentType componentType() const noexcept {
return _enumValueType;
}

/** @copydoc PropertyArrayView::begin */
auto begin() { return this->_values.begin(); }
Expand Down Expand Up @@ -398,15 +400,18 @@ template <> class PropertyArrayCopy<PropertyEnumValue> {
*/
PropertyArrayCopy() : _storage{}, _view() {}

PropertyArrayCopy(const std::vector<std::byte>& values, PropertyComponentType componentType, int64_t size) {
const size_t sizeInBytes = static_cast<size_t>(size) * getSizeOfComponentType(componentType);
PropertyArrayCopy(
const std::vector<std::byte>& values,
PropertyComponentType componentType,
int64_t size) {
const size_t sizeInBytes =
static_cast<size_t>(size) * getSizeOfComponentType(componentType);
this->_storage.resize(sizeInBytes);
std::memcpy(
this->_storage.data(),
values.data(),
sizeInBytes
);
this->_view = PropertyArrayView<PropertyEnumValue>(this->_storage, componentType, size);
std::memcpy(this->_storage.data(), values.data(), sizeInBytes);
this->_view = PropertyArrayView<PropertyEnumValue>(
this->_storage,
componentType,
size);
}

/** @brief Default move constructor */
Expand All @@ -416,12 +421,16 @@ template <> class PropertyArrayCopy<PropertyEnumValue> {

/** @brief Copy constructor */
PropertyArrayCopy(const PropertyArrayCopy& rhs)
: _storage(rhs._storage), _view(this->_storage, rhs._view.componentType(), rhs._view.size()) {}
: _storage(rhs._storage),
_view(this->_storage, rhs._view.componentType(), rhs._view.size()) {}

/** @brief Copy assignment operator */
PropertyArrayCopy& operator=(const PropertyArrayCopy& rhs) {
this->_storage = rhs._storage;
this->_view = PropertyArrayView<PropertyEnumValue>(this->_storage, rhs._view.componentType(), rhs._view.size());
this->_view = PropertyArrayView<PropertyEnumValue>(
this->_storage,
rhs._view.componentType(),
rhs._view.size());
return *this;
}

Expand Down Expand Up @@ -450,7 +459,9 @@ template <> class PropertyArrayCopy<PropertyEnumValue> {
/**
* @brief Obtains a \ref PropertyArrayView over the contents of this copy.
*/
const PropertyArrayView<PropertyEnumValue>& view() const { return this->_view; }
const PropertyArrayView<PropertyEnumValue>& view() const {
return this->_view;
}

/**
* @brief Obtains a buffer and view from the copied data, leaving this \ref
Expand Down
3 changes: 1 addition & 2 deletions CesiumGltf/include/CesiumGltf/PropertyTablePropertyView.h
Original file line number Diff line number Diff line change
Expand Up @@ -396,8 +396,7 @@ class PropertyTablePropertyView<ElementType, false>
return transformArray(value, this->offset(), this->scale());
} else if constexpr (IsMetadataEnumArray<ElementType>::value) {
return propertyValueViewToCopy(value);
}
else {
} else {
return value;
}
}
Expand Down
23 changes: 16 additions & 7 deletions CesiumGltf/include/CesiumGltf/PropertyTexturePropertyView.h
Original file line number Diff line number Diff line change
Expand Up @@ -650,8 +650,7 @@ class PropertyTexturePropertyView<PropertyEnumValue>
* @return The value of the element, or std::nullopt if it matches the "no
* data" value
*/
std::optional<PropertyEnumValue>
get(double u, double v) const noexcept {
std::optional<PropertyEnumValue> get(double u, double v) const noexcept {
if (this->_status ==
PropertyTexturePropertyViewStatus::EmptyPropertyWithDefault) {
return this->defaultValue();
Expand Down Expand Up @@ -725,7 +724,8 @@ class PropertyTexturePropertyView<PropertyEnumValue>
*/
template <>
class PropertyTexturePropertyView<PropertyArrayView<PropertyEnumValue>>
: public PropertyView<PropertyArrayView<PropertyEnumValue>>, public TextureView {
: public PropertyView<PropertyArrayView<PropertyEnumValue>>,
public TextureView {
public:
/**
* @brief Constructs an invalid instance for a non-existent property.
Expand Down Expand Up @@ -798,7 +798,9 @@ class PropertyTexturePropertyView<PropertyArrayView<PropertyEnumValue>>
const Sampler& sampler,
const ImageAsset& image,
const TextureViewOptions& options = TextureViewOptions()) noexcept
: PropertyView<PropertyArrayView<PropertyEnumValue>>(classProperty, pEnumDefinition),
: PropertyView<PropertyArrayView<PropertyEnumValue>>(
classProperty,
pEnumDefinition),
TextureView(
sampler,
image,
Expand Down Expand Up @@ -915,9 +917,16 @@ class PropertyTexturePropertyView<PropertyArrayView<PropertyEnumValue>>
this->sampleNearestPixel(u, v, this->_channels);
std::vector<std::byte> byteSample;
byteSample.resize(sample.size());
std::memcpy(byteSample.data(), reinterpret_cast<const std::byte*>(sample.data()), sample.size());

return PropertyArrayCopy<PropertyEnumValue>(byteSample, this->_componentType, static_cast<int64_t>(this->_channels.size())); }
std::memcpy(
byteSample.data(),
reinterpret_cast<const std::byte*>(sample.data()),
sample.size());

return PropertyArrayCopy<PropertyEnumValue>(
byteSample,
this->_componentType,
static_cast<int64_t>(this->_channels.size()));
}

/**
* @brief Gets the channels of this property texture property.
Expand Down
21 changes: 14 additions & 7 deletions CesiumGltf/include/CesiumGltf/PropertyTextureView.h
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,10 @@ class PropertyTextureView {
}

if constexpr (IsMetadataEnumArray<T>::value) {
return createEnumArrayPropertyView(classProperty, propertyTextureProperty, propertyOptions);
return createEnumArrayPropertyView(
classProperty,
propertyTextureProperty,
propertyOptions);
}

if constexpr (IsMetadataArray<T>::value) {
Expand Down Expand Up @@ -761,14 +764,14 @@ class PropertyTextureView {
}

const int64_t count = classProperty.count.value_or(0);
if(count <= 0 || count > 4) {
if (count <= 0 || count > 4) {
return PropertyTexturePropertyView<PropertyArrayView<PropertyEnumValue>>(
PropertyTexturePropertyViewStatus::ErrorUnsupportedProperty);
}

const size_t arraySize = static_cast<size_t>(count) * componentSize;

if(arraySize > 4) {
if (arraySize > 4) {
return PropertyTexturePropertyView<PropertyArrayView<PropertyEnumValue>>(
PropertyTexturePropertyViewStatus::ErrorUnsupportedProperty);
}
Expand All @@ -780,17 +783,20 @@ class PropertyTextureView {
getTextureSafe(propertyTextureProperty.index, samplerIndex, imageIndex);

if (status != PropertyTexturePropertyViewStatus::Valid) {
return PropertyTexturePropertyView<PropertyArrayView<PropertyEnumValue>>(status);
return PropertyTexturePropertyView<PropertyArrayView<PropertyEnumValue>>(
status);
}

status = checkSampler(samplerIndex);
if (status != PropertyTexturePropertyViewStatus::Valid) {
return PropertyTexturePropertyView<PropertyArrayView<PropertyEnumValue>>(status);
return PropertyTexturePropertyView<PropertyArrayView<PropertyEnumValue>>(
status);
}

status = checkImage(imageIndex);
if (status != PropertyTexturePropertyViewStatus::Valid) {
return PropertyTexturePropertyView<PropertyArrayView<PropertyEnumValue>>(status);
return PropertyTexturePropertyView<PropertyArrayView<PropertyEnumValue>>(
status);
}

const CesiumUtility::IntrusivePointer<ImageAsset>& pImage =
Expand All @@ -799,7 +805,8 @@ class PropertyTextureView {

status = checkChannels(channels, *pImage);
if (status != PropertyTexturePropertyViewStatus::Valid) {
return PropertyTexturePropertyView<PropertyArrayView<PropertyEnumValue>>(status);
return PropertyTexturePropertyView<PropertyArrayView<PropertyEnumValue>>(
status);
}

if (channels.size() * static_cast<size_t>(pImage->bytesPerChannel) !=
Expand Down
24 changes: 14 additions & 10 deletions CesiumGltf/include/CesiumGltf/PropertyTypeTraits.h
Original file line number Diff line number Diff line change
Expand Up @@ -588,8 +588,9 @@ struct TypeToNormalizedType<PropertyArrayView<glm::mat<N, N, T, Q>>> {
* @brief Transforms a property value type from a view to an equivalent type
* that owns the data it is viewing. For most property types this is an identity
* transformation, because most property types are held by value. However, it
* transforms numeric and enum `PropertyArrayView<T>` to `PropertyArrayCopy<T>` because a
* `PropertyArrayView<T>` only has a pointer to the value it is viewing.
* transforms numeric and enum `PropertyArrayView<T>` to `PropertyArrayCopy<T>`
* because a `PropertyArrayView<T>` only has a pointer to the value it is
* viewing.
*
* See `propertyValueViewToCopy`.
*
Expand Down Expand Up @@ -631,15 +632,15 @@ using PropertyValueCopyToView = std::conditional_t<
template <typename T>
static std::optional<PropertyValueViewToCopy<T>>
propertyValueViewToCopy(const std::optional<T>& view) {
if constexpr (IsMetadataNumericArray<T>::value || IsMetadataEnumArray<T>::value) {
if constexpr (
IsMetadataNumericArray<T>::value || IsMetadataEnumArray<T>::value) {
if (view) {
if constexpr (IsMetadataEnumArray<T>::value) {
return std::make_optional<PropertyArrayCopy<PropertyEnumValue>>(
std::vector(view->begin(), view->end()),
view->componentType(),
view->size());
}
else {
std::vector(view->begin(), view->end()),
view->componentType(),
view->size());
} else {
return std::make_optional<PropertyValueViewToCopy<T>>(
std::vector(view->begin(), view->end()));
}
Expand All @@ -664,8 +665,11 @@ static PropertyValueViewToCopy<T> propertyValueViewToCopy(const T& view) {
if constexpr (IsMetadataNumericArray<T>::value) {
return PropertyValueViewToCopy<T>(std::vector(view.begin(), view.end()));
} else if constexpr (IsMetadataEnumArray<T>::value) {
return PropertyValueViewToCopy<T>(std::vector(view.begin(), view.end()), view.componentType(), view.size());
}else {
return PropertyValueViewToCopy<T>(
std::vector(view.begin(), view.end()),
view.componentType(),
view.size());
} else {
return view;
}
}
Expand Down
21 changes: 8 additions & 13 deletions CesiumGltf/test/TestPropertyTexturePropertyView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,8 @@ void checkEnumTextureValues(
const CesiumGltf::Enum& enumDef,
const std::optional<JsonValue>& noData = std::nullopt,
const std::optional<JsonValue>& defaultValue = std::nullopt,
const std::optional<std::vector<std::optional<int64_t>>>& expectedTransformed = std::nullopt) {
const std::optional<std::vector<std::optional<int64_t>>>&
expectedTransformed = std::nullopt) {
PropertyTextureProperty property;
ClassProperty classProperty;
classProperty.type = ClassProperty::Type::ENUM;
Expand Down Expand Up @@ -598,10 +599,10 @@ void checkEnumTextureValues(
for (size_t i = 0; i < texCoords.size(); i++) {
glm::dvec2 uv = texCoords[i];
REQUIRE(view.getRaw(uv[0], uv[1]).value() == expected[i]);
if(expectedTransformed && (*expectedTransformed)[i]) {
REQUIRE(view.get(uv[0], uv[1]).value() == (*expectedTransformed)[i].value());
}
else if (expectedTransformed) {
if (expectedTransformed && (*expectedTransformed)[i]) {
REQUIRE(
view.get(uv[0], uv[1]).value() == (*expectedTransformed)[i].value());
} else if (expectedTransformed) {
REQUIRE(view.get(uv[0], uv[1]) == std::nullopt);
}
}
Expand Down Expand Up @@ -2299,14 +2300,8 @@ TEST_CASE("Check enum PropertyTexturePropertyView") {
SUBCASE("uint8_t with noData and defaultValue") {
enumDef.valueType = Enum::ValueType::UINT8;
std::vector<uint8_t> data{11, 28, 0xff, 233, 0xff, 77, 43};
std::vector<std::optional<int64_t>> expected{
data[0],
data[1],
0,
data[3],
0,
data[5],
data[6]};
std::vector<std::optional<int64_t>>
expected{data[0], data[1], 0, data[3], 0, data[5], data[6]};
std::vector<int64_t> expectedRaw(data.begin(), data.end());
checkEnumTextureValues(
data,
Expand Down
Loading

0 comments on commit 02347aa

Please sign in to comment.