Answers `p` as a 3D point. If it is already a list of 3 elements, then don't change and answer the original. If it's a smaller or larger list / tuple, then extend it. >>> point3D() # Default 3D origin (0pt, 0pt, 0pt) >>> point3D(pt(20, -40)) # Add z = pt(0) (20pt, -40pt, 0pt
(p=None)
| 56 | # P O I N T |
| 57 | |
| 58 | def point3D(p=None): |
| 59 | """Answers `p` as a 3D point. If it is already a list of 3 elements, then |
| 60 | don't change and answer the original. If it's a smaller or larger list / |
| 61 | tuple, then extend it. |
| 62 | |
| 63 | >>> point3D() # Default 3D origin |
| 64 | (0pt, 0pt, 0pt) |
| 65 | >>> point3D(pt(20, -40)) # Add z = pt(0) |
| 66 | (20pt, -40pt, 0pt) |
| 67 | >>> point3D(mm(30)) # One value defaults to x == y |
| 68 | (30mm, 30mm, 0pt) |
| 69 | >>> point3D(p(2,3,4,5)) # Trim tuple to 3 coordinates. |
| 70 | (2p, 3p, 4p) |
| 71 | """ |
| 72 | if not p: # None or zero. |
| 73 | return pt(0, 0, 0) # Undefined 3D point as list. |
| 74 | |
| 75 | if isinstance(p, (list, tuple)): |
| 76 | if len(p) > 3: |
| 77 | p = p[:3] |
| 78 | while len(p) < 3: |
| 79 | p += (pt(0),) # Value undefined, add origin as z value. |
| 80 | p = tuple(p) |
| 81 | else: |
| 82 | p = p, p, pt(0) |
| 83 | |
| 84 | return p |
| 85 | |
| 86 | def point2D(p=None): |
| 87 | """Answers the 2D point from a 2D or 3D point. |
no test coverage detected