Skip to content

Commit 436227b

Browse files
committed
Attempt to use autoclass
This is an attempt to use autoclass for axis-aligned line. This should be nearly parity and, to help compare, includes both the auto generated documentation and the old style documentation. This also fixes some non-command wording in axis-aligned line * docs/Geometry.rst - Fix incorrect reST and minor wording improvements. Also add autoclass for AxisAlignedLine. * pygorithm/geometry/axisall.py - Add function skeletons and (hopefully) something resembling parity to documentation in Geometry.rst
1 parent 507e8a0 commit 436227b

File tree

2 files changed

+153
-14
lines changed

2 files changed

+153
-14
lines changed

docs/Geometry.rst

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ Features
5959
Vector2
6060
-------
6161

62-
.. class: Vector2
62+
.. class:: Vector2
6363

6464
Defines a simple two-dimensional, mutable vector.
6565

@@ -229,12 +229,12 @@ Example:
229229
The named argument "degrees" or "radians" may be passed in to rotate
230230
this vector by the specified amount in degrees (or radians),
231231
respectively. If both are omitted, the first unnamed argument is
232-
assummed to be the amount to rotate in radians.
232+
assumed to be the amount to rotate in radians.
233233

234234
Additionally, the named argument "about" may be passed in to specify
235235
about what the vector should be rotated. If omitted then the first
236236
unconsumed unnamed argument is assumed to be the vector. If there are
237-
no unconsumed unamed arguments then the origin is assumed.
237+
no unconsumed unnamed arguments then the origin is assumed.
238238

239239
Examples:
240240

@@ -417,24 +417,24 @@ Defines an undirected two-dimensional line by an axis, a minimum and a maximum.
417417
.. note::
418418

419419
`min` and `max` are referring to nearness to negative and positive infinity,
420-
respectively. The absolute value of `min` may be larger than `max`.
420+
respectively. The absolute value of `min` may be larger than that of `max`.
421421

422422
.. note::
423423

424-
`AxisAlignedLine`s are an intermediary operation, so offsets should be baked
424+
AxisAlignedLines are an intermediary operation, so offsets should be baked
425425
into them.
426426

427-
.. attribute AxisAlignedLine.axis
427+
.. attribute:: AxisAlignedLine.axis
428428

429429
`Vector2` the axis this line is along.
430430

431-
.. attribute AxisAlignedLine.min
431+
.. attribute:: AxisAlignedLine.min
432432

433433
`numeric` the number (closest to negative infinity) that is still on this
434434
line when walked along the axis. If negative, it may have a greater absolute
435435
value than max and implies walking in the opposite direction of the axis.
436436

437-
.. attribute AxisAlignedLine.max
437+
.. attribute:: AxisAlignedLine.max
438438

439439
`numeric` the number (closest to positive infinity) that is still on this
440440
line when walked along the axis. If negative, it may have a smaller absolute
@@ -446,16 +446,18 @@ Defines an undirected two-dimensional line by an axis, a minimum and a maximum.
446446
- **point1** - `numeric` one point on this line
447447
- **point2** - `numeric` a different point on this line
448448

449-
Constructs an axis aligned line with the appropriate min and max.
449+
Construct an axis aligned line with the appropriate min and max.
450450

451451
.. staticmethod:: AxisAlignedLine.intersects(line1, line2)
452452

453453
- **line1** - `AxisAlignedLine` the first line
454454
- **line2** - `AxisAlignedLine` the second line
455455
- **Return Value** - `bool, bool` touching, overlapping
456456

457-
Determines if the two lines are touching and if they are, if
458-
they are overlapping.
457+
Determine if the two lines are touching and if they are, if
458+
they are overlapping. Lines are touching if they share only
459+
one end point, whereas they are overlapping if they share
460+
infinitely many points.
459461

460462
.. note::
461463

@@ -469,7 +471,7 @@ Defines an undirected two-dimensional line by an axis, a minimum and a maximum.
469471
- **line2** - `AxisAlignedLine` the second line
470472
- **Return Value** - `bool, numeric or None` touching, mtv against 1
471473

472-
Determines if the two lines are touching, and then returns the
474+
Determine if the two lines are touching, and then returns the
473475
minimum translation vector to move line 1 along axis. If the result
474476
is negative, it means line 1 should be moved in the opposite direction
475477
of the axis by the magnitude of the result.
@@ -484,11 +486,17 @@ Defines an undirected two-dimensional line by an axis, a minimum and a maximum.
484486

485487
- **line** - `AxisAlignedLine` the line
486488
- **point** - `numeric` the point
487-
- **Return Value** - `bool` if point is contained (or an edge of) the line
489+
- **Return Value** - `bool, bool` if point is contained, if the point is an edge
488490

