A python library for degree calculations and conversions.
Project description
degrees V0.4.0
Contents
- Introduction
- Importing
- Class
- Degree
- Functions
- degree2radian
- radian2degree
- normalize
- Changelog
Introduction
A python library for degree calculations and conversions.
🟩 Added in version 0.2: Supported
pickle.
Installing
| Python version | Windows | MacOS / Linux |
|---|---|---|
3.8 or 3.9 |
python -m pip install degrees==0.3.0.post1 |
pip3 install degrees==0.3.0.post1 |
3.10+ |
python -m pip install degrees |
pip3 install degrees |
If you use python 3.8 or 3.9, please read the docs here.
Importing
Just type import degrees.
Class
-
class degrees.Degree(number)
class degrees.Degree(degree_obj)
class degrees.Degree(degree=0, minute=0, second=0)-
Creating a Degree object
-
import degrees
print(degrees.Degree(1)) # 1°
print(degrees.Degree(2, 3, 4)) # 2°3'4"
print(degrees.Degree(1, second=2)) # 1°0'2"
print(degrees.Degree(1, 3)) # 1°3'
print(degrees.Degree(0, -1)) # -1'
print(degrees.Degree(1.5)) # 1°30'
print(degrees.Degree(2, -4)) # ValueError: if degree is not 0, minute and second must be positive integer
-
calculating:
comprehensions type(a)type(b)return type a + bDegreeint | floatDegreeint | floatDegreeDegreea - bDegreeint | floatDegreeint | floatDegreeDegreea * bDegreeint | floatDegreeint | floatDegreeDegreeDegreeDegreeDegreea / bDegreeDegreefloatDegreeint | floatDegreemath.trunc(a)Degree/ Degreeabs(a)Degree/ Degreemath.ceil(a)Degree/ Degreemath.floor(a)Degree/ Degreea % bDegreeDegreeDegreea // bDegreeDegreeintDegreeint | floatDegree+aDegree/ Degree-aDegree/ Degreehash(a)Degree/ int🟩 Added in version 0.1.7: Implemented the
math.truncfunction on the Degree objects.🟩 Added in version 0.4.0: Now
deg_obj * float_objis supported. In the previous version, onlydeg_obj * int_objis supported.🟥 Deprecated since version 0.4.0, will be removed in version 0.5.0:
Degree_obj * Degree_objis deprecated because it is useless and strange. -
conversions:
int(a)float(a)str(a)repr(a)bool(a)complex(a)In the table above, type(a)isDegree.The
complex(degree_obj)is different fromdegree_obj.to_complex(length). The former returnsint(degree_obj)+0j, but the latter returnscomplex(length * cos(theta), length * sin(theta)),theta=degree2radian(degree_obj).
For example:
import degrees
a = degrees.Degree(45)
print(complex(a)) # (45+0j)
print(a.to_complex(2 ** 0.5)) # about (1+1j)
-
comparisons:
comprehensions type(a)type(b)a >= bDegreeDegree | int | floata > bDegreeDegree | int | floata == bDegreeAnya <= bDegreeDegree | int | floata < bDegreeDegree | int | floata != bDegreeAnyIn the table above, the return value is bool,type(a)andtype(b)can be swapped. -
staticmethod from_str(string)
Return a degree object from a string. The dms characters should be
°,'and". -
staticmethod from_unicode(string)
Similar to
from_str, but the dms characters should be°,′and″.🟩 Added in version 0.1.10.
-
staticmethod from_iter(iterable)
Return a degree object from an iterable.
-
property total_seconds
The total seconds of a degree object.
-
deg
The degree of a degree object(without sign).
-
min
The minute of a degree object(without sign).
-
sec
The second of a degree object(without sign).
-
sign
The sign of a degree object.
-
to_complex(length: int | float)
Returns the complex number corresponding to
(angle=self, radius=length).🟩 Added in version 0.2.1.
-
property dms
A tuple of
(degree, minute, second).
Note
The attributes of Degree are read-only.
Functions
def degree2radian(x: Degree, /)
- Convert angle x from a degree object to radians.
def radian2degree(x: int | float, /)
- Convert angle x from radians to a degree object.
def normalize(x: Degree, /)
- Be using for angle normalization.
Version
version_info
- The version of this package, like
sys.version_info← click for more info.
Consts
DEGREE
MINUTE
SECOND
Equals to °, ′ and ″.
Changelog
- Supported
Degree_obj * float_obj. - Optimized
from_strandfrom_unicode. - Raised DeprecatedWarning when using
Degree_obj * Degree_obj.
Write in the end
If you found the bug in the code, you can email me at
snake830@vip.163.com. I am happy to receive the advice!
Project details
Release history Release notifications | RSS feed
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file degrees-0.4.0.tar.gz.
File metadata
- Download URL: degrees-0.4.0.tar.gz
- Upload date:
- Size: 9.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4641469f863d464644e7748aa6d45109139b4b54295535bc764781da2d26a08e
|
|
| MD5 |
fc9993cd5e0182e5ae292f0d969114bc
|
|
| BLAKE2b-256 |
4ae2760127fe5d5dc4aefcc42de12c87fd72a65a8133066557cdd63041677cae
|
File details
Details for the file degrees-0.4.0-py3-none-any.whl.
File metadata
- Download URL: degrees-0.4.0-py3-none-any.whl
- Upload date:
- Size: 8.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ce10a3461b84528fe43d786d02dca171bf3e097881d717e5323162e821ac55b6
|
|
| MD5 |
b931cc1b280afdb0fe8d4b1a1b2d8ac9
|
|
| BLAKE2b-256 |
0dd6afff4fd0e495e8137731931f2ceafd36d76fb1a80e4915a3a39fd9640744
|