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

WiP: in-Python documentation #110

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
114 changes: 5 additions & 109 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,8 +20,6 @@ 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
Expand Down Expand Up @@ -51,7 +52,7 @@ Also iterable for translation between Vector2 and other sequence types.

## Mathematical operators

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

>>> Vector2(1, 1) + [1, 3]
Expand All @@ -64,23 +65,6 @@ vector-like objects such as `tuple`, `list`, and `dict`.
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`:
Expand All @@ -107,19 +91,6 @@ 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.
Expand All @@ -143,78 +114,3 @@ Perform an approximate comparison of two vectors.
`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)

>>> Vector2(5, 3).reflect( Vector2(-1, -2).normalize() )
Vector2(0.5999999999999996, -5.800000000000001)
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)
179 changes: 179 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
# -*- coding: utf-8 -*-
#
# Configuration file for the Sphinx documentation builder.
#
# This file does only contain a selection of the most common options. For a
# full list see the documentation:
# http://www.sphinx-doc.org/en/master/config

# -- Path setup --------------------------------------------------------------

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
# import os
# import sys
# sys.path.insert(0, os.path.abspath('.'))


# -- Project information -----------------------------------------------------

project = 'ppb-vector'
copyright = '2019, Piper Thunstrom, Jamie Bliss'
author = 'Piper Thunstrom, Jamie Bliss'

# The short X.Y version
version = ''
# The full version, including alpha/beta/rc tags
release = ''


# -- General configuration ---------------------------------------------------

# If your documentation needs a minimal Sphinx version, state it here.
#
# needs_sphinx = '1.0'

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.mathjax',
'sphinx.ext.viewcode',
]

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']

# The suffix(es) of source filenames.
# You can specify multiple suffix as a list of string:
#
# source_suffix = ['.rst', '.md']
source_suffix = '.rst'

# The master toctree document.
master_doc = 'index'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
#
# This is also used if you do content translation via gettext catalogs.
# Usually you set "language" from the command line for these cases.
language = None

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']

# The name of the Pygments (syntax highlighting) style to use.
pygments_style = None


# -- Options for HTML output -------------------------------------------------

# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'alabaster'

# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
# documentation.
#
# html_theme_options = {}

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']

# Custom sidebar templates, must be a dictionary that maps document names
# to template names.
#
# The default sidebars (for documents that don't match any pattern) are
# defined by theme itself. Builtin themes are using these templates by
# default: ``['localtoc.html', 'relations.html', 'sourcelink.html',
# 'searchbox.html']``.
#
# html_sidebars = {}


# -- Options for HTMLHelp output ---------------------------------------------

# Output file base name for HTML help builder.
htmlhelp_basename = 'ppb-vectordoc'


# -- Options for LaTeX output ------------------------------------------------

latex_elements = {
# The paper size ('letterpaper' or 'a4paper').
#
# 'papersize': 'letterpaper',

# The font size ('10pt', '11pt' or '12pt').
#
# 'pointsize': '10pt',

# Additional stuff for the LaTeX preamble.
#
# 'preamble': '',

# Latex figure (float) alignment
#
# 'figure_align': 'htbp',
}

# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
(master_doc, 'ppb-vector.tex', 'ppb-vector Documentation',
'Piper Thunstrom, Jamie Bliss', 'manual'),
]


# -- Options for manual page output ------------------------------------------

# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
(master_doc, 'ppb-vector', 'ppb-vector Documentation',
[author], 1)
]


# -- Options for Texinfo output ----------------------------------------------

# Grouping the document tree into Texinfo files. List of tuples
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
(master_doc, 'ppb-vector', 'ppb-vector Documentation',
author, 'ppb-vector', 'One line description of project.',
'Miscellaneous'),
]


# -- Options for Epub output -------------------------------------------------

# Bibliographic Dublin Core info.
epub_title = project

# The unique identifier of the text. This can be a ISBN number
# or the project homepage.
#
# epub_identifier = ''

# A unique identification for the text.
#
# epub_uid = ''

# A list of files that should not be packed into the epub file.
epub_exclude_files = ['search.html']


# -- Extension configuration -------------------------------------------------
20 changes: 20 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
.. ppb-vector documentation master file, created by
sphinx-quickstart on Sat Mar 23 14:10:03 2019.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.

Welcome to ppb-vector's documentation!
======================================

.. toctree::
:maxdepth: 2
:caption: Contents:



Indices and tables
==================

* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
Loading