NumberInterpolation 1.0.1

dotnet add package NumberInterpolation --version 1.0.1
                    
NuGet\Install-Package NumberInterpolation -Version 1.0.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="NumberInterpolation" Version="1.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="NumberInterpolation" Version="1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="NumberInterpolation" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add NumberInterpolation --version 1.0.1
                    
#r "nuget: NumberInterpolation, 1.0.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package NumberInterpolation@1.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=NumberInterpolation&version=1.0.1
                    
Install as a Cake Addin
#tool nuget:?package=NumberInterpolation&version=1.0.1
                    
Install as a Cake Tool

NumberInterpolation Library - README

Introduction

Imagine you're a chef, and you have a recipe that serves 4 people, but you need to scale it up to serve 10. How do you figure out the new quantities for each ingredient? This is a classic example of interpolation, and the NumberInterpolation library is your kitchen assistant for such tasks, but in the realm of software.

The NumberInterpolation library provides a simple and efficient way to work with numeric ranges. It allows you to perform various operations like getting a value by percentage, clamping a value within a range, and even interpolating between two different ranges.

Features

  • Generic Numeric Ranges: Supports various numeric types like float, double, and decimal.
  • Value by Percentage: Calculate a value based on a given percentage within a range.
  • Percentage by Value: Find the percentage a value represents within a range.
  • Clamping: Restrict a value to be within a given range.
  • Interpolation: Interpolate a value from one range to another.

Installation

Include the NumberInterpolation library in your project. If it's a NuGet package, you can install it using:

dotnet add package NumberInterpolation

Quick Start

Import the Namespace

using NumberInterpolation;

Create a Numeric Range

var myRange = new FloatRange(0, 100);

Get Value by Percentage

float value = myRange.GetValueByPercentage(0.5f);  // Returns 50

Get Percentage by Value

float percentage = myRange.GetPercentageByValue(50);  // Returns 0.5

Clamping a Value

float clampedValue = myRange.Clamp(110);  // Returns 100

Interpolating Between Ranges

var anotherRange = new FloatRange(200, 300);
float interpolatedValue = myRange.Interpolate(anotherRange, 50);  // Returns 250

API Documentation

NumericRange<T>

This is the core class that represents a numeric range.

Properties
  • Minimum: The minimum value of the range.
  • Maximum: The maximum value of the range.
Methods
  • GetValueByPercentage(T percentage): Gets the value corresponding to a given percentage within the range.
  • GetPercentageByValue(T value): Gets the percentage corresponding to a given value within the range.
  • Clamp(T value): Clamps a value to be within the range.
  • Interpolate(NumericRange<T> other, T value): Interpolates a value from this range to another range.

DecimalRange, DoubleRange, FloatRange

These are specialized classes that extend NumericRange<T> for decimal, double, and float types respectively.

Exceptions

  • ArgumentException: Thrown when the minimum value is greater than or equal to the maximum value.
  • ArgumentOutOfRangeException: Thrown when the value or percentage is not within the valid range.

Conclusion

Think of NumberInterpolation as your Swiss Army knife for dealing with numeric ranges. Whether you're scaling up a recipe, resizing images, or normalizing data, this library has got you covered.

Happy Coding! 🚀

Product Compatible and additional computed target framework versions.
.NET net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net7.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.1 251 9/28/2023
1.0.0 204 9/28/2023