Skip to content

Commit 7ebd1b7

Browse files
committed
Implement Line2 docstrings
* docs/Geometry.rst - Use autoclass for Line2 * pygorithm/geometry/axisall.py - fix incorrect tuple syntax, add missing vartypes on ivars * pygorithm/geometry/line2.py - skeleton code * pygorithm/geometry/vector2.py - add missing vartypes on ivars, add magnitude_squared.
1 parent 7677d64 commit 7ebd1b7

File tree

4 files changed

+340
-96
lines changed

4 files changed

+340
-96
lines changed

docs/Geometry.rst

Lines changed: 3 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -66,97 +66,10 @@ Vector2
6666
Line2
6767
-----
6868

69-
.. class:: Line2
70-
71-
Defines a two-dimensional directed line segment defined by two points.
72-
This class is mostly used as a way to cache information that is
73-
regularly required when working on geometrical problems.
74-
75-
.. note::
76-
77-
Lines should be used as if they were completely immutable to ensure
78-
correctness. All attributes of Line2 can be reconstructed from the two
79-
points, and thus cannot be changed on their own and must be recalculated
80-
if there were any changes to `start` or `end`.
81-
82-
.. note::
83-
84-
To prevent unnecessary recalculations, many functions on lines accept an
85-
'offset' argument, which is used to perform calculations on lines that
86-
are simply shifts of other lines.
87-
88-
.. attribute:: Line2.start
89-
90-
`Vector2` the start of this line
91-
92-
.. attribute:: Line2.end
93-
94-
`Vector2` the end of this line
95-
96-
.. attribute:: Line2.delta
97-
98-
`Vector2` from start to end
99-
100-
.. attribute:: Line2.axis
101-
102-
`Vector2` normalized `delta`
103-
104-
.. attribute:: Line2.normal
105-
106-
`Vector2` normalized normal of `axis`
107-
108-
.. attribute:: Line2.magnitude_squared
109-
110-
`numerical` square of the magnitude of the line
111-
112-
.. attribute:: Line2.magnitude
113-
114-
`numerical` magnitude of the line
115-
116-
.. attribute:: Line2.min_x
117-
118-
`numerical` minimum x-value on the line
119-
120-
.. attribute:: Line2.min_y
121-
122-
`numerical` minimum y-value on the line
123-
124-
.. attribute:: Line2.max_x
125-
126-
`numerical` maximum x-value on the line
127-
128-
.. attribute:: Line2.max_y
129-
130-
`numerical` maximum y-value on the line
131-
132-
.. attribute:: Line2.slope
133-
134-
`numerical` (including +inf and -inf) slope of the line
135-
136-
.. attribute:: Line2.y_intercept
137-
138-
`numerical or None` y_intercept of the line (or None if `vertical`)
139-
140-
.. attribute:: Line2.horizontal
141-
142-
`bool` true if ``slope == 0``, false otherwise
143-
144-
.. attribute:: Line2.vertical
145-
146-
`bool` true if ``slope == float('+inf') or slope == float('-inf')``, false otherwise
147-
148-
.. staticmethod:: intersects_line(line1, line2, offset1, offset2)
149-
150-
- **line1** - `Line2` first line
151-
- **line2** - `Line2` second line
152-
- **offset1** - `Vector2` offset of first line
153-
- **offset2** - `Vector2` offset of second line
154-
- **Return Value** - `bool, bool` touches, overlaps
69+
.. autoclass:: pygorithm.geometry.line2.Line2
70+
:members:
71+
:special-members:
15572

156-
Determines if the two lines at the specified offsets are touching and/or
157-
overlapping. Two lines touch if they share endpoints, two lines overlap
158-
if they intersect on any point that is not an endpoint.
159-
16073
Axis-Aligned Line
16174
-----------------
16275

pygorithm/geometry/axisall.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,11 @@ class AxisAlignedLine(object):
3939
into them.
4040
4141
:ivar axis: the axis this line is on
42+
:vartype axis: :class:`pygorithm.geometry.vector2.Vector2`
4243
:ivar min: the point closest to negative infinity
44+
:vartype min: :class:`numbers.Number`
4345
:ivar max: the point closest to positive infinity
46+
:vartype max: :class:`numbers.Number`
4447
"""
4548

4649
def __init__(self, axis, point1, point2):
@@ -77,8 +80,8 @@ def intersects(line1, line2):
7780
:type line1: :class:`pygorithm.geometry.axisall.AxisAlignedLine`
7881
:param line2: the second line
7982
:type line2: :class:`pygorithm.geometry.axisall.AxisAlignedLine`
80-
:returns: touching, overlapping
81-
:rtype: bool, bool
83+
:returns: (touching, overlapping)
84+
:rtype: (bool, bool)
8285
"""
8386

8487
pass
@@ -104,8 +107,8 @@ def find_intersection(line1, line2):
104107
:type line1: :class:`pygorithm.geometry.axisall.AxisAlignedLine`
105108
:param line2: the second line
106109
:type line2: :class:`pygorithm.geometry.axisall.AxisAlignedLine`
107-
:returns: touching, mtv against 1
108-
:rtype: bool, :class:`numbers.Number` or None
110+
:returns: (touching, mtv against 1)
111+
:rtype: (bool, :class:`numbers.Number` or None)
109112
"""
110113

111114
pass
@@ -125,7 +128,7 @@ def contains_point(line, point):
125128
:type line: :class:`pygorithm.geometry.axisall.AxisAlignedLine`
126129
:param point: the point
127130
:type point: :class:`numbers.Number`
128-
:returns: if the point is an edge of the line, if the point is contained by the line
129-
:rtype: bool, bool
131+
:returns: (if the point is an edge of the line, if the point is contained by the line)
132+
:rtype: (bool, bool)
130133
"""
131134
pass

0 commit comments

Comments
 (0)