engeom 0.1.1__cp38-abi3-musllinux_1_2_aarch64.whl → 0.2.1__cp38-abi3-musllinux_1_2_aarch64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
engeom/geom2.pyi CHANGED
@@ -1,8 +1,14 @@
1
1
  from __future__ import annotations
2
2
  import numpy
3
+ from typing import Iterable, Tuple, Type, TypeVar
3
4
 
5
+ from engeom.engeom import Resample
4
6
 
5
- class Vector2:
7
+ Transformable2 = TypeVar("Transformable2", Vector2, Point2, Iso2, SurfacePoint2)
8
+ PointOrVec2 = TypeVar("PointOrVec2", Point2, Vector2)
9
+
10
+
11
+ class Vector2(Iterable[float]):
6
12
  def __init__(self, x: float, y: float):
7
13
  """
8
14
 
@@ -22,7 +28,7 @@ class Vector2:
22
28
  def __rmul__(self, other: float) -> Vector2:
23
29
  ...
24
30
 
25
- def __add__(self, other: Vector2 | Point2) -> Vector2 | Point2:
31
+ def __add__(self, other: PointOrVec2) -> PointOrVec2:
26
32
  ...
27
33
 
28
34
  def __sub__(self, other: Vector2) -> Vector2:
@@ -40,8 +46,38 @@ class Vector2:
40
46
  """
41
47
  ...
42
48
 
49
+ def dot(self, other: Vector2) -> float:
50
+ """
51
+ Compute the dot product of two vectors.
52
+ """
53
+ ...
54
+
55
+ def cross(self, other: Vector2) -> float:
56
+ """
57
+ Compute the cross product of two vectors.
58
+ """
59
+ ...
60
+
61
+ def norm(self) -> float:
62
+ """
63
+ Compute the norm of the vector.
64
+ """
65
+ ...
66
+
67
+ def normalized(self) -> Vector2:
68
+ """
69
+ Return a normalized version of the vector.
70
+ """
71
+ ...
72
+
73
+ def angle_to(self, other: Vector2) -> float:
74
+ """
75
+ Compute the smallest angle between two vectors and return it in radians.
76
+ """
77
+ ...
78
+
43
79
 
44
- class Point2:
80
+ class Point2(Iterable[float]):
45
81
  def __init__(self, x: float, y: float):
46
82
  """
47
83
 
@@ -66,7 +102,7 @@ class Point2:
66
102
  """
67
103
  ...
68
104
 
69
- def __sub__(self, other: Vector2 | Point2) -> Vector2 | Point2:
105
+ def __sub__(self, other: PointOrVec2) -> PointOrVec2:
70
106
  ...
71
107
 
72
108
  def __add__(self, other: Vector2) -> Vector2:
@@ -79,6 +115,92 @@ class Point2:
79
115
  ...
80
116
 
81
117
 
118
+ class SurfacePoint2:
119
+ def __init__(self, x: float, y: float, nx: float, ny: float):
120
+ """
121
+
122
+ :param x:
123
+ :param y:
124
+ :param nx:
125
+ :param ny:
126
+ """
127
+ ...
128
+
129
+ @property
130
+ def point(self) -> Point2:
131
+ """
132
+ Get the coordinates of the point as a Point2 object.
133
+ :return: a Point2 object
134
+ """
135
+ ...
136
+
137
+ @property
138
+ def normal(self) -> Vector2:
139
+ """
140
+ Get the normal of the point as a Vector2 object.
141
+ :return: a Vector2 object
142
+ """
143
+ ...
144
+
145
+ def at_distance(self, distance: float) -> Point2:
146
+ """
147
+ Get the point at a distance along the normal from the surface point.
148
+ :param distance: the distance to move along the normal.
149
+ :return: the point at the distance along the normal.
150
+ """
151
+ ...
152
+
153
+ def scalar_projection(self, point: Point2) -> float:
154
+ """
155
+ Calculate the scalar projection of a point onto the axis defined by the surface point position and direction.
156
+ Positive values indicate that the point is in the normal direction from the surface point, while negative values
157
+ indicate that the point is in the opposite direction.
158
+
159
+ :param point: the point to calculate the projection of.
160
+ :return: the scalar projection of the point onto the normal.
161
+ """
162
+ ...
163
+
164
+ def projection(self, point: Point2) -> Point2:
165
+ """
166
+ Calculate the projection of a point onto the axis defined by the surface point position and direction.
167
+
168
+ :param point: the point to calculate the projection of.
169
+ :return: the projection of the point onto the plane.
170
+ """
171
+ ...
172
+
173
+ def reversed(self) -> SurfacePoint2:
174
+ """
175
+ Return a new surface point with the normal vector inverted, but the position unchanged.
176
+ :return: a new surface point with the inverted normal vector.
177
+ """
178
+ ...
179
+
180
+ def planar_distance(self, point: Point2) -> float:
181
+ """
182
+ Calculate the planar (non-normal) distance between the surface point and a point. This is complementary to the
183
+ scalar projection. A point is projected onto the plane defined by the position and normal of the surface point,
184
+ and the distance between the surface point position and the projected point is returned. The value will always
185
+ be positive.
186
+
187
+ :param point: the point to calculate the distance to.
188
+ :return: the planar distance between the surface point and the point.
189
+ """
190
+ ...
191
+
192
+ def shift_orthogonal(self, distance: float) -> SurfacePoint2:
193
+ """
194
+ Shift the surface point by a distance orthogonal to the normal vector. The direction of travel is the surface
195
+ point's normal vector rotated 90 degrees clockwise. For instance, if the normal vector is (0, 1), a positive
196
+ distance will move the point to the right and a negative distance will move the point to the left.
197
+
198
+ :param distance: the distance to shift the surface point.
199
+ :return: a new surface point shifted by the given distance.
200
+ """
201
+ ...
202
+
203
+
82
204
  class Iso2:
