protected override IEnumerable <Piece> CreatePiece(int fromValue, int toValue, Clamper clamper) { if (fromValue > toValue) { return(new[] { new Piece(clamper.Minimum, clamper.Clamp(toValue)), new Piece(clamper.Clamp(fromValue), clamper.Maximum), }); } return(base.CreatePiece(fromValue, toValue, clamper)); }
public void Clamper_TestIntegerTooLarge_ReturnsMax() { var val = 4; var min = 2; var max = 3; var result = Clamper.Clamp(val, min, max); Assert.Equal(max, result); }
public void Clamper_TestIntegerTooSmall_ReturnsMin() { var val = 1; var min = 2; var max = 3; var result = Clamper.Clamp(val, min, max); Assert.Equal(min, result); }
public void Clamper_TestFloatTooLarge_ReturnsMax() { var val = 4.0f; var min = 2.0f; var max = 3.0f; var result = Clamper.Clamp(val, min, max); Assert.Equal(max, result); }
public void Clamper_TestFloatTooSmall_ReturnsMin() { var val = 1.0f; var min = 2.0f; var max = 3.0f; var result = Clamper.Clamp(val, min, max); Assert.Equal(min, result); }
protected override IEnumerable <Piece> TryToGetSingleValuePiece(string part, Clamper clamper) { if (!TryParse(part, out var value)) { return(null); } if (_roundSingle && part.IndexOf('e') == -1 && part.IndexOf('E') == -1) { var match = FloatyPart.Match(part); if (match.Success) { var accuracy = Math.Pow(0.1, match.Length - 1) * 0.99; return(new[] { new Piece(clamper.Clamp(value - accuracy), clamper.Clamp(value + accuracy)) }); } return(new[] { new Piece(clamper.Clamp(value), clamper.Clamp(value + 0.999)) }); } return(new[] { new Piece(clamper.Clamp(value)) }); }
protected override IEnumerable <Piece> TryToGetSingleValuePiece(string part, Clamper clamper) { if (!_roundSingle) { return(base.TryToGetSingleValuePiece(part, clamper)); } if (!TryParse(part, out var value)) { return(null); } switch (part.Count(':')) { case 0: return(new[] { new Piece(clamper.Clamp(value), clamper.Clamp(value + 60 * 60 - 1)) }); case 1: return(new[] { new Piece(clamper.Clamp(value), clamper.Clamp(value + 59)) }); default: return(new[] { new Piece(clamper.Clamp(value)) }); } }
public void SetEffectTransition(ref ColourEffectConfiguration config, ref float transitionSeconds) { transitionSeconds = Clamper.Clamp(transitionSeconds, 0.0f, float.MaxValue); //Might be duplicated clamp for this value if (transitionSeconds == 0.0f) { _current = config; _isTransitioning = false; UpdateBufferAndClearColour(); return; } _previous = _current; _target = config; _transitionTotalTime = transitionSeconds; _transitionCurrentTime = 0.0f; _isTransitioning = true; }
public ITexture CreateRgbaFromData(uint textureWidth, uint textureHeight, Vector4[] pixels, SamplerType samplerType = SamplerType.Anisotropic, bool generateMipMaps = true) { if (pixels == null) { throw new Yak2DException("Surfaces -> CreateRgbaFromData(), pixel data cannot be null", new ArgumentNullException("pixels")); } if (textureWidth == 0 | textureHeight == 0) { throw new Yak2DException("Surfaces -> CreateRgbaFromData(), texture dimensions cannot be zero"); } if (textureWidth * textureHeight != pixels.Length) { throw new Yak2DException("Surfaces -> CreateRgbaFromData(), pixel data array size does not match dimensions"); } var pixelcount = textureWidth * textureHeight; var rgba = new Rgba32[pixelcount]; for (var p = 0; p < pixelcount; p++) { var value = pixels[p]; rgba[p] = new Rgba32( Clamper.Clamp(value.X, 0.0f, 1.0f), Clamper.Clamp(value.Y, 0.0f, 1.0f), Clamper.Clamp(value.Z, 0.0f, 1.0f), Clamper.Clamp(value.W, 0.0f, 1.0f) ); } return(_surfaceManager.CreateRgbaTextureFromPixelData(textureWidth, textureHeight, rgba, samplerType, generateMipMaps, false)); }