Working with ranges made simple
Project description
qrange
A small, easy-to-use library for working with ranges.
Installation
This package can be installed with the command:
pip install qrange
How to use
Use qrange in your project by adding the following line at the top of your file:
import qrange
This library provides a set of functions for making it easier to work with ranges:
set_min_max(x, min_max, min_max_new)
: Takes anx
that's betweenmin_max[0]
andmin_max[1]
, and changes the limits tomin_max_new[0]
andmin_max_new[1]
. Example usage:
color = [128, 0, 0]
color[0] = set_min_max(color[0], [0, 255], [0, 1]) #converts 0-255 color to 0-1 color range.
reverse_range(x, min_max)
: Reverses anx
value in amin_max
range. Suppose you have asoftness
variable, but you made the program so that the higher the softness is, the harder it gets.reverse_range
can fix that for you:
softness = reverse_range(softness, [0, 10])
# If the variable was 0, this function made it 10.
# similarly, if it had a value of 10, it is now 0.
is_in_range(x, min_max, limits = ['c', 'c'])
: Checks if anx
value is betweenmin_max[0]
andmin_max[1]
. The limits of the range are closed by default, so ifx
is equal to one of them, the function returnsTrue
. However, you can choose betweenc
ando
(closed/open) for each one of the two limits. An example:
isBetween = is_in_range(var, [25, 75])
range_lerp(min_max, t)
: Returns the linear interpolation betweenmin_max[0]
andmin_max[1]
. The following line prints the value halfway between 1 and 5:
print(range_lerp([1, 5], 0.5))
# outputs 3
find_lerp(x, min_max)
: returns the correspondingt
value (between 0 and 1) of anx
value betweenmin_max[0]
andmin_max[1]
. Consider the following examples:
print(find_lerp(5, [5, 10])) #outputs 0
print(find_lerp(10, [5, 10])) #outputs 1
print(find_lerp(8, [5, 10])) #outputs 0.6
clamp(x, min_max)
: Restricts the value to stay within the limitsmin_max[0]
andmin_max[1]
.
var = clamp(var, [25, 75])
Changelog
Version 1.0.0
- qrange has been created
About the author
Hi! I am a solo software developer. I created qrange as an open source library to simplify the process of using ranges in Python. Check out my other repositories as well. If you want to support me, please buy me a coffee here. Any amount is appreciated! :)
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file qrange-1.0.1.tar.gz
.
File metadata
- Download URL: qrange-1.0.1.tar.gz
- Upload date:
- Size: 2.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a623079f313aa2981cd34da5bed52c85cea0be91f9a135bd8e4e6719667f30ba |
|
MD5 | 212e7b1648cb96ac15d3a445fdd6119b |
|
BLAKE2b-256 | a773183c29d43a3c0afc0aa1c4233676be30a09dacf0eb2a0aa08be34eec90f3 |
File details
Details for the file qrange-1.0.1-py3-none-any.whl
.
File metadata
- Download URL: qrange-1.0.1-py3-none-any.whl
- Upload date:
- Size: 2.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 22dd9c3b4d09276787a6f2862658124e3b2e14cee1be25dcbd7e56ffaee2dc4d |
|
MD5 | a120b6f2f54f14e308c9da1b97b71502 |
|
BLAKE2b-256 | fcaa3f01511ce488470d0a324603f9e827cb58d8905e4b7118ba7a8e7e2d88a0 |