rat-trig 0.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- rat_trig/__init__.py +16 -0
- rat_trig/skeleton.py +149 -0
- rat_trig/trigonom.py +65 -0
- rat_trig-0.1.dist-info/METADATA +49 -0
- rat_trig-0.1.dist-info/RECORD +8 -0
- rat_trig-0.1.dist-info/WHEEL +5 -0
- rat_trig-0.1.dist-info/licenses/LICENSE.txt +21 -0
- rat_trig-0.1.dist-info/top_level.txt +1 -0
rat_trig/__init__.py
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
|
|
3
|
+
if sys.version_info[:2] >= (3, 8):
|
|
4
|
+
# TODO: Import directly (no need for conditional) when `python_requires = >= 3.9`
|
|
5
|
+
from importlib.metadata import PackageNotFoundError, version # pragma: no cover
|
|
6
|
+
else:
|
|
7
|
+
from importlib_metadata import PackageNotFoundError, version # pragma: no cover
|
|
8
|
+
|
|
9
|
+
try:
|
|
10
|
+
# Change here if project is renamed and does not equal the package name
|
|
11
|
+
dist_name = "rat-trig"
|
|
12
|
+
__version__ = version(dist_name)
|
|
13
|
+
except PackageNotFoundError: # pragma: no cover
|
|
14
|
+
__version__ = "unknown"
|
|
15
|
+
finally:
|
|
16
|
+
del version, PackageNotFoundError
|
rat_trig/skeleton.py
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
"""
|
|
2
|
+
This is a skeleton file that can serve as a starting point for a Python
|
|
3
|
+
console script. To run this script uncomment the following lines in the
|
|
4
|
+
``[options.entry_points]`` section in ``setup.cfg``::
|
|
5
|
+
|
|
6
|
+
console_scripts =
|
|
7
|
+
fibonacci = rat_trig.skeleton:run
|
|
8
|
+
|
|
9
|
+
Then run ``pip install .`` (or ``pip install -e .`` for editable mode)
|
|
10
|
+
which will install the command ``fibonacci`` inside your current environment.
|
|
11
|
+
|
|
12
|
+
Besides console scripts, the header (i.e. until ``_logger``...) of this file can
|
|
13
|
+
also be used as template for Python modules.
|
|
14
|
+
|
|
15
|
+
Note:
|
|
16
|
+
This file can be renamed depending on your needs or safely removed if not needed.
|
|
17
|
+
|
|
18
|
+
References:
|
|
19
|
+
- https://setuptools.pypa.io/en/latest/userguide/entry_point.html
|
|
20
|
+
- https://pip.pypa.io/en/stable/reference/pip_install
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
import argparse
|
|
24
|
+
import logging
|
|
25
|
+
import sys
|
|
26
|
+
|
|
27
|
+
from rat_trig import __version__
|
|
28
|
+
|
|
29
|
+
__author__ = "Wai-Shing Luk"
|
|
30
|
+
__copyright__ = "Wai-Shing Luk"
|
|
31
|
+
__license__ = "MIT"
|
|
32
|
+
|
|
33
|
+
_logger = logging.getLogger(__name__)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
# ---- Python API ----
|
|
37
|
+
# The functions defined in this section can be imported by users in their
|
|
38
|
+
# Python scripts/interactive interpreter, e.g. via
|
|
39
|
+
# `from rat_trig.skeleton import fib`,
|
|
40
|
+
# when using this Python module as a library.
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def fib(n):
|
|
44
|
+
"""Fibonacci example function
|
|
45
|
+
|
|
46
|
+
Args:
|
|
47
|
+
n (int): integer
|
|
48
|
+
|
|
49
|
+
Returns:
|
|
50
|
+
int: n-th Fibonacci number
|
|
51
|
+
"""
|
|
52
|
+
assert n > 0
|
|
53
|
+
a, b = 1, 1
|
|
54
|
+
for _i in range(n - 1):
|
|
55
|
+
a, b = b, a + b
|
|
56
|
+
return a
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
# ---- CLI ----
|
|
60
|
+
# The functions defined in this section are wrappers around the main Python
|
|
61
|
+
# API allowing them to be called directly from the terminal as a CLI
|
|
62
|
+
# executable/script.
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def parse_args(args):
|
|
66
|
+
"""Parse command line parameters
|
|
67
|
+
|
|
68
|
+
Args:
|
|
69
|
+
args (List[str]): command line parameters as list of strings
|
|
70
|
+
(for example ``["--help"]``).
|
|
71
|
+
|
|
72
|
+
Returns:
|
|
73
|
+
:obj:`argparse.Namespace`: command line parameters namespace
|
|
74
|
+
"""
|
|
75
|
+
parser = argparse.ArgumentParser(description="Just a Fibonacci demonstration")
|
|
76
|
+
parser.add_argument(
|
|
77
|
+
"--version",
|
|
78
|
+
action="version",
|
|
79
|
+
version=f"rat-trig {__version__}",
|
|
80
|
+
)
|
|
81
|
+
parser.add_argument(dest="n", help="n-th Fibonacci number", type=int, metavar="INT")
|
|
82
|
+
parser.add_argument(
|
|
83
|
+
"-v",
|
|
84
|
+
"--verbose",
|
|
85
|
+
dest="loglevel",
|
|
86
|
+
help="set loglevel to INFO",
|
|
87
|
+
action="store_const",
|
|
88
|
+
const=logging.INFO,
|
|
89
|
+
)
|
|
90
|
+
parser.add_argument(
|
|
91
|
+
"-vv",
|
|
92
|
+
"--very-verbose",
|
|
93
|
+
dest="loglevel",
|
|
94
|
+
help="set loglevel to DEBUG",
|
|
95
|
+
action="store_const",
|
|
96
|
+
const=logging.DEBUG,
|
|
97
|
+
)
|
|
98
|
+
return parser.parse_args(args)
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def setup_logging(loglevel):
|
|
102
|
+
"""Setup basic logging
|
|
103
|
+
|
|
104
|
+
Args:
|
|
105
|
+
loglevel (int): minimum loglevel for emitting messages
|
|
106
|
+
"""
|
|
107
|
+
logformat = "[%(asctime)s] %(levelname)s:%(name)s:%(message)s"
|
|
108
|
+
logging.basicConfig(
|
|
109
|
+
level=loglevel, stream=sys.stdout, format=logformat, datefmt="%Y-%m-%d %H:%M:%S"
|
|
110
|
+
)
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
def main(args):
|
|
114
|
+
"""Wrapper allowing :func:`fib` to be called with string arguments in a CLI fashion
|
|
115
|
+
|
|
116
|
+
Instead of returning the value from :func:`fib`, it prints the result to the
|
|
117
|
+
``stdout`` in a nicely formatted message.
|
|
118
|
+
|
|
119
|
+
Args:
|
|
120
|
+
args (List[str]): command line parameters as list of strings
|
|
121
|
+
(for example ``["--verbose", "42"]``).
|
|
122
|
+
"""
|
|
123
|
+
args = parse_args(args)
|
|
124
|
+
setup_logging(args.loglevel)
|
|
125
|
+
_logger.debug("Starting crazy calculations...")
|
|
126
|
+
print(f"The {args.n}-th Fibonacci number is {fib(args.n)}")
|
|
127
|
+
_logger.info("Script ends here")
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
def run():
|
|
131
|
+
"""Calls :func:`main` passing the CLI arguments extracted from :obj:`sys.argv`
|
|
132
|
+
|
|
133
|
+
This function can be used as entry point to create console scripts with setuptools.
|
|
134
|
+
"""
|
|
135
|
+
main(sys.argv[1:])
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
if __name__ == "__main__":
|
|
139
|
+
# ^ This is a guard statement that will prevent the following code from
|
|
140
|
+
# being executed in the case someone imports this file instead of
|
|
141
|
+
# executing it as a script.
|
|
142
|
+
# https://docs.python.org/3/library/__main__.html
|
|
143
|
+
|
|
144
|
+
# After installing your project with pip, users can also run your Python
|
|
145
|
+
# modules as scripts via the ``-m`` flag, as defined in PEP 338::
|
|
146
|
+
#
|
|
147
|
+
# python -m rat_trig.skeleton 42
|
|
148
|
+
#
|
|
149
|
+
run()
|
rat_trig/trigonom.py
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Rational Trigonometry is a new approach to classical trigonometry, developed by Norman
|
|
3
|
+
Wildberger, that aims to simplify and clarify the subject by using only rational numbers
|
|
4
|
+
and operations, rather than irrational numbers and limits.
|
|
5
|
+
|
|
6
|
+
In traditional trigonometry, concepts such as the sine, cosine, and tangent of an angle
|
|
7
|
+
are typically defined using circles and the unit circle in particular. These definitions
|
|
8
|
+
involve irrational numbers and limits, which can make the subject more difficult to
|
|
9
|
+
understand and work with.
|
|
10
|
+
|
|
11
|
+
In rational trigonometry, Wildberger replaces these circular definitions with ones based
|
|
12
|
+
on lines and line segments, which allows for a more straightforward and intuitive approach.
|
|
13
|
+
The fundamental concepts in rational trigonometry are the "quadaverage" and the "dilated
|
|
14
|
+
directed angle," which are defined in terms of lines and line segments, rather than circles.
|
|
15
|
+
|
|
16
|
+
Rational trigonometry has been gaining popularity in recent years, as it provides a useful
|
|
17
|
+
alternative to traditional trigonometry for certain applications, such as computer graphics,
|
|
18
|
+
robotics, and physics. It can also be a helpful tool for students who struggle with the
|
|
19
|
+
irrational numbers and limits used in traditional trigonometry.
|
|
20
|
+
|
|
21
|
+
In summary, Rational Trigonometry is a new approach to classical trigonometry that uses
|
|
22
|
+
rational numbers and operations, rather than irrational numbers and limits, making it a more
|
|
23
|
+
straightforward and intuitive subject to understand and work with.
|
|
24
|
+
"""
|
|
25
|
+
|
|
26
|
+
from typing import TypeVar
|
|
27
|
+
from fractions import Fraction
|
|
28
|
+
|
|
29
|
+
T = TypeVar("T", int, Fraction, float)
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def archimedes(q_1: T, q_2: T, q_3: T) -> T:
|
|
33
|
+
r"""
|
|
34
|
+
The function `archimedes` calculates the qudrea of a triangle using Archimedes' formula with
|
|
35
|
+
the lengths of the three sides `q_1`, `q_2`, and `q_3`. It can also be used to check if a quadraple
|
|
36
|
+
with length Q1, Q2, Q3, Q4 is on a circle.
|
|
37
|
+
|
|
38
|
+
:param q_1: The function `archimedes` takes three parameters `q_1`, `q_2`, and `q_3` of type `T` and
|
|
39
|
+
returns a value of type `T`
|
|
40
|
+
:type q_1: T
|
|
41
|
+
:param q_2: The `q_2` parameter in the `archimedes` function represents a value of type `T`. It is
|
|
42
|
+
one of the input parameters along with `q_1` and `q_3`. The function performs a calculation using
|
|
43
|
+
these parameters and returns a result of type `T`
|
|
44
|
+
:type q_2: T
|
|
45
|
+
:param q_3: The function `archimedes` takes three parameters `q_1`, `q_2`, and `q_3`, all of type
|
|
46
|
+
`T`. It then calculates a value based on these parameters and returns the result
|
|
47
|
+
:type q_3: T
|
|
48
|
+
:return: the result of the expression \(4 \times q_1 \times q_2 - \text{temp}^2\), where
|
|
49
|
+
\(\text{temp} = q_1 + q_2 - q_3\).
|
|
50
|
+
|
|
51
|
+
Example:
|
|
52
|
+
>>> q_1 = Fraction(1, 2)
|
|
53
|
+
>>> q_2 = Fraction(1, 4)
|
|
54
|
+
>>> q_3 = Fraction(1, 6)
|
|
55
|
+
>>> archimedes(q_1, q_2, q_3)
|
|
56
|
+
Fraction(23, 144)
|
|
57
|
+
"""
|
|
58
|
+
temp = q_1 + q_2 - q_3
|
|
59
|
+
return 4 * q_1 * q_2 - temp * temp
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
if __name__ == "__main__":
|
|
63
|
+
import doctest
|
|
64
|
+
|
|
65
|
+
doctest.testmod()
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: rat-trig
|
|
3
|
+
Version: 0.1
|
|
4
|
+
Summary: Rational Trigonometry
|
|
5
|
+
Home-page: https://github.com/pyscaffold/pyscaffold/
|
|
6
|
+
Author: Wai-Shing Luk
|
|
7
|
+
Author-email: luk036@gmail.com
|
|
8
|
+
License: MIT
|
|
9
|
+
Project-URL: Documentation, https://pyscaffold.org/
|
|
10
|
+
Platform: any
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Programming Language :: Python
|
|
13
|
+
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
|
|
14
|
+
License-File: LICENSE.txt
|
|
15
|
+
Requires-Dist: importlib-metadata; python_version < "3.9"
|
|
16
|
+
Provides-Extra: testing
|
|
17
|
+
Requires-Dist: setuptools; extra == "testing"
|
|
18
|
+
Requires-Dist: pytest; extra == "testing"
|
|
19
|
+
Requires-Dist: pytest-cov; extra == "testing"
|
|
20
|
+
Dynamic: license-file
|
|
21
|
+
|
|
22
|
+
<!-- These are examples of badges you might want to add to your README:
|
|
23
|
+
please update the URLs accordingly
|
|
24
|
+
|
|
25
|
+
[](https://cirrus-ci.com/github/<USER>/rat-trig)
|
|
26
|
+
[](https://rat-trig.readthedocs.io/en/stable/)
|
|
27
|
+
[](https://coveralls.io/r/<USER>/rat-trig)
|
|
28
|
+
[](https://pypi.org/project/rat-trig/)
|
|
29
|
+
[](https://anaconda.org/conda-forge/rat-trig)
|
|
30
|
+
[](https://pepy.tech/project/rat-trig)
|
|
31
|
+
[](https://twitter.com/rat-trig)
|
|
32
|
+
-->
|
|
33
|
+
|
|
34
|
+
[](https://pyscaffold.org/)
|
|
35
|
+
[](https://rat-trig.readthedocs.io/en/latest/?badge=latest)
|
|
36
|
+
[](https://coveralls.io/github/luk036/rat-trig?branch=main)
|
|
37
|
+
|
|
38
|
+
# 📐 rat-trig
|
|
39
|
+
|
|
40
|
+
> Rational Trigonometry
|
|
41
|
+
|
|
42
|
+
A longer description of your project goes here...
|
|
43
|
+
|
|
44
|
+
<!-- pyscaffold-notes -->
|
|
45
|
+
|
|
46
|
+
## 👉 Note
|
|
47
|
+
|
|
48
|
+
This project has been set up using PyScaffold 4.5. For details and usage
|
|
49
|
+
information on PyScaffold see https://pyscaffold.org/.
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
rat_trig/__init__.py,sha256=J1xoODWzwo8Do7xesIyhBX23Nljfo15P0kkHvU4Vvhg,579
|
|
2
|
+
rat_trig/skeleton.py,sha256=1kqseaPHmHXjEyCcl8vHe7UVVwGS72St74rStpEQrx0,4219
|
|
3
|
+
rat_trig/trigonom.py,sha256=TqhwuNey8cwkbkZ5FBLnC3ID-VMQ5LI3ORUzDHKsRGk,2993
|
|
4
|
+
rat_trig-0.1.dist-info/licenses/LICENSE.txt,sha256=otwo95eHpqJh3FUY6G6USS9xIIItcfoC7B5Cm_VY9-M,1080
|
|
5
|
+
rat_trig-0.1.dist-info/METADATA,sha256=uFcA6IrOCaM-FriASmWHwafEK4y8vMXUVzJ0Y2lsPu8,2311
|
|
6
|
+
rat_trig-0.1.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
|
|
7
|
+
rat_trig-0.1.dist-info/top_level.txt,sha256=gJl9p85VYM_uk1qOwfZIIKR7VAS8O0AIpGONEwE9B2o,9
|
|
8
|
+
rat_trig-0.1.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Wai-Shing Luk
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
rat_trig
|