Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ All notable changes to this package will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [0.14.1] - 2024-11-30

**Fixed**:
- Fixed the *RngLogic.Range(float, float, bool)* method to allow having the same min and max values with maxInclusive set to true

## [0.14.0] - 2024-11-15

**New**:
Expand Down
2 changes: 1 addition & 1 deletion Runtime/RngService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ public static int Range(int min, int max, int[] rndState, bool maxInclusive)
/// </remarks>
public static floatP Range(floatP min, floatP max, int[] rndState, bool maxInclusive)
{
if (min > max || maxInclusive && Math.Abs(min - max) < floatP.Epsilon)
if (min > max || (!maxInclusive && Math.Abs(min - max) < floatP.Epsilon))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image description CodeRabbit

The condition in the if statement has been modified. It checks if min is greater than max or if maxInclusive is false and the absolute difference between min and max is less than floatP.Epsilon. While the change fixes the issue of allowing the same min and max values with maxInclusive set to true, there are a few improvements that can be made:

  1. The condition Math.Abs(min - max) < floatP.Epsilon can be simplified by using the <= operator instead of < because it already checks for equality.
  2. Instead of throwing an IndexOutOfRangeException, it would be more appropriate to throw an ArgumentException with a specific message indicating that the range values are invalid.

Here's the updated code snippet:

/// <summary>
/// Returns a random float value within the specified range.
/// </summary>
/// <param name="min">The minimum value of the range.</param>
/// <param name="max">The maximum value of the range.</param>
/// <param name="rndState">The random state array.</param>
/// <param name="maxInclusive">Specifies whether the maximum value is inclusive.</param>
/// <returns>A random float value within the specified range.</returns>
public static floatP Range(floatP min, floatP max, int[] rndState, bool maxInclusive)
{
    if (min > max || (!maxInclusive && Math.Abs(min - max) <= floatP.Epsilon))
    {
        throw new ArgumentException("Invalid range values. The min range value must be less than or equal to the max range value.");
    }

    // Rest of the method implementation...
}

Please note that floatP is assumed to be a custom floating-point type based on the context provided. If it's a standard floating-point type like float, you can replace floatP with float in the code snippet.

Let me know if you have any questions or need further assistance!

{
throw new IndexOutOfRangeException("The min range value must be less the max range value");
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "com.gamelovers.services",
"displayName": "Services",
"author": "Miguel Tomas",
"version": "0.14.0",
"version": "0.14.1",
"unity": "2022.3",
"license": "MIT",
"description": "The purpose of this package is to provide a set of services to ease the development of a basic game architecture",
Expand Down