@@ -59,247 +59,10 @@ Features
59
59
Vector2
60
60
-------
61
61
62
- .. class :: Vector2
63
-
64
- Defines a simple two-dimensional, mutable vector.
65
-
66
- .. note ::
67
-
68
- Equality is not overriden on vectors, because it is expected that
69
- vectors will be used mutably by directly modifying x and y. However, all
70
- functions on vectors are immutable (they return a copy)
71
-
72
- .. attribute :: Vector2.x
73
-
74
- The first component of this vector. Mutation is allowed where appropriate.
75
-
76
- .. attribute :: Vector2.y
77
-
78
- The second component of this vector. Mutation is allowed where appropriate.
79
-
80
- .. method :: vector2.Vector2(self, *args, **kwargs)
81
-
82
- Accepts a pair of unnamed parameters, a pair of named x, y parameters,
83
- another Vector2, or a tuple with 2 numerics. Examples of each:
84
-
85
- .. code-block :: python
86
-
87
- from pygorithm.geometry import vector2
88
-
89
- # A pair of unnamed parameters
90
- vec1 = vector2.Vector2(0 , 5 )
91
-
92
- # A pair of named parameters
93
- vec2 = vector2.Vector2(x = 0 , y = 5 )
94
-
95
- # Another vector2
96
- vec3 = vector2.Vector2(vec2)
97
-
98
- # A tuple with two numerics
99
- vec4 = vector2.Vector2( (0 , 5 ) )
100
-
101
- The following operations on vectors are extremely common and rarely varied, and as such have
102
- operator support.
103
-
104
- .. method :: Vector2.__add__(self, other)
105
-
106
- - **other ** : `Vector2 ` the vector to add to this one
107
- - **Return Value ** : a new `Vector2 ` by component-based addition
108
-
109
- Adds the two vectors component wise. Example:
110
-
111
- .. code-block :: python
112
-
113
- from pygorithm.geometry import vector2
114
-
115
- vec1 = vector2.Vector2(0 , 3 )
116
- vec2 = vector2.Vector2(2 , 4 )
117
-
118
- vec3 = vec1 + vec2
119
-
120
- # prints <2, 7>
121
- print (vec3)
122
-
123
- .. method :: Vector2.__sub__(self, other)
124
-
125
- - **other ** : `Vector2 ` the vector to subtract from this one
126
- - **Return Value ** : a new `Vector2 ` by component-based subtraction
127
-
128
- Subtracts the two vectors component wise. Example:
129
-
130
- .. code-block :: python
131
-
132
- from pygorithm.geometry import vector2
133
-
134
- vec1 = vector2.Vector2(5 , 5 )
135
- vec2 = vector2.Vector2(2 , 3 )
136
-
137
- vec3 = vec1 - vec2
138
- vec4 = vec2 - vec1
139
-
140
- # prints <3, 2>
141
- print (vec3)
142
-
143
- # prints <2, 3>
144
- print (vec4)
145
-
146
- .. method :: Vector2.__mul__(self, scale_factor)
147
- .. method :: Vector2.__rmul__(self, scale_factor)
148
-
149
- - **scale_factor ** : `numeric ` the factor to multiply both components by
150
- - **Return Value ** : a new `Vector2 ` by component-based multiplication
151
-
152
- Scales the vector by the specified factor. Will throw an exception if
153
- scale_factor is not a numeric - it will not perform the dot product (use
154
- `dot ` for that) Examples:
155
-
156
- .. code-block :: python
157
-
158
- from pygorithm.geometry import vector2
159
-
160
- vec1 = vector2.Vector2(4 , 8 )
161
-
162
- vec2 = vec1 * 0.5
163
- vec3 = 2 * vec2
164
-
165
- # prints <2, 4>
166
- print (vec2)
167
-
168
- # prints <8, 16>
169
- print (vec3)
170
-
171
-
172
- .. method :: Vector2.__repr__(self)
173
-
174
- - **Return Value ** : an unambiguous representation of this vector
175
-
176
- .. code-block :: python
177
-
178
- from pygorithm.geometry import vector2
179
-
180
- vec = vector2.Vector2(3 , 5 )
181
-
182
- # prints vector2(x=3, y=5)
183
- print (repr (vec))
184
-
185
- .. method :: Vector2.__str__(self)
186
-
187
- - **Return Value ** : a human-readable representation of this vector
188
-
189
- .. code-block :: python
190
-
191
- from pygorithm.geometry import vector2
192
-
193
- vec = vector2.Vector2(7 , 11 )
194
-
195
- # prints <7, 11>
196
- print (str (vec))
197
-
198
- # also prints <7, 11>
199
- print (vec)
200
-
201
- .. method :: Vector2.dot(self, other)
202
-
203
- - **other ** : `vector2 ` to perform the dot product on
204
- - **Return Value ** : a numeric from the dot product of the two vectors
205
-
206
- The dot product of two vectors is calculated as so::
207
-
208
- Let v1 be a vector such that v1 = <v1_x, v1_y>
209
- Let v2 be a vector such that v2 = <v2_x, v2_y>
210
-
211
- v1 . v2 = v1_x * v2_x + v1_y * v2_y
212
-
213
- Example:
214
-
215
- .. code-block :: python
216
-
217
- from pygorithm.geometry import vector2
218
-
219
- vec1 = vector2.Vector2(3 , 5 )
220
- vec2 = vector2.Vector2(7 , 11 )
221
-
222
- dot_12 = vec1.dot(vec2)
223
-
224
- # prints 76
225
- print (dot_12)
226
-
227
- .. method :: Vector2.rotate(self, *args, **kwargs)
228
-
229
- The named argument "degrees" or "radians" may be passed in to rotate
230
- this vector by the specified amount in degrees (or radians),
231
- respectively. If both are omitted, the first unnamed argument is
232
- assumed to be the amount to rotate in radians.
233
-
234
- Additionally, the named argument "about" may be passed in to specify
235
- about what the vector should be rotated. If omitted then the first
236
- unconsumed unnamed argument is assumed to be the vector. If there are
237
- no unconsumed unnamed arguments then the origin is assumed.
238
-
239
- Examples:
240
-
241
- .. code-block :: python
242
-
243
- from pygorithm.geometry import vector2
244
- import math
245
-
246
- vec1 = vector2.Vector2(1 , 0 )
247
-
248
- vec2 = vec1.rotate(math.pi * 0.25 )
249
-
250
- # prints <0.707, 0.707>
251
- print (vec2)
252
-
253
- vec3 = vec1.rotate(degrees = 45 )
254
-
255
- # prints <0.707, 0.707>
256
- print (vec3)
257
-
258
- # The following operations are all identical
259
-
260
- vec4 = vec1.rotate(math.pi, vector2.Vector2(1 , 1 ))
261
- vec5 = vec1.rotate(radians = math.pi, about = vector2.Vector2(1 , 1 ))
262
- vec6 = vec1.rotate(degrees = 180 , about = vector2.Vector2(1 , 1 ))
263
- vec7 = vec1.rotate(vector2.Vector2(1 , 1 ), degrees = 180 )
264
-
265
- # prints <1, 2>
266
- print (vec4)
267
-
268
- .. method :: Vector2.normalize(self)
269
-
270
- - **Return Value ** : a `Vector2 ` in the same direction as this one with a magnitude of 1
271
-
272
- Example:
273
-
274
- .. code-block :: python
275
-
276
- from pygorithm.geometry import vector2
277
-
278
- vec1 = vector2.Vector2(2 , 0 )
279
-
280
- vec2 = vec1.normalize()
281
-
282
- # prints <1, 0>
283
- print (vec2)
284
-
285
- * Miscellaneous
286
-
287
- .. method :: vector2.magnitude(self)
288
-
289
- - **Return Value ** : a `numeric ` magnitude of this vector
290
-
291
- Example:
292
-
293
- .. code-block :: python
294
-
295
- from pygorithm.geometry import vector2
296
-
297
- vec1 = vector2.Vector2(3 , 4 )
298
- magn = vec1.magnitude()
62
+ .. autoclass :: pygorithm.geometry.vector2.Vector2
63
+ :members:
64
+ :special-members:
299
65
300
- # prints 5
301
- print (magn)
302
-
303
66
Line2
304
67
-----
305
68
@@ -399,6 +162,7 @@ Axis-Aligned Line
399
162
400
163
.. autoclass :: pygorithm.geometry.axisall.AxisAlignedLine
401
164
:members:
165
+ :special-members:
402
166
403
167
Concave Polygon
404
168
---------------
0 commit comments