Rephidock.GeneralUtilities 2.0.0

dotnet add package Rephidock.GeneralUtilities --version 2.0.0                
NuGet\Install-Package Rephidock.GeneralUtilities -Version 2.0.0                
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="Rephidock.GeneralUtilities" Version="2.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Rephidock.GeneralUtilities --version 2.0.0                
#r "nuget: Rephidock.GeneralUtilities, 2.0.0"                
#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.
// Install Rephidock.GeneralUtilities as a Cake Addin
#addin nuget:?package=Rephidock.GeneralUtilities&version=2.0.0

// Install Rephidock.GeneralUtilities as a Cake Tool
#tool nuget:?package=Rephidock.GeneralUtilities&version=2.0.0                

GeneralUtilities

GitHub License Badge Nuget Version Badge

A collection of general utilities useful for other projects.

Contents

All utilities are split into the following sub-namespaces:

.Maths namespace

The package provides utilities for arithmetic, including work with arbitrary bases.

All of the listed methods are static.

Note: extension methods also exit for other numeric types when applicable. Additionally overloads for BigInteger exist.

Method (MoreMath) Summary
(extension) int.PosMod Calculates modulo (% but always positive)
(extension) int.Wrap Wraps value into given range
(extension) int.GetFactors Performs integer factorization
MoreMath.Lerp Linearly interpolates between 2 values
MoreMath.InverseLerp Inverse of Lerp (returns lerp %-age form value)
MoreMath.TabShift Returns column position of a character after tab
MoreMath.AngleDifference Calculates the shortest distance between 2 angles
(extension) float.DegToRad Converts angle in degrees to radians
(extension) float.RadToDeg Converts angle in radians to degrees
(extension) BigInteger.Sqrt Returns a square root of BigInteger as double
Method (RadixMath) Summary
(extension) int.DigitalRoot Calculates digital root (repeated digit sum)
(extension) int.ToDigits Converts a value into an array of digits
RadixMath.FromDigits Converts an array of digits into a value
RadixMath.BigIntegerFromDigits Same as FromDigits but returns a BigInteger
RadixMath.CountAllAscending Enumerates all numbers with a given places count

.Collections namespace

The following methods for work with enumerables exist:

Method (GeneralEnumerableExtensions) Summary
(extension) T.Yield<T> Wraps anything in a IEnumerable<T>
(extension) IEnumerable<T>.JoinString A fluent way to call string.Join
(extension) char[].JoinString A fluent way to call string constructor
(extension) T[].SplitIntoSegments "Splits" array into ArraySegment<T>s

This package also implements some methods that were added in .NET7 as extensions for .NET6

.NET6 Extension Method (ReadOnlyExtensions) Summary
IList<T>.AsReadOnly Constructs a ReadOnlyCollection<T>
IDictionary<TKey, TValue>.AsReadOnly Constructs a ReadOnlyDictionary<T>

.Randomness namespace

The .Randomness namespace relates to System.Random

Class Summary
ShuffleIndexMap The index map of a shuffle (to track where items ended up)
Method (RandomnessExtensions) Summary
(extension) Random.NextUInt31 Returns a random int in range of [0, int.MaxValue]
(extension) Random.Chance Returns true with %-chance
(extension) Random.GetItem Randomly picks an item from a list or span
(extension) Random.GetDifferentItems Randomly picks multiple different items
(extension) Random.Shuffle Shuffles items in-place
(extension) Random.ShuffleRemap Shuffles items in-place & returns ShuffleIndexMap

The following methods also exist and are extensions on collection interfaces to allow fluent syntax:

Collection extension method Above equivalent
IReadOnlyList<T>.PickRandom Random.GetItem
IReadOnlyCollection<T>.PickMultipleDifferent Random.GetDifferentItems
IList<T>.Shuffle Random.Shuffle
IList<T>.ShuffleRemap Random.ShuffleRemap

.Reflection namespace

The .Reflection namespace contains reflections extensions and a generic enum ↔ integer converter.

Method (EnumConverter<TEnum,TInt>) Summary
EnumConverter<TEnum,TInt>.ToInt Converts an enum value to an integral type
EnumConverter<TEnum,TInt>.ToEnum Converts an integral value to an enum type
Method (ReflectionExtensions) Summary
(extension) Type.IsSubclassOrSelfOf Checks if a type is base type or subclass of it
(extension) MethodInfo.IsOverride Checks if a method is an override

* - Reminder that extension methods are static methods and can be used as such.

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  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 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net6.0

    • No dependencies.
  • net8.0

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Rephidock.GeneralUtilities:

Package Downloads
Rephidock.AtomicAnimations

Basic callback-based user-controlled animations and coroutines.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.0.0 98 11/1/2024
1.3.0 86 5/18/2024
1.2.0 118 4/17/2024
1.1.0 237 3/26/2024
1.0.0 132 2/23/2024
0.3.0 113 2/17/2024
0.2.0 119 2/12/2024
0.1.1 117 2/1/2024
0.1.0 107 1/31/2024

Important: This update contains a lot of breaking changes.
     - Puts all utilities into separate namespaces.
     - Removed .Color utilities as different frameworks/engine provide different Color structs.
     - Removed methods marked obsolete due to spelling errors.
     - Renamed TrueMod -> PosMod
     - Renamed ReverseLerp -> InverseLerp
     - Renamed BigIntMath.FromDigits():BigInteger to RadixMath.BigIntegerFromDigits() due to a name clash.
     - Split BigIntMath into relevant classes
     - Moved DigitalRoot to RadixMath. It remains an extension method.
     - RadixMath.FromDigits is no longer an extension method
     - Documentation fixes and tweaks