File: utils.py

package info (click to toggle)
python-vispy 0.6.6-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 21,240 kB
  • sloc: python: 57,407; javascript: 6,810; makefile: 63; sh: 5
file content (30 lines) | stat: -rw-r--r-- 772 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from __future__ import print_function, unicode_literals, absolute_import, division


EPSILON = 1e-8

REQUIRED = 1001001000
STRONG = 1000000
MEDIUM = 1000
WEAK = 1


def approx_equal(a, b, epsilon=EPSILON):
    "A comparison mechanism for floats"
    return abs(a - b) < epsilon


def repr_strength(strength):
    """Convert a numerical strength constant into a human-readable value.

    We could wrap this up in an enum, but enums aren't available in Py2;
    we could use a utility class, but we really don't need the extra
    implementation weight. In practice, this repr is only used for debug
    purposes during development.
    """
    return {
        REQUIRED: 'Required',
        STRONG: 'Strong',
        MEDIUM: 'Medium',
        WEAK: 'Weak'
    }[strength]