Skip to main content

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 an x that's between min_max[0] and min_max[1], and changes the limits to min_max_new[0] and min_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.

set_min_max

  • reverse_range(x, min_max): Reverses an x value in a min_max range. Suppose you have a softness 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.

reverse_range

  • is_in_range(x, min_max, limits = ['c', 'c']): Checks if an x value is between min_max[0] and min_max[1]. The limits of the range are closed by default, so if x is equal to one of them, the function returns True. However, you can choose between c and o (closed/open) for each one of the two limits. An example:
isBetween = is_in_range(var, [25, 75])

is_in_range

  • range_lerp(min_max, t): Returns the linear interpolation between min_max[0] and min_max[1]. The following line prints the value halfway between 1 and 5:
print(range_lerp([1, 5], 0.5))
# outputs 3

range_lerp

  • find_lerp(x, min_max): returns the corresponding t value (between 0 and 1) of an x value between min_max[0] and min_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

find_lerp

  • clamp(x, min_max): Restricts the value to stay within the limits min_max[0] and min_max[1].
var = clamp(var, [25, 75])

clamp

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

qrange-1.0.3.tar.gz (2.9 kB view details)

Uploaded Source

Built Distribution

qrange-1.0.3-py3-none-any.whl (3.5 kB view details)

Uploaded Python 3

File details

Details for the file qrange-1.0.3.tar.gz.

File metadata

  • Download URL: qrange-1.0.3.tar.gz
  • Upload date:
  • Size: 2.9 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

Hashes for qrange-1.0.3.tar.gz
Algorithm Hash digest
SHA256 da76c99c8b9463706d0cd749c521b2bd43d62236eba8aa58b170e6b4d5aa5c37
MD5 928a3b1126bb0862fc371d26b716a632
BLAKE2b-256 1d0244d0f9e3fe7a2f8bd825a909e85475786caae4ebdda4f381f5d1ca4c5f37

See more details on using hashes here.

File details

Details for the file qrange-1.0.3-py3-none-any.whl.

File metadata

  • Download URL: qrange-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 3.5 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

Hashes for qrange-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 35fb74754c09f02a96cbc2efc26a5eb02ccf60977460a0008b2e11528bd2026f
MD5 caa3b04a2b3cc6bef7753140361913f4
BLAKE2b-256 226a51eaa64e192326f92f6217ad478e5f6b435b3db15765be8f0a29a62baaf4

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page