Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Sphincs-based documentation #130

Merged
merged 73 commits into from
Mar 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
820dc4d
Run sphinx-quickstart
AstraLuma Mar 23, 2019
a866e64
README: Miscellaneous improvements in API description
nbraud Jan 19, 2019
c8ecf0c
Start moving API documentation from README to docstrings
nbraud Jan 19, 2019
da86482
README: Slight improvement
nbraud Jan 19, 2019
0515851
Vector2: Add a class docstring
nbraud Jan 19, 2019
b8dd905
Vector2.convert: Improve docstring
nbraud Jan 19, 2019
f24a6cb
Use RTD theme
AstraLuma Mar 23, 2019
7de90f5
Add docs requirements
AstraLuma Mar 23, 2019
cb0b0b6
docs: Generate docs for Vector2 using autoclass
nbraud Mar 23, 2019
131d34b
Vector2: Remove installation instructions from the class docstring
nbraud Mar 23, 2019
9c78c0f
Vector2: Start converting docstrings to rst markup
nbraud Mar 23, 2019
54ecf23
Add intersphinx to core python docs
AstraLuma Mar 23, 2019
c60537c
Add sphinx_autodoc_annotation
AstraLuma Mar 23, 2019
5cd676f
Merge pull request #128 from nbraud/pydoc
AstraLuma Mar 23, 2019
8856b7b
docs: Add missing dependency on sphinx_rtd_theme
nbraud Mar 23, 2019
0e9b47f
Vector2: Add markup for references in the docstrings
nbraud Mar 23, 2019
14cb33f
docs: Vector2: Add special members, because operators are pretty impo…
AstraLuma Mar 23, 2019
da9fff0
Better docs for Vector2.update
AstraLuma Mar 23, 2019
0136075
Rename the VectorOrSub type variable to Vector
nbraud Mar 23, 2019
7267ce8
Vector2.convert: Fix inter-Sphinx references to Mapping and Sequence
nbraud Mar 23, 2019
08bde42
Vector2.scale_by: Rename parameter to `scalar` (from `other`)
nbraud Mar 23, 2019
f9260e4
README: Bring back dunder operators (Sphinx doesn't render them)
nbraud Mar 23, 2019
8d57326
fixup! Vector2.scale_by: Rename parameter to `scalar` (from `other`)
nbraud Mar 23, 2019
53930fc
README: Use more operators for examples introducing vector-likes
nbraud Mar 23, 2019
b106a7d
Revert "README: Bring back dunder operators (Sphinx doesn't render th…
nbraud Mar 23, 2019
2ccc387
docs: Vector2: Document .x and .y
AstraLuma Mar 23, 2019
ad47824
Remove .scale from docs
AstraLuma Mar 23, 2019
66c0af3
Vector2.isclose: Grab the documentation from the README
nbraud Mar 23, 2019
edb9733
Vector2: Properly format variable names in docstrings
nbraud Mar 23, 2019
739d5af
docs: Annotate types of .x and .y
AstraLuma Mar 23, 2019
74f3936
Merge branch 'sphinx' of github.com:ppb/ppb-vector into sphinx
AstraLuma Mar 23, 2019
b8da55f
docs: Document the Vector typevar
nbraud Mar 23, 2019
36cabf3
docs/Vector2: Sort the exclude-members list
nbraud Mar 23, 2019
e25920b
docs/Vector2: Do not autogenerate doc for __repr__
nbraud Mar 23, 2019
e86e8c2
Vector2.__truediv__: Add example in docstring
nbraud Mar 23, 2019
24ddea2
Add examples for .convert()
AstraLuma Mar 23, 2019
bdb974f
Vector2.__mul__: Move the documentation to a docstring
nbraud Mar 23, 2019
3dc443c
README: Link to the RTD documentation
nbraud Mar 23, 2019
2a63fd6
Add docs about Vector2 being sequence-ish and mapping-ish
AstraLuma Mar 23, 2019
9692fd9
normalize: Remove errant comma
AstraLuma Mar 23, 2019
73543f1
Vector2: Reference vector-likes in each relevant method docstring
nbraud Mar 23, 2019
1b87499
Vector2.dot: Terser description
nbraud Mar 23, 2019
b82b597
Vector2.scale_by: Add example, document infix notation
nbraud Mar 23, 2019
aa6e723
Vector2.reflect: Reflow text in docstring
nbraud Mar 23, 2019
2f05e62
fixup! Vector2.scale_by: Add example, document infix notation
nbraud Mar 23, 2019
d74cdab
Vector2: Provide proper code examples for unpacking, and accessing
nbraud Mar 23, 2019
54336e9
README: Drop the documentation of “convenience functions”
nbraud Mar 23, 2019
dea1c9e
Work on the Vector typevar
AstraLuma Mar 23, 2019
14752b1
README: Drop documentation of “Mathematical operators”
nbraud Mar 23, 2019
941d1b1
docs: Add an annotation to Vector with the actual declaration
AstraLuma Mar 23, 2019
8a85914
Vector2.__eq__: Reference convert()/vector-like in docstring
nbraud Mar 23, 2019
ed127db
Vector2.__eq__: Drop the ambiguous & unhelpful definition
nbraud Mar 23, 2019
158cf09
docs/Vector: Add a cross-reference to typing.TypeVar
nbraud Mar 23, 2019
af39e54
docs/Vector: Fix minor typo
nbraud Mar 23, 2019
cb4c3e8
docs: Change title to “PPB's 2D Vector class”
nbraud Mar 23, 2019
f057795
Cirrus CI: Add a task for building documentation
nbraud Mar 23, 2019
5fc3584
fixup! Cirrus CI: Add a task for building documentation
nbraud Mar 23, 2019
e815e72
fixup! Cirrus CI: Add a task for building documentation
nbraud Mar 23, 2019
a52160a
Vector2: Add cross-references to the relevant protocols in docstring
nbraud Mar 23, 2019
b09e3fd
Vector2: Sort [indexing, unpacking] in class docstring
nbraud Mar 23, 2019
470ee19
Vector2: Add examples of conversions to lists and tuples
nbraud Mar 23, 2019
c687b20
Vector2.asdict: Add docstring
nbraud Mar 23, 2019
8c5e70b
Vector2: Move comparison of scale and normalize to the latter's doc
nbraud Mar 23, 2019
cdc00a7
Vector2.normalize: Replace redundant display with assert in example
nbraud Mar 23, 2019
5d31e92
Revert "Vector2: Add cross-references to the relevant protocols in do…
nbraud Mar 23, 2019
83f6612
Vector2.isclose: Replace outputting `True` with an assertion
nbraud Mar 23, 2019
811f6b9
Vector2: Fix indentation in class docstring
nbraud Mar 23, 2019
d51a958
docs/Vector: Clarify what Vector is used for.
nbraud Mar 24, 2019
f6d1e41
Cirrus CI: Do not perform builds for Bors' temporary branches
nbraud Mar 24, 2019
554f4c0
Bors: Configure required CI checks
nbraud Mar 24, 2019
2418d64
Merge branch 'qa/bors' into sphinx
nbraud Mar 24, 2019
41b34d5
Cirrus CI: Do not build docs on Bors temporary branches
nbraud Mar 24, 2019
7d56285
Bors: Require docs to build successfully
nbraud Mar 24, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .cirrus.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
docs_task:
skip: $CIRRUS_BRANCH =~ '.*\.tmp'
container:
image: python:3.7-slim

install_script:
- apt update && apt install make
- pip install --upgrade-strategy eager -U -r docs-requirements.txt
- pip install -e .

script:
- make -C docs/ html

lint_task:
skip: $CIRRUS_BRANCH =~ '.*\.tmp'
container:
image: python:3.7-slim

Expand All @@ -15,6 +29,7 @@ lint_task:


FreeBSD_task:
skip: $CIRRUS_BRANCH =~ '.*\.tmp'
freebsd_instance:
image: freebsd-12-0-release-amd64
env:
Expand All @@ -37,6 +52,7 @@ FreeBSD_task:
- ./test.sh

Linux_task:
skip: $CIRRUS_BRANCH =~ '.*\.tmp'
allow_failures: $CIRRUS_TASK_NAME =~ '.*-rc-.*'
container:
matrix:
Expand All @@ -56,6 +72,7 @@ Linux_task:
- ./test.sh

macOS_task:
skip: $CIRRUS_BRANCH =~ '.*\.tmp'
osx_instance:
image: mojave-base
env:
Expand All @@ -81,6 +98,7 @@ macOS_task:
- ./test.sh

Windows_task:
skip: $CIRRUS_BRANCH =~ '.*\.tmp'
allow_failures: $CIRRUS_TASK_NAME =~ '.*-rc-.*'
windows_container:
os_version: 2019
Expand Down
206 changes: 6 additions & 200 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# ppb-vector
The 2D Vector Class for the PursuedPyBear project.
The immutable, 2D vector class for the PursuedPyBear project.

`Vector2` implements many convenience features, as well as
useful mathematical operations for 2D geometry.

## Install

Expand All @@ -17,204 +20,7 @@ pip install 'ppb-vector'
>>> Vector2(3, 4)
Vector2(3.0, 4.0)

`Vector2` implements many convenience features, as well as
useful mathematical operations for 2D geometry and linear algebra.


## Convenience functions

### Unpacking

>>> x, y = Vector2(1, 3)
>>> print(x)
1.0
>>> print(y)
3.0

### Access Values

Convenient access to `Vector2` members via dot notation, indexes, or keys.

>>> my_vector = Vector2(2, 3)
>>> my_vector.x
2.0
>>> my_vector[1]
3.0
>>> my_vector["x"]
2.0

Also iterable for translation between Vector2 and other sequence types.

>>> tuple(Vector2(2, 3))
(2.0, 3.0)


## Mathematical operators

In addition to `Vector2`, operators also accepts, as second operand,
vector-like objects such as `tuple`, `list`, and `dict`.

>>> Vector2(1, 1) + [1, 3]
Vector2(2.0, 4.0)

>>> Vector2(1, 1) + (2, 4)
Vector2(3.0, 5.0)

>>> Vector2(1, 1) + {"x": 3, "y": 5}
Vector2(4.0, 6.0)


### Addition

>>> Vector2(1, 0) + (0, 1)
Vector2(1.0, 1.0)

### Subtraction

>>> Vector2(3, 3) - (1, 1)
Vector2(2.0, 2.0)

### Equality

Vectors are equal if their coordinates are equal.

>>> Vector2(1, 0) == (0, 1)
False

### Scalar Multiplication

Multiply a `Vector2` by a scalar to get a scaled `Vector2`:

>>> 3 * Vector2(1, 1)
Vector2(3.0, 3.0)

>>> Vector2(1, 1) * 3
Vector2(3.0, 3.0)

>>> Vector2(1, 1).scale_by(3)
Vector2(3.0, 3.0)


It is also possible to divide a `Vector2` by a scalar:

>>> Vector2(3, 3) / 3
Vector2(1.0, 1.0)

### Dot Product

Multiply a `Vector2` by another `Vector2` to get the dot product.

>>> Vector2(1, 1) * (-1, -1)
-2.0

### Vector Length

>>> Vector2(45, 60).length
75.0

### Negation

Negating a `Vector2` is equivalent to multiplying it by -1.

>>> -Vector2(1, 1)
Vector2(-1.0, -1.0)


## Methods

Useful functions for game development.

### isclose(vector)

Perform an approximate comparison of two vectors.

>>> Vector2(1, 0).isclose((1, 1e-10))
True

`Vector2.isclose` takes optional, keyword arguments, akin to those of
`math.isclose`:
- `abs_tol` (absolute tolerance) is the minimum magnitude (of the difference
vector) under which two inputs are considered close, without consideration for
(the magnitude of) the input values.
- `rel_tol` (relative tolerance) is the relative error: if the length of the
difference vector is less than `rel_tol * input.length` for any `input`,
the two vectors are considered close.
- `rel_to` is an iterable of additional vector-likes whose length (times
`rel_tol`) is compared to the length of the difference vector.

By default, `abs_tol = 1e-3`, `rel_tol = 1e-6`, and `rel_to = []`.

### rotate(deg)

Rotate a vector in relation to its own origin and return a new `Vector2`.

>>> Vector2(1, 0).rotate(90)
Vector2(0.0, 1.0)

Positive rotation is counter/anti-clockwise.

### angle(vector)

Compute the angle between two vectors, expressed as a scalar in degrees.

>>> Vector2(1, 0).angle( (0, 1) )
90.0

As with `rotate()`, angles are signed, and refer to a direct coordinate system
(i.e. positive rotations are counter-clockwise).

`Vector2.angle` is guaranteed to produce an angle between -180° and 180°.

### normalize()

Return a vector with the same direction, and unit length.

>>> Vector2(3, 4).normalize()
Vector2(0.6, 0.8)

### scale(scalar)

Scale given `Vector2` to a given length.

>>> Vector2(7, 24).scale(2)
Vector2(0.56, 1.92)

Note that `Vector2.normalize()` is equivalent to `Vector2.scale(1)`.

>>> Vector2(7, 24).normalize()
Vector2(0.28, 0.96)
>>> Vector2(7, 24).scale(1)
Vector2(0.28, 0.96)

### truncate(scalar)

Scale a given `Vector2` down to a given length, if it is larger.

>>> Vector2(7, 24).truncate(3)
Vector2(0.84, 2.88)

Note that `Vector2.scale` is equivalent to `Vector2.truncate` when `scalar` is
less than length.

>>> Vector2(3, 4).scale(4)
Vector2(2.4, 3.2)
>>> Vector2(3, 4).truncate(4)
Vector2(2.4, 3.2)

>>> Vector2(3, 4).scale(6)
Vector2(3.6, 4.8)
>>> Vector2(3, 4).truncate(6)
Vector2(3.0, 4.0)

Note: `x.truncate(max_length)` may sometimes be slightly-larger than
`max_length`, due to floating-point rounding effects.

### reflect(surface_normal)

Reflect a `Vector2` based on a given surface normal.

>>> Vector2(5, 3).reflect( (-1, 0) )
Vector2(-5.0, 3.0)
See the [online documentation] for an overview of the functionality.

>>> Vector2(5, 3).reflect( Vector2(-1, -2).normalize() )
Vector2(0.5999999999999996, -5.800000000000001)
[online documentation]: https://ppb-vector.readthedocs.io/en/latest/
12 changes: 12 additions & 0 deletions bors.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
status = [
"docs",
"FreeBSD PYTHON:3.6",
"FreeBSD PYTHON:3.7",
"lint",
"Linux container:python:3.6-slim",
"Linux container:python:3.7-slim",
"Windows container:python:3.6-windowsservercore-1809",
"Windows container:python:3.7-windowsservercore-1809",
"macOS PYTHON:3.6.8",
"macOS PYTHON:3.7.2",
]
3 changes: 3 additions & 0 deletions docs-requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
sphinx
sphinx-autodoc-annotation
sphinx_rtd_theme
1 change: 1 addition & 0 deletions docs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/_build/
19 changes: 19 additions & 0 deletions docs/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Minimal makefile for Sphinx documentation
#

# You can set these variables from the command line.
SPHINXOPTS =
SPHINXBUILD = sphinx-build
SOURCEDIR = .
BUILDDIR = _build

# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

.PHONY: help Makefile

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
Loading