489-
Determines if the line contains the specified point, which is assumed
491+
Determine if the line contains the specified point, which is assumed
490492
to be defined the same way as min and max.
491493

494+
Axis-Aligned Line (autogen)
495+
---------------------------
496+
497+
.. autoclass:: pygorithm.geometry.AxisAlignedLine
498+
:members:
499+
492500
Concave Polygon
493501
---------------
494502

pygorithm/geometry/axisall.py

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
"""
2+
axisall
3+
4+
Author: Timothy Moore
5+
6+
Defines a class for handling axis-aligned two-dimensional lines
7+
segments. This class simplifies intermediary calculations in
8+
SAT and similiar algorithms.
9+
10+
These are 2dimensional axis-aligned objects
11+
https://en.wikipedia.org/wiki/Axis-aligned_object
12+
"""
13+
14+
class AxisAlignedLine(object):
15+
"""
16+
Define an axis aligned line.
17+
18+
This class provides functions related to axis aligned lines as well as
19+
acting as a convienent container for them. In this context, an axis
20+
aligned line is a two-dimensional line that is defined by an axis and
21+
length on that axis, rather than two points. When working with two lines
22+
defined as such that have the same axis, many calculations are
23+
simplified.
24+
25+
.. note::
26+
27+
Though it requires the same amount of memory as a simple representation of
28+
a 2 dimensional line (4 numerics), it cannot describe all types of lines.
29+
All lines that can be defined this way intersect (0, 0).
30+
31+
.. note::
32+
33+
`min` and `max` are referring to nearness to negative and positive infinity,
34+
respectively. The absolute value of `min` may be larger than that of `max`.
35+
36+
.. note::
37+
38+
AxisAlignedLines are an intermediary operation, so offsets should be baked
39+
into them.
40+
41+
:ivar axis: the axis this line is on
42+
:ivar min: the point closest to negative infinity
43+
:ivar max: the point closest to positive infinity
44+
"""
45+
46+
def __init__(self, axis, point1, point2):
47+
"""
48+
Construct an axis aligned line with the appropriate min and max.
49+
50+
:param axis: axis this line is on
51+
:type axis: :class:`pygorithm.geometry.Vector2`
52+
:param point1: one point on this line
53+
:type point1: :class:`numbers.Number`
54+
:param point2: a different point on this line
55+
:type point2: :class:`numbers.Number`
56+
"""
57+
58+
pass
59+
60+
@staticmethod
61+
def intersects(line1, line2):
62+
"""
63+
Determine if the two lines intersect
64+
65+
Determine if the two lines are touching and if they are, if
66+
they are overlapping. Lines are touching if they share only
67+
one end point, whereas they are overlapping if they share
68+
infinitely many points.
69+
70+
.. note::
71+
72+
It is rarely faster to check intersection before finding intersection if
73+
you will need the minimum translation vector, since they do mostly
74+
the same operations.
75+
76+
:param line1: the first line
77+
:type line1: :class:`pygorithm.geometry.AxisAlignedLine`
78+
:param line2: the second line
79+
:type line2: :class:`pygorithm.geometry.AxisAlignedLine`
80+
:returns: touching, overlapping
81+
:rtype: bool, bool
82+
"""
83+
84+
pass
85+
86+
@staticmethod
87+
def find_intersection(line1, line2):
88+
"""
89+
Calculate the MTV between line1 and line2 to move line1
90+
91+
Determine if the two lines are touching, and then returns the
92+
minimum translation vector to move line 1 along axis. If the result
93+
is negative, it means line 1 should be moved in the opposite direction
94+
of the axis by the magnitude of the result.
95+
96+
Returns `true, None` if the lines are touching.
97+
98+
.. note::
99+
100+
Ensure your program correctly handles `true, None`
101+
102+
103+
:param line1: the first line
104+
:type line1: :class:`pygorithm.geometry.AxisAlignedLine`
105+
:param line2: the second line
106+
:type line2: :class:`pygorithm.geometry.AxisAlignedLine`
107+
:returns: touching, mtv against 1
108+
:rtype: bool, :class:`numbers.Number` or None
109+
"""
110+
111+
pass
112+
113+
@staticmethod
114+
def contains_point(line, point):
115+
"""
116+
Determine if the line contains the specified point.
117+
118+
The point must be defined the same way as min and max.
119+
120+
.. tip::
121+
122+
It is not possible for both returned booleans to be `True`.
123+
124+
:param line: the line
125+
:type line: :class:`pygorithm.geometry.AxisAlignedLine`
126+
:param point: the point
127+
: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
130+
"""
131+
pass

0 commit comments

Comments
 (0)