83
205
  def __init__(self, tx: float, ty: float, r: float):
84
206
  """
@@ -96,7 +218,7 @@ class Iso2:
96
218
  """
97
219
  ...
98
220
 
99
- def __matmul__(self, other: Iso2 | Vector2 | Point2) -> Iso2 | Vector2 | Point2:
221
+ def __matmul__(self, other: Transformable2) -> Transformable2:
100
222
  ...
101
223
 
102
224
  def inverse(self) -> Iso2:
@@ -130,10 +252,483 @@ class Iso2:
130
252
 
131
253
  class SvdBasis2:
132
254
 
133
- def __init__(self, points: numpy.ndarray[float], weights: numpy.ndarray[float] | None):
255
+ def __init__(
256
+ self,
257
+ points: numpy.ndarray[float],
258
+ weights: numpy.ndarray[float] | None = None
259
+ ):
134
260
  """
135
261
 
136
262
  :param points:
137
263
  :param weights:
138
264
  """
139
265
  ...
266
+
267
+
268
+ class CurveStation2:
269
+ """
270
+ A class representing a station along a curve in 3D space. The station is represented by a point on the curve, a
271
+ tangent (direction) vector, and a length along the curve.
272
+ """
273
+
274
+ @property
275
+ def point(self) -> Point2:
276
+ """ The 2d position in space on the curve. """
277
+ ...
278
+
279
+ @property
280
+ def direction(self) -> Vector2:
281
+ """ The tangent (direction) vector of the curve at the station. """
282
+ ...
283
+
284
+ @property
285
+ def normal(self) -> Vector2:
286
+ """ The normal vector of the curve at the station. """
287
+ ...
288
+
289
+ @property
290
+ def direction_point(self) -> SurfacePoint2:
291
+ """
292
+ A `SurfacePoint2` object representing the point on the curve and the curve's tangent/direction vector.
293
+ """
294
+ ...
295
+
296
+ @property
297
+ def surface_point(self) -> SurfacePoint2:
298
+ """
299
+ A `SurfacePoint2` object representing the point on the curve and the curve's normal vector.
300
+ """
301
+ ...
302
+
303
+ @property
304
+ def index(self) -> int:
305
+ """ The index of the previous vertex on the curve, at or before the station. """
306
+ ...
307
+
308
+ @property
309
+ def length_along(self) -> float:
310
+ """ The length along the curve from the start of the curve to the station. """
311
+ ...
312
+
313
+
314
+ class Curve2:
315
+ """
316
+ A class representing a curve in 2D space. The curve is defined by a set of vertices and the line segments between
317
+ them. In two dimensions, the curve also has the concepts of closed/open, surface direction, and hull.
318
+
319
+ """
320
+
321
+ def __init__(
322
+ self,
323
+ vertices: numpy.ndarray,
324
+ normals: numpy.ndarray | None = None,
325
+ tol: float = 1e-6,
326
+ force_closed: bool = False,
327
+ hull_ccw: bool = False,
328
+ ):
329
+ """
330
+ Create a 2d curve from a set of vertices and some additional options.
331
+
332
+ It's important to note that in 2d, a curve has a concept of a normal direction, built from the concept of
333
+ inside/outside defined through the winding order of the vertices. This extra information can allow a 2d curve
334
+ to model a manifold surface.
335
+
336
+ There are three ways to specify the winding order of the vertices:
337
+ 1. Control it manually by passing the vertices array with the rows already organized so that an exterior surface
338
+ is counter-clockwise.
339
+ 2. If the vertices represent an exterior shape, pass `hull_ccw=True` to have the constructor automatically
340
+ check the winding order and reverse it if point ordering in the convex hull does not match ordering in the
341
+ original array.
342
+ 3. Pass a `normals` array the same size as the `vertices` array, where the normals are non-zero vectors pointed
343
+ in the "outside" direction at each point. The constructor will reverse the winding if the majority of normals
344
+ do not point in the same direction as the winding.
345
+
346
+ :param vertices: a numpy array of shape (N, 2) representing the vertices of the curve.
347
+ :param normals: an optional numpy array of shape (N, 2) representing the normals of the curve associated with
348
+ each vertex.
349
+ :param tol: a tolerance value for the curve. If not provided, a default value of 1e-6 is used. This is the
350
+ distance at which two points are considered to be the same.
351
+ :param force_closed: If True, the curve will be closed even if the first and last points are not the same, which
352
+ will be done by adding a new point at the end of the array that is the same as the first point.
353
+ :param hull_ccw: If True, the constructor will check the winding order of the vertices and reverse it if the
354
+ convex hull of the points is not in the same order as the original array. This will do nothing if the `normals`
355
+ parameter is provided.
356
+ """
357
+ ...
358
+
359
+ def length(self) -> float:
360
+ """
361
+ Get the length of the curve.
362
+ :return: the length of the curve.
363
+ """
364
+ ...
365
+
366
+ def at_front(self) -> CurveStation2:
367
+ """
368
+ Get the station at the front of the curve.
369
+ :return: the station at the front of the curve.
370
+ """
371
+ ...
372
+
373
+ def at_back(self) -> CurveStation2:
374
+ """
375
+ Get the station at the back of the curve.
376
+ :return: the station at the back of the curve.
377
+ """
378
+ ...
379
+
380
+ def at_length(self, length: float) -> CurveStation2:
381
+ """
382
+ Get the station at a given length along the curve. Will throw a ValueError if the length is less than zero or
383
+ greater than the length of the curve.
384
+ :param length: the length along the curve.
385
+ :return: the station at the given length.
386
+ """
387
+ ...
388
+
389
+ def at_fraction(self, fraction: float) -> CurveStation2:
390
+ """
391
+ Get the station at a given fraction of the length of the curve. Will throw a ValueError if the fraction is less
392
+ than zero or greater than one.
393
+ :param fraction: the fraction of the length of the curve.
394
+ :return: the station at the given fraction.
395
+ """
396
+ ...
397
+
398
+ def at_closest_to_point(self, point: Point2) -> CurveStation2:
399
+ """
400
+ Get the station on the curve that is closest to a given point.
401
+ :param point: the point to find the closest station to.
402
+ :return: the station on the curve that is closest to the given point.
403
+ """
404
+ ...
405
+
406
+ @property
407
+ def is_closed(self) -> bool:
408
+ """
409
+ Check if the curve is closed.
410
+ :return: True if the curve is closed, False otherwise.
411
+ """
412
+ ...
413
+
414
+ def trim_front(self, length: float) -> Curve2:
415
+ """
416
+ Remove the front of the curve by a given length and return a new curve.
417
+ :param length: the length to trim from the front of the curve.
418
+ :return: a new curve with the front trimmed by the given length.
419
+ """
420
+ ...
421
+
422
+ def trim_back(self, length: float) -> Curve2:
423
+ """
424
+ Remove the back of the curve by a given length and return a new curve.
425
+ :param length: the length to trim from the back of the curve.
426
+ :return: a new curve with the back trimmed by the given length.
427
+ """
428
+ ...
429
+
430
+ def between_lengths(self, l0: float, l1: float) -> Curve2:
431
+ """
432
+ Attempt to get a new curve cut between two lengths along the curve. If the lengths are not valid, a ValueError
433
+ will be thrown.
434
+
435
+ If the curve is closed, the lengths will be wrapped around the curve. If the curve is not closed, the value
436
+ of `l0` must be less than `l1`. In either case, the lengths must be within the bounds of the curve.
437
+
438
+ :param l0: the start length.
439
+ :param l1: the end length.
440
+ :return: a new curve between the two lengths.
441
+ """
442
+ ...
443
+
444
+ def between_lengths_by_control(self, a: float, b: float, control: float) -> Curve2:
445
+ """
446
+ Attempt to get a new curve cut between two lengths along the curve, with a control point that will be used to
447
+ determine which side of the curve to keep. This is primarily helpful on closed curves when you can find a length
448
+ (usually via use of the `at_closest_to_point` method) that is on the side of the curve you want to keep.
449
+
450
+ If the lengths are not valid, a ValueError will be thrown.
451
+
452
+ :param a: the first length along the curve to cut
453
+ :param b: the second length along the curve to cut
454
+ :param control: a length along the curve that is on a point in the portion of the result that you want to keep
455
+ :return: a new curve between the two lengths
456
+ """
457
+
458
+ def reversed(self) -> Curve2:
459
+ """
460
+ Reverse the curve and return a new curve.
461
+ :return: a new curve with the vertices in reverse order.
462
+ """
463
+ ...
464
+
465
+ def make_hull(self) -> numpy.ndarray[float]:
466
+ """
467
+ Get the vertices of a convex hull of the curve, in counter-clockwise order.
468
+ :return: a numpy array of shape (N, 2) representing the convex hull of the curve.
469
+ """
470
+ ...
471
+
472
+ def max_point_in_direction(self, direction: Vector2) -> Tuple[int, Point2]:
473
+ """
474
+ Find the point on the curve that is furthest in a given direction.
475
+ :param direction: the direction to find the furthest point in.
476
+ :return: a tuple of the index of the point and the point itself.
477
+ """
478
+ ...
479
+
480
+ def max_distance_in_direction(self, surf_point: SurfacePoint2) -> float:
481
+ """
482
+ Find the maximum scalar projection of all vertices of the curve onto a surface point.
483
+ :param surf_point: the direction to find the furthest point in.
484
+ :return: the maximum scalar projection of all vertices of the curve onto a surface point.
485
+ """
486
+ ...
487
+
488
+ @property
489
+ def points(self) -> numpy.ndarray[float]:
490
+ """
491
+ Get the points of the curve.
492
+ :return: a numpy array of shape (N, 2) representing the points of the curve.
493
+ """
494
+ ...
495
+
496
+ def simplify(self, tol: float) -> Curve2:
497
+ """
498
+ Simplify the curve using the Ramer-Douglas-Peucker algorithm.
499
+ :param tol: the tolerance to use for simplification.
500
+ :return: a new curve with the simplified points.
501
+ """
502
+ ...
503
+
504
+ def resample(self, resample: Resample) -> Curve2:
505
+ """
506
+ Resample the curve using the given resampling method. The resampling method can be one of the following:
507
+
508
+ - `Resample.ByCount(count: int)`: resample the curve to have the given number of points.
509
+ - `Resample.BySpacing(distance: float)`: resample the curve to have points spaced by the given distance.
510
+ - `Resample.ByMaxSpacing(distance: float)`: resample the curve to have points spaced by a maximum distance.
511
+
512
+ :param resample: the resampling method to use.
513
+ :return: a new curve object with the resampled vertices.
514
+ """
515
+ ...
516
+
517
+ def transformed_by(self, transform: Iso2) -> Curve2:
518
+ """
519
+ Transform the curve by the given transform and return a new curve.
520
+ :param transform: the transform to apply to the curve.
521
+ :return: a new curve object with the transformed vertices.
522
+ """
523
+ ...
524
+
525
+
526
+ class Circle2:
527
+ def __init__(self, x: float, y: float, r: float):
528
+ """
529
+
530
+ :param x:
531
+ :param y:
532
+ :param r:
533
+ """
534
+ ...
535
+
536
+
537
+ @property
538
+ def center(self) -> Point2:
539
+ """
540
+ Get the center of the circle.
541
+ :return: the center of the circle.
542
+ """
543
+ ...
544
+
545
+ @property
546
+ def x(self) -> float:
547
+ """
548
+ Get the x-coordinate of the circle.
549
+ :return: the x-coordinate of the circle.
550
+ """
551
+ ...
552
+
553
+ @property
554
+ def y(self) -> float:
555
+ """
556
+ Get the y-coordinate of the circle.
557
+ :return: the y-coordinate of the circle.
558
+ """
559
+ ...
560
+
561
+ @property
562
+ def r(self) -> float:
563
+ """
564
+ Get the radius of the circle.
565
+ :return: the radius of the circle.
566
+ """
567
+ ...
568
+
569
+ @property
570
+ def aabb(self) -> Aabb2:
571
+ """
572
+ Get the axis-aligned bounding box of the circle.
573
+ :return: the axis-aligned bounding box of the circle.
574
+ """
575
+ ...
576
+
577
+
578
+ class Arc2:
579
+ def __init__(self, x: float, y: float, r: float, start_radians: float, sweep_radians: float):
580
+ """
581
+
582
+ :param x:
583
+ :param y:
584
+ :param r:
585
+ :param start_radians:
586
+ :param sweep_radians:
587
+ """
588
+
589
+ @property
590
+ def center(self) -> Point2:
591
+ """
592
+ Get the center of the arc.
593
+ :return: the center of the arc.
594
+ """
595
+ ...
596
+
597
+ @property
598
+ def x(self) -> float:
599
+ """
600
+ Get the x-coordinate of the arc.
601
+ :return: the x-coordinate of the arc.
602
+ """
603
+ ...
604
+
605
+ @property
606
+ def y(self) -> float:
607
+ """
608
+ Get the y-coordinate of the arc.
609
+ :return: the y-coordinate of the arc.
610
+ """
611
+ ...
612
+
613
+ @property
614
+ def r(self) -> float:
615
+ """
616
+ Get the radius of the arc.
617
+ :return: the radius of the arc.
618
+ """
619
+ ...
620
+
621
+ @property
622
+ def start(self) -> float:
623
+ """
624
+ Get the start angle of the arc in radians.
625
+ :return: the start angle of the arc in radians.
626
+ """
627
+ ...
628
+
629
+ @property
630
+ def sweep(self) -> float:
631
+ """
632
+ Get the sweep angle of the arc in radians.
633
+ :return: the sweep angle of the arc in radians.
634
+ """
635
+ ...
636
+
637
+ @property
638
+ def aabb(self) -> Aabb2:
639
+ """
640
+ Get the axis-aligned bounding box of the arc.
641
+ :return: the axis-aligned bounding box of the arc.
642
+ """
643
+ ...
644
+
645
+ @property
646
+ def start_point(self) -> Point2:
647
+ """
648
+ Get the start point of the arc.
649
+ :return: the start point of the arc.
650
+ """
651
+ ...
652
+
653
+ @property
654
+ def end_point(self) -> Point2:
655
+ """
656
+ Get the end point of the arc.
657
+ :return: the end point of the arc.
658
+ """
659
+ ...
660
+
661
+ class Aabb2:
662
+ def __init__(self, x_min: float, x_max: float, y_min: float, y_max: float):
663
+ """
664
+
665
+ :param x_min:
666
+ :param x_max:
667
+ :param y_min:
668
+ :param y_max:
669
+ """
670
+ ...
671
+
672
+ @staticmethod
673
+ def at_point(x: float, y: float, w: float, h: float | None = None) -> Aabb2:
674
+ """
675
+ Create an AABB centered at a point with a given width and height.
676
+ :param x: the x-coordinate of the center of the AABB.
677
+ :param y: the y-coordinate of the center of the AABB.
678
+ :param w: the width of the AABB.
679
+ :param h: the height of the AABB. If not provided, the AABB will be square.
680
+ :return: a new AABB object.
681
+ """
682
+ ...
683
+
684
+ @property
685
+ def min(self) -> Point2:
686
+ """
687
+ Get the minimum point of the AABB.
688
+ :return: the minimum point of the AABB.
689
+ """
690
+ ...
691
+
692
+ @property
693
+ def max(self) -> Point2:
694
+ """
695
+ Get the maximum point of the AABB.
696
+ :return: the maximum point of the AABB.
697
+ """
698
+ ...
699
+
700
+ @property
701
+ def center(self) -> Point2:
702
+ """
703
+ Get the center point of the AABB.
704
+ :return: the center point of the AABB.
705
+ """
706
+ ...
707
+
708
+ @property
709
+ def extent(self) -> Vector2:
710
+ """
711
+ Get the extent of the AABB.
712
+ :return: the extent of the AABB.
713
+ """
714
+ ...
715
+
716
+ def expand(self, d: float) -> Aabb2:
717
+ """
718
+ Expand the AABB by a given distance in all directions. The resulting height and
719
+ width will be increased by 2 * d.
720
+
721
+ :param d: the distance to expand the AABB by.
722
+ :return: a new AABB object with the expanded bounds.
723
+ """
724
+ ...
725
+
726
+ def shrink(self, d: float) -> Aabb2:
727
+ """
728
+ Shrink the AABB by a given distance in all directions. The resulting height and
729
+ width will be decreased by 2 * d.
730
+
731
+ :param d: the distance to shrink the AABB by.
732
+ :return: a new AABB object with the shrunk bounds.
733
+ """
734
+ ...