question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Simple Math and Geometry convenience improvements

See original GitHub issue

Summary

The following suggestions were gathered while using the engine for a number of projects. The intention is to make one’s life easier by providing shortcuts for common calculations.

List of suggestions

  1. Vector component properties for Vector2 and Vector3 types. Obtaining the X, Y and Z vector components quickly. Names are arguable. Implementation example:
struct Vector3 {
    Vector3 XVector { get { return new Vector3 (this.X, 0f, 0f); } }
    Vector3 YVector { get { return new Vector3 (0f, this.Y, 0f); } }
    Vector3 ZVector { get { return new Vector3 (0f, 0f, this.Z); } }
}
  1. More coordinate selector properties for Rect. Convenient access for: TopMiddle, RightMiddle, BottomMiddle and LeftMiddle coordinates.

  2. A saturation function to the MathF class. Similar to Sign, but accepts an epsilon value too. Implementation example:

float Saturate (float val, float eps)
{
    if (Abs (val) <= eps) return 0f;
    return Sign (val);
}
  1. Clamp is quite often used with 0f and 1f as boundaries. Let’s create a function for that: Clamp01.

  2. Inverse linear interpolation to MathF, and possibly to Vector2 and Vector3. Implementation example:

float InvLerp (float value, float min, float max)
{
    return (value - min) / (max - min);
}
  1. Inverse linear interpolation with 0f and 1f as boundaries.

  2. Introduce the well known smoothstep function to MathF. The formula is x * x * (3 - 2 * x).

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:24 (23 by maintainers)

github_iconTop GitHub Comments

2reactions
deanljohnsoncommented, May 17, 2018

Yup, I saw that mentioned previously in the thread. I believe I’ve got it right, I just haven’t had a chance to ensure it is so.

If you wanted to go the extra mile you could add unit tests for this to the DualityTests project. That’d also give you a chance to test every case without needing to setup a game project. You’ll need to install the NUnit test adapter in order or run the unit tests.

2reactions
deanljohnsoncommented, May 14, 2018

@helle253 Yep, nothing on that Todo list has been done yet. Have at it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Top 17 Apps to Improve Math Skills for Adults
There are many ways to improve your math skills as an adult, and using mobile apps is a convenient and effective option.
Read more >
A measure estimate in geometry of numbers and ...
Mathematical Society. RESEARCH ARTICLE. A measure estimate in geometry of numbers and improvements to Dirichlet's theorem. Dmitry Kleinbock1.
Read more >
Adding It Up: Helping Children Learn Mathematics (2001)
Read chapter 4 THE STRANDS OF MATHEMATICAL PROFICIENCY: Adding It Up explores how students in pre-K through 8th grade learn mathematics and recommends...
Read more >
The Simple Math Problem We Still Can't Solve
Despite recent progress on the notorious Collatz conjecture, we still don't know whether a number can escape its infinite loop.
Read more >
Answers To Geometry Home Improvement Project
You'll also be able to go online to study whenever you like, with convenient resources, hundreds of flashcards, 6 full- length ASVAB practice...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found