internal void ValidateBounds(Validation.ValidationContext result) { if (_min.Count == 0 && _max.Count == 0) { return; } var dimensions = this.Dimensions.DimCount(); if (_min.Count != dimensions) { result.AddError(this, $"min bounds length mismatch; expected {dimensions} but found {_min.Count}"); return; } if (_max.Count != dimensions) { result.AddError(this, $"max bounds length mismatch; expected {dimensions} but found {_max.Count}"); return; } for (int i = 0; i < _min.Count; ++i) { if (_min[i] > _max[i]) { result.AddError(this, $"min[{i}] is larger than max[{i}]"); } } if (this.Encoding != EncodingType.FLOAT) { return; } var current = new float[dimensions]; var minimum = this._min.ConvertAll(item => (float)item); var maximum = this._max.ConvertAll(item => (float)item); var array = new MultiArray(this.SourceBufferView.Content, this.ByteOffset, this.Count, this.SourceBufferView.ByteStride, dimensions, this.Encoding, false); for (int i = 0; i < array.Count; ++i) { array.CopyItemTo(i, current); for (int j = 0; j < current.Length; ++j) { var v = current[j]; if (!v._IsReal()) { result.AddError(this, $"Item[{j}][{i}] is not a finite number: {v}"); } var min = minimum[j]; var max = maximum[j]; if (v < min || v > max) { result.AddError(this, $"Item[{j}][{i}] is out of bounds. {min} <= {v} <= {max}"); } } } }
public void UpdateBounds() { var dimensions = this._type.DimCount(); var bounds = new double[dimensions]; this._min.Clear(); this._min.AddRange(bounds); this._max.Clear(); this._max.AddRange(bounds); this._min.Fill(double.MaxValue); this._max.Fill(double.MinValue); var array = new MultiArray(this.SourceBufferView.Content, this.ByteOffset, this.Count, this.SourceBufferView.ByteStride, dimensions, this.Encoding, false); var current = new float[dimensions]; for (int i = 0; i < array.Count; ++i) { array.CopyItemTo(i, current); for (int j = 0; j < current.Length; ++j) { this._min[j] = Math.Min(this._min[j], current[j]); this._max[j] = Math.Max(this._max[j], current[j]); } } }
private void ValidateBounds(VALIDATIONCTX result) { result = result.GetContext(this); if (_min.Count != _max.Count) { result.AddDataError("Max", $"Min and Max bounds dimension mismatch Min:{_min.Count} Max:{_max.Count}"); } if (_min.Count == 0 && _max.Count == 0) { return; } var dimensions = this.Dimensions.DimCount(); if (_min.Count != dimensions) { result.AddLinkError("Min", $"size mismatch; expected {dimensions} but found {_min.Count}"); return; } if (_max.Count != dimensions) { result.AddLinkError("Max", $"size mismatch; expected {dimensions} but found {_max.Count}"); return; } for (int i = 0; i < _min.Count; ++i) { // if (_min[i] > _max[i]) result.AddError(this, $"min[{i}] is larger than max[{i}]"); } if (this.Encoding != EncodingType.FLOAT) { return; } var current = new float[dimensions]; var minimum = this._min.ConvertAll(item => (float)item); var maximum = this._max.ConvertAll(item => (float)item); var array = new MultiArray(this.SourceBufferView.Content, this.ByteOffset, this.Count, this.SourceBufferView.ByteStride, dimensions, this.Encoding, false); for (int i = 0; i < array.Count; ++i) { array.CopyItemTo(i, current); for (int j = 0; j < current.Length; ++j) { var v = current[j]; // if (!v._IsFinite()) result.AddError(this, $"Item[{j}][{i}] is not a finite number: {v}"); var min = minimum[j]; var max = maximum[j]; // if (v < min || v > max) result.AddError(this, $"Item[{j}][{i}] is out of bounds. {min} <= {v} <= {max}"); } } }
public void UpdateBounds() { this._min.Clear(); this._max.Clear(); if (this.Count == 0) { return; } // With the current limitations of the serializer, we can only handle floating point values. if (this.Encoding != EncodingType.FLOAT) { return; } // https://github.com/KhronosGroup/glTF-Validator/issues/79 var dimensions = this.Dimensions.DimCount(); for (int i = 0; i < dimensions; ++i) { this._min.Add(double.MaxValue); this._max.Add(double.MinValue); } var array = new MultiArray(this.SourceBufferView.Content, this.ByteOffset, this.Count, this.SourceBufferView.ByteStride, dimensions, this.Encoding, false); var current = new float[dimensions]; for (int i = 0; i < array.Count; ++i) { array.CopyItemTo(i, current); for (int j = 0; j < current.Length; ++j) { this._min[j] = Math.Min(this._min[j], current[j]); this._max[j] = Math.Max(this._max[j], current[j]); } } }
public static void VerifyAccessorBounds(MemoryAccessor memory, IReadOnlyList <double> min, IReadOnlyList <double> max) { Guard.NotNull(memory, nameof(memory)); Guard.NotNull(min, nameof(min)); Guard.NotNull(max, nameof(max)); if (min.Count == 0 && max.Count == 0) { return; } var dimensions = memory.Attribute.Dimensions.DimCount(); if (min.Count != dimensions) { throw new ArgumentException($"min size mismatch; expected {dimensions} but found {min.Count}", nameof(min)); } if (max.Count != dimensions) { throw new ArgumentException($"max size mismatch; expected {dimensions} but found {max.Count}", nameof(max)); } for (int i = 0; i < min.Count; ++i) { // if (_min[i] > _max[i]) result.AddError(this, $"min[{i}] is larger than max[{i}]"); } var minimum = min.Select(item => (float)item).ToArray(); var maximum = max.Select(item => (float)item).ToArray(); var xinfo = memory.Attribute; xinfo.Dimensions = DIMENSIONS.SCALAR; memory = new MemoryAccessor(memory.Data, xinfo); var array = new MultiArray(memory.Data, memory.Attribute.ByteOffset, memory.Attribute.ItemsCount, memory.Attribute.ByteStride, dimensions, memory.Attribute.Encoding, memory.Attribute.Normalized); var current = new float[dimensions]; for (int i = 0; i < array.Count; ++i) { array.CopyItemTo(i, current); for (int j = 0; j < current.Length; ++j) { var v = current[j]; // if (!v._IsFinite()) result.AddError(this, $"Item[{j}][{i}] is not a finite number: {v}"); var axisMin = minimum[j]; var axisMax = maximum[j]; if (v < axisMin || v > axisMax) { throw new ArgumentOutOfRangeException(nameof(memory), $"Value[{i}] is out of bounds. {axisMin} <= {v} <= {axisMax}"); } // if (v < min || v > max) result.AddError(this, $"Item[{j}][{i}] is out of bounds. {min} <= {v} <= {max}"); } } }