session-py 0.261.0__tar.gz → 0.263.0__tar.gz
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.
- {session_py-0.261.0 → session_py-0.263.0}/PKG-INFO +1 -1
- {session_py-0.261.0 → session_py-0.263.0}/pyproject.toml +1 -1
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/__init__.py +6 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/color.py +12 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/color_test.py +14 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/line.py +80 -5
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/line_test.py +42 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/polyline.py +33 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/polyline_test.py +33 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/session.py +20 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/session_test.py +26 -0
- session_py-0.263.0/src/session_py/text.py +258 -0
- session_py-0.263.0/src/session_py/text_test.py +92 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/vector.py +5 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/vector_test.py +15 -0
- session_py-0.263.0/src/session_py/viewer.py +608 -0
- session_py-0.263.0/src/session_py/viewer_test.py +186 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/xform.py +78 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/xform_test.py +18 -0
- {session_py-0.261.0 → session_py-0.263.0}/uv.lock +1 -15
- {session_py-0.261.0 → session_py-0.263.0}/.github/FUNDING.yml +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/.github/workflows/publish.yml +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/.github/workflows/test.yml +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/.gitignore +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/.gitmodules +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/README.md +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/conftest.py +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/examples/bench.py +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/examples/bvh_demo.py +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/examples/loft_holes.py +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/examples/nurbsurface.py +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/serialization/.gitkeep +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/aabb.py +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/aabb_test.py +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/boolean_polyline.py +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/boolean_polyline_test.py +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/brep.py +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/brep_test.py +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/closest.py +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/closest_test.py +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/collection.py +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/collection_test.py +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/convex_hull.py +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/convex_hull_test.py +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/element.py +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/element_test.py +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/file_encoders.py +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/file_encoders_test.py +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/file_obj.py +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/file_obj_test.py +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/file_step.py +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/file_step_test.py +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/file_xyz.py +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/file_xyz_test.py +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/graph.py +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/graph_test.py +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/history.py +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/history_test.py +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/instance_ref.py +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/instance_ref_test.py +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/interaction.py +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/interaction_test.py +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/intersection.py +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/intersection_test.py +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/matrix.py +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/matrix_test.py +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/mesh.py +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/mesh_test.py +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/mini_test.py +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/nurbscurve.py +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/nurbscurve_test.py +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/nurbsknot.py +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/nurbsknot_test.py +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/nurbssurface.py +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/nurbssurface_test.py +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/nurbssurface_trimmed.py +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/nurbssurface_trimmed_test.py +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/obb.py +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/obb_test.py +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/objects.py +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/objects_test.py +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/plane.py +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/plane_test.py +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/point.py +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/point_test.py +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/pointcloud.py +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/pointcloud_test.py +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/primitives.py +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/primitives_test.py +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/proto/.gitattributes +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/proto/__init__.py +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/proto/boundingbox_pb2.py +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/proto/brep_pb2.py +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/proto/color_pb2.py +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/proto/element_pb2.py +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/proto/file_encoders_pb2.py +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/proto/graph_edge_pb2.py +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/proto/graph_pb2.py +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/proto/graph_vertex_pb2.py +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/proto/instance_ref_pb2.py +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/proto/interaction_pb2.py +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/proto/line_pb2.py +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/proto/matrix_pb2.py +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/proto/mesh_pb2.py +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/proto/nurbscurve_pb2.py +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/proto/nurbssurface_pb2.py +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/proto/nurbssurface_trimmed_pb2.py +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/proto/objects_pb2.py +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/proto/plane_pb2.py +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/proto/point_pb2.py +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/proto/pointcloud_pb2.py +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/proto/polyline_pb2.py +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/proto/quaternion_pb2.py +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/proto/session_pb2.py +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/proto/sheet_pb2.py +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/proto/tolerance_pb2.py +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/proto/tree_pb2.py +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/proto/treenode_pb2.py +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/proto/vector_pb2.py +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/proto/xform_pb2.py +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/py.typed +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/quaternion.py +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/quaternion_test.py +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/reload.py +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/remesh_cdt.py +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/remesh_cdt_test.py +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/remesh_nurbssurface_adaptive.py +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/remesh_nurbssurface_adaptive_test.py +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/remesh_nurbssurface_grid.py +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/remesh_nurbssurface_grid_test.py +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/session_config.py +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/session_config_test.py +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/spatial_aabbtree.py +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/spatial_aabbtree_test.py +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/spatial_bvh.py +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/spatial_bvh_test.py +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/spatial_kdtree.py +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/spatial_kdtree_test.py +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/spatial_octree.py +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/spatial_octree_test.py +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/spatial_rtree.py +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/spatial_rtree_test.py +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/split.py +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/split_test.py +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/tolerance.py +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/tolerance_test.py +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/tree.py +0 -0
- {session_py-0.261.0 → session_py-0.263.0}/src/session_py/tree_test.py +0 -0
|
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "session_py"
|
|
7
|
-
version = "0.
|
|
7
|
+
version = "0.263.0"
|
|
8
8
|
description = "A minimal Python geometry library"
|
|
9
9
|
authors = [{name = "Petras Vestartas", email = "petrasvestartas@gmail.com"}]
|
|
10
10
|
license = {text = "MIT"}
|
|
@@ -15,6 +15,7 @@ from .point import Point
|
|
|
15
15
|
from .vector import Vector
|
|
16
16
|
from .plane import Plane
|
|
17
17
|
from .line import Line
|
|
18
|
+
from .line import Arrowhead
|
|
18
19
|
from .instance_ref import InstanceRef
|
|
19
20
|
from .interaction import Interaction
|
|
20
21
|
from .interaction import InteractionUnknown
|
|
@@ -31,6 +32,8 @@ from .objects import Objects
|
|
|
31
32
|
from .objects import Component
|
|
32
33
|
from .history import History
|
|
33
34
|
from .session import Session
|
|
35
|
+
from .text import Text
|
|
36
|
+
from .viewer import show
|
|
34
37
|
from .mesh import Mesh
|
|
35
38
|
from .mesh import NormalWeighting
|
|
36
39
|
from .aabb import AABB
|
|
@@ -81,6 +84,7 @@ __all__ = [
|
|
|
81
84
|
"Vector",
|
|
82
85
|
"Plane",
|
|
83
86
|
"Line",
|
|
87
|
+
"Arrowhead",
|
|
84
88
|
"InstanceRef",
|
|
85
89
|
"Interaction",
|
|
86
90
|
"InteractionUnknown",
|
|
@@ -139,4 +143,6 @@ __all__ = [
|
|
|
139
143
|
"ConvexHull",
|
|
140
144
|
"SpatialKDTree",
|
|
141
145
|
"SpatialOctree",
|
|
146
|
+
"Text",
|
|
147
|
+
"show",
|
|
142
148
|
]
|
|
@@ -301,6 +301,18 @@ class Color:
|
|
|
301
301
|
"""Construct from [r, g, b, a]."""
|
|
302
302
|
return cls(arr[0], arr[1], arr[2], arr[3])
|
|
303
303
|
|
|
304
|
+
@staticmethod
|
|
305
|
+
def lerp(a: Color, b: Color, t: float) -> Color:
|
|
306
|
+
"""Return the color at parameter t in [0, 1] between a and b, named after a."""
|
|
307
|
+
|
|
308
|
+
return Color(
|
|
309
|
+
a.r + (b.r - a.r) * t,
|
|
310
|
+
a.g + (b.g - a.g) * t,
|
|
311
|
+
a.b + (b.b - a.b) * t,
|
|
312
|
+
a.a + (b.a - a.a) * t,
|
|
313
|
+
a.name,
|
|
314
|
+
)
|
|
315
|
+
|
|
304
316
|
# ═══════════════════════════════════════════════════════════════════════════
|
|
305
317
|
# JSON
|
|
306
318
|
# ═══════════════════════════════════════════════════════════════════════════
|
|
@@ -113,6 +113,20 @@ def test_color_conversion():
|
|
|
113
113
|
MINI_CHECK(back == c)
|
|
114
114
|
|
|
115
115
|
|
|
116
|
+
@MINI_TEST("Color", "Lerp")
|
|
117
|
+
def test_color_lerp():
|
|
118
|
+
from session_py import Color
|
|
119
|
+
|
|
120
|
+
a = Color(0.0, 0.0, 0.0, 1.0)
|
|
121
|
+
b = Color(1.0, 0.5, 0.0, 0.0)
|
|
122
|
+
c = Color.lerp(a, b, 0.5)
|
|
123
|
+
|
|
124
|
+
MINI_CHECK(TOLERANCE.is_close(c.r, 0.5))
|
|
125
|
+
MINI_CHECK(TOLERANCE.is_close(c.g, 0.25))
|
|
126
|
+
MINI_CHECK(TOLERANCE.is_close(c.b, 0.0))
|
|
127
|
+
MINI_CHECK(TOLERANCE.is_close(c.a, 0.5))
|
|
128
|
+
|
|
129
|
+
|
|
116
130
|
@MINI_TEST("Color", "Presets")
|
|
117
131
|
def test_color_presets():
|
|
118
132
|
from session_py import Color
|
|
@@ -4,6 +4,7 @@ import copy
|
|
|
4
4
|
import json
|
|
5
5
|
import math
|
|
6
6
|
import uuid
|
|
7
|
+
from enum import IntEnum
|
|
7
8
|
from .color import Color
|
|
8
9
|
from .point import Point
|
|
9
10
|
from .tolerance import Tolerance
|
|
@@ -16,6 +17,36 @@ if TYPE_CHECKING:
|
|
|
16
17
|
from .xform import Xform
|
|
17
18
|
|
|
18
19
|
|
|
20
|
+
class Arrowhead(IntEnum):
|
|
21
|
+
"""Which ends of a curve carry an arrowhead."""
|
|
22
|
+
|
|
23
|
+
NONE = 0 # No arrowhead.
|
|
24
|
+
START = 1 # Arrowhead at the start.
|
|
25
|
+
END = 2 # Arrowhead at the end.
|
|
26
|
+
BOTH = 3 # Arrowheads at both ends.
|
|
27
|
+
|
|
28
|
+
def flipped(self) -> Arrowhead:
|
|
29
|
+
"""Return the arrowhead with start and end swapped."""
|
|
30
|
+
|
|
31
|
+
if self is Arrowhead.START:
|
|
32
|
+
return Arrowhead.END
|
|
33
|
+
|
|
34
|
+
if self is Arrowhead.END:
|
|
35
|
+
return Arrowhead.START
|
|
36
|
+
|
|
37
|
+
return self
|
|
38
|
+
|
|
39
|
+
def joined(self, last: Arrowhead) -> Arrowhead:
|
|
40
|
+
"""Return the start head of self combined with the end head of last."""
|
|
41
|
+
return Arrowhead((self.value & 1) | (last.value & 2))
|
|
42
|
+
|
|
43
|
+
def piece(self, first: bool, last: bool) -> Arrowhead:
|
|
44
|
+
"""Return the heads a split piece keeps."""
|
|
45
|
+
return (self if first else Arrowhead.NONE).joined(
|
|
46
|
+
self if last else Arrowhead.NONE
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
|
|
19
50
|
class Line:
|
|
20
51
|
"""A 3D line segment with display width, dash pattern and color."""
|
|
21
52
|
|
|
@@ -33,6 +64,7 @@ class Line:
|
|
|
33
64
|
"width",
|
|
34
65
|
"dash",
|
|
35
66
|
"linecolor",
|
|
67
|
+
"arrowhead",
|
|
36
68
|
)
|
|
37
69
|
|
|
38
70
|
# ═══════════════════════════════════════════════════════════════════════════
|
|
@@ -62,6 +94,7 @@ class Line:
|
|
|
62
94
|
self.width = 1.0 # Display width.
|
|
63
95
|
self.dash = [] # Dash pattern lengths.
|
|
64
96
|
self.linecolor = Color.black() # Display color.
|
|
97
|
+
self.arrowhead = Arrowhead.NONE # Arrowhead ends.
|
|
65
98
|
|
|
66
99
|
def __deepcopy__(self, memo):
|
|
67
100
|
"""Copy with a new guid and the same data."""
|
|
@@ -73,6 +106,7 @@ class Line:
|
|
|
73
106
|
result.width = self.width
|
|
74
107
|
result.dash = list(self.dash)
|
|
75
108
|
result.linecolor = copy.deepcopy(self.linecolor, memo)
|
|
109
|
+
result.arrowhead = self.arrowhead
|
|
76
110
|
memo[id(self)] = result
|
|
77
111
|
|
|
78
112
|
return result
|
|
@@ -281,7 +315,7 @@ class Line:
|
|
|
281
315
|
raise IndexError("Index out of bounds")
|
|
282
316
|
|
|
283
317
|
def __eq__(self, other) -> bool:
|
|
284
|
-
"""Compare name, coordinates to 1e-6, width and
|
|
318
|
+
"""Compare name, coordinates to 1e-6, width, linecolor and arrowhead; guid ignored."""
|
|
285
319
|
|
|
286
320
|
if not isinstance(other, Line):
|
|
287
321
|
return False
|
|
@@ -298,10 +332,11 @@ class Line:
|
|
|
298
332
|
and round(self._z1 * 1000000.0) == round(other._z1 * 1000000.0)
|
|
299
333
|
and round(self.width * 1000000.0) == round(other.width * 1000000.0)
|
|
300
334
|
and self.linecolor == other.linecolor
|
|
335
|
+
and self.arrowhead == other.arrowhead
|
|
301
336
|
)
|
|
302
337
|
|
|
303
338
|
def __ne__(self, other) -> bool:
|
|
304
|
-
"""Compare name, coordinates to 1e-6, width and
|
|
339
|
+
"""Compare name, coordinates to 1e-6, width, linecolor and arrowhead; guid ignored."""
|
|
305
340
|
return not self == other
|
|
306
341
|
|
|
307
342
|
def __iadd__(self, other: Vector) -> Line:
|
|
@@ -385,8 +420,18 @@ class Line:
|
|
|
385
420
|
return result
|
|
386
421
|
|
|
387
422
|
def __neg__(self) -> Line:
|
|
388
|
-
"""Return a flipped copy (end to start)."""
|
|
389
|
-
|
|
423
|
+
"""Return a flipped copy (end to start, arrowhead ends swapped)."""
|
|
424
|
+
|
|
425
|
+
result = Line(self._x1, self._y1, self._z1, self._x0, self._y0, self._z0)
|
|
426
|
+
result.name = self.name
|
|
427
|
+
result.is_visible = self.is_visible
|
|
428
|
+
result.is_locked = self.is_locked
|
|
429
|
+
result.width = self.width
|
|
430
|
+
result.dash = list(self.dash)
|
|
431
|
+
result.linecolor = copy.deepcopy(self.linecolor)
|
|
432
|
+
result.arrowhead = self.arrowhead.flipped()
|
|
433
|
+
|
|
434
|
+
return result
|
|
390
435
|
|
|
391
436
|
# ═══════════════════════════════════════════════════════════════════════════
|
|
392
437
|
# Transformation
|
|
@@ -522,6 +567,22 @@ class Line:
|
|
|
522
567
|
|
|
523
568
|
return (output_start, output_end)
|
|
524
569
|
|
|
570
|
+
@staticmethod
|
|
571
|
+
def lerp(a: Line, b: Line, t: float) -> Line:
|
|
572
|
+
"""Return a copy of a with each end at parameter t in [0, 1] between the ends of a and b."""
|
|
573
|
+
|
|
574
|
+
s = Point.lerp(a.start(), b.start(), t)
|
|
575
|
+
e = Point.lerp(a.end(), b.end(), t)
|
|
576
|
+
result = a.duplicate()
|
|
577
|
+
result._x0 = s[0]
|
|
578
|
+
result._y0 = s[1]
|
|
579
|
+
result._z0 = s[2]
|
|
580
|
+
result._x1 = e[0]
|
|
581
|
+
result._y1 = e[1]
|
|
582
|
+
result._z1 = e[2]
|
|
583
|
+
|
|
584
|
+
return result
|
|
585
|
+
|
|
525
586
|
@staticmethod
|
|
526
587
|
def from_projected_points(line: Line, points: list[Point]) -> Line | None:
|
|
527
588
|
"""Compute the extreme sub-segment of line spanned by the projected points; None when empty."""
|
|
@@ -650,7 +711,7 @@ class Line:
|
|
|
650
711
|
def __jsondump__(self) -> dict:
|
|
651
712
|
"""Serialize to a JSON object."""
|
|
652
713
|
|
|
653
|
-
|
|
714
|
+
data = {
|
|
654
715
|
"dash": list(self.dash),
|
|
655
716
|
"guid": self.guid,
|
|
656
717
|
"is_locked": self.is_locked,
|
|
@@ -667,6 +728,11 @@ class Line:
|
|
|
667
728
|
"z1": self._z1,
|
|
668
729
|
}
|
|
669
730
|
|
|
731
|
+
if self.arrowhead != Arrowhead.NONE:
|
|
732
|
+
data["arrowhead"] = self.arrowhead.name.lower()
|
|
733
|
+
|
|
734
|
+
return dict(sorted(data.items()))
|
|
735
|
+
|
|
670
736
|
@classmethod
|
|
671
737
|
def __jsonload__(
|
|
672
738
|
cls, data: dict, guid: str | None = None, name: str | None = None
|
|
@@ -692,6 +758,11 @@ class Line:
|
|
|
692
758
|
if "width" in data:
|
|
693
759
|
line.width = data["width"]
|
|
694
760
|
|
|
761
|
+
if "arrowhead" in data:
|
|
762
|
+
line.arrowhead = Arrowhead.__members__.get(
|
|
763
|
+
data["arrowhead"].upper(), Arrowhead.NONE
|
|
764
|
+
)
|
|
765
|
+
|
|
695
766
|
return line
|
|
696
767
|
|
|
697
768
|
def file_json_dumps(self) -> str:
|
|
@@ -750,6 +821,7 @@ class Line:
|
|
|
750
821
|
proto.linecolor_rgba.append(self.linecolor.b)
|
|
751
822
|
proto.linecolor_rgba.append(self.linecolor.a)
|
|
752
823
|
proto.linecolor_name = self.linecolor.name
|
|
824
|
+
proto.arrowhead = int(self.arrowhead)
|
|
753
825
|
|
|
754
826
|
return proto
|
|
755
827
|
|
|
@@ -790,6 +862,9 @@ class Line:
|
|
|
790
862
|
if proto.linecolor_name:
|
|
791
863
|
line.linecolor.name = proto.linecolor_name
|
|
792
864
|
|
|
865
|
+
if 0 < proto.arrowhead < 4:
|
|
866
|
+
line.arrowhead = Arrowhead(proto.arrowhead)
|
|
867
|
+
|
|
793
868
|
return line
|
|
794
869
|
|
|
795
870
|
def pb_dumps(self) -> bytes:
|
|
@@ -7,6 +7,7 @@ from .tolerance import TOLERANCE
|
|
|
7
7
|
|
|
8
8
|
@MINI_TEST("Line", "Constructor")
|
|
9
9
|
def test_line_constructor():
|
|
10
|
+
from session_py import Arrowhead
|
|
10
11
|
from session_py import Color
|
|
11
12
|
from session_py import Line
|
|
12
13
|
from session_py import Point
|
|
@@ -114,34 +115,51 @@ def test_line_constructor():
|
|
|
114
115
|
MINI_CHECK(l_pdl[0] == 0.0 and l_pdl[3] == 5.0)
|
|
115
116
|
MINI_CHECK(lc.linecolor[0] == 1.0 and lc.linecolor[1] == 0.0 and lc.width == 2.5)
|
|
116
117
|
MINI_CHECK(lwn.name == "custom" and lwn[3] == 1.0)
|
|
118
|
+
la = Line()
|
|
119
|
+
la.arrowhead = Arrowhead.END
|
|
120
|
+
lacopy = la.duplicate()
|
|
121
|
+
laneg = -la
|
|
122
|
+
laother = Line()
|
|
123
|
+
|
|
124
|
+
MINI_CHECK(la.arrowhead == Arrowhead.END and lacopy == la and la != laother)
|
|
125
|
+
MINI_CHECK(laneg.arrowhead == Arrowhead.START)
|
|
126
|
+
MINI_CHECK(Arrowhead.BOTH.piece(True, False) == Arrowhead.START)
|
|
127
|
+
MINI_CHECK(Arrowhead.START.joined(Arrowhead.END) == Arrowhead.BOTH)
|
|
117
128
|
MINI_CHECK(TOLERANCE.is_close(ms[1], 1.0) and TOLERANCE.is_close(me[1], 1.0))
|
|
118
129
|
|
|
119
130
|
|
|
120
131
|
@MINI_TEST("Line", "Transformation")
|
|
121
132
|
def test_line_transformation():
|
|
133
|
+
from session_py import Arrowhead
|
|
122
134
|
from session_py import Line
|
|
123
135
|
from session_py import Xform
|
|
124
136
|
|
|
125
137
|
line = Line(0.0, 0.0, 0.0, 1.0, 0.0, 0.0)
|
|
138
|
+
line.arrowhead = Arrowhead.BOTH
|
|
126
139
|
xform = Xform.translation(10.0, 0.0, 0.0)
|
|
127
140
|
moved = line.transformed(xform)
|
|
128
141
|
line.transform(xform)
|
|
129
142
|
|
|
130
143
|
MINI_CHECK(moved[0] == 10.0 and moved[3] == 11.0)
|
|
131
144
|
MINI_CHECK(line[0] == 10.0 and line[3] == 11.0)
|
|
145
|
+
MINI_CHECK(moved.arrowhead == Arrowhead.BOTH and line.arrowhead == Arrowhead.BOTH)
|
|
132
146
|
|
|
133
147
|
|
|
134
148
|
@MINI_TEST("Line", "Json Roundtrip")
|
|
135
149
|
def test_line_json_roundtrip():
|
|
136
150
|
from pathlib import Path
|
|
151
|
+
from session_py import Arrowhead
|
|
137
152
|
from session_py import Line
|
|
138
153
|
|
|
139
154
|
line = Line(42.1, 84.2, 126.3, 168.4, 210.5, 252.6)
|
|
140
155
|
line.name = "test_line"
|
|
141
156
|
line.dash = [3.0, 2.0]
|
|
157
|
+
line.arrowhead = Arrowhead.END
|
|
142
158
|
|
|
143
159
|
j = line.__jsondump__()
|
|
144
160
|
loaded_j = Line.__jsonload__(j)
|
|
161
|
+
unknown = dict(j)
|
|
162
|
+
unknown["arrowhead"] = "sideways"
|
|
145
163
|
|
|
146
164
|
s = line.file_json_dumps()
|
|
147
165
|
loaded_s = Line.file_json_loads(s)
|
|
@@ -162,16 +180,21 @@ def test_line_json_roundtrip():
|
|
|
162
180
|
MINI_CHECK(TOLERANCE.is_close(loaded[4], 210.5))
|
|
163
181
|
MINI_CHECK(TOLERANCE.is_close(loaded[5], 252.6))
|
|
164
182
|
MINI_CHECK(loaded.dash == [3.0, 2.0])
|
|
183
|
+
MINI_CHECK(loaded.arrowhead == Arrowhead.END and loaded_j.arrowhead == Arrowhead.END)
|
|
184
|
+
MINI_CHECK("arrowhead" not in Line().__jsondump__())
|
|
185
|
+
MINI_CHECK(Line.__jsonload__(unknown).arrowhead == Arrowhead.NONE)
|
|
165
186
|
|
|
166
187
|
|
|
167
188
|
@MINI_TEST("Line", "Protobuf Roundtrip")
|
|
168
189
|
def test_line_protobuf_roundtrip():
|
|
169
190
|
from pathlib import Path
|
|
191
|
+
from session_py import Arrowhead
|
|
170
192
|
from session_py import Line
|
|
171
193
|
|
|
172
194
|
line = Line(42.1, 84.2, 126.3, 168.4, 210.5, 252.6)
|
|
173
195
|
line.name = "test_line"
|
|
174
196
|
line.dash = [3.0, 2.0]
|
|
197
|
+
line.arrowhead = Arrowhead.END
|
|
175
198
|
|
|
176
199
|
guid = line.guid
|
|
177
200
|
s = line.pb_dumps()
|
|
@@ -181,6 +204,8 @@ def test_line_protobuf_roundtrip():
|
|
|
181
204
|
line.pb_dump(fname)
|
|
182
205
|
loaded = Line.pb_load(fname)
|
|
183
206
|
converted = Line.from_proto(line.to_proto())
|
|
207
|
+
outside = line.to_proto()
|
|
208
|
+
outside.arrowhead = 9
|
|
184
209
|
|
|
185
210
|
MINI_CHECK(loaded_s.name == "test_line")
|
|
186
211
|
MINI_CHECK(TOLERANCE.is_close(loaded_s[0], 42.1))
|
|
@@ -196,6 +221,8 @@ def test_line_protobuf_roundtrip():
|
|
|
196
221
|
MINI_CHECK(loaded.guid == guid)
|
|
197
222
|
MINI_CHECK(converted == line)
|
|
198
223
|
MINI_CHECK(converted.guid == guid)
|
|
224
|
+
MINI_CHECK(loaded.arrowhead == Arrowhead.END)
|
|
225
|
+
MINI_CHECK(Line.from_proto(outside).arrowhead == Arrowhead.NONE)
|
|
199
226
|
|
|
200
227
|
|
|
201
228
|
@MINI_TEST("Line", "Length")
|
|
@@ -247,6 +274,21 @@ def test_line_point_at():
|
|
|
247
274
|
MINI_CHECK(pe[0] == 10.0 and pe[1] == 10.0 and pe[2] == 10.0)
|
|
248
275
|
|
|
249
276
|
|
|
277
|
+
@MINI_TEST("Line", "Lerp")
|
|
278
|
+
def test_line_lerp():
|
|
279
|
+
from session_py import Line
|
|
280
|
+
from session_py import Point
|
|
281
|
+
|
|
282
|
+
a = Line(0.0, 0.0, 0.0, 1.0, 0.0, 0.0)
|
|
283
|
+
a.width = 3.0
|
|
284
|
+
b = Line(0.0, 2.0, 0.0, 1.0, 4.0, 0.0)
|
|
285
|
+
half = Line.lerp(a, b, 0.5)
|
|
286
|
+
|
|
287
|
+
MINI_CHECK(TOLERANCE.is_point_close(half.start(), Point(0.0, 1.0, 0.0)))
|
|
288
|
+
MINI_CHECK(TOLERANCE.is_point_close(half.end(), Point(1.0, 2.0, 0.0)))
|
|
289
|
+
MINI_CHECK(half.width == 3.0)
|
|
290
|
+
|
|
291
|
+
|
|
250
292
|
@MINI_TEST("Line", "Closest Point")
|
|
251
293
|
def test_line_closest_point():
|
|
252
294
|
from session_py import Line
|
|
@@ -1444,6 +1444,39 @@ class Polyline:
|
|
|
1444
1444
|
|
|
1445
1445
|
return result
|
|
1446
1446
|
|
|
1447
|
+
def resampled(self, count: int) -> Polyline:
|
|
1448
|
+
"""Return a copy with count points at equal arc-length spacing, first and last kept."""
|
|
1449
|
+
|
|
1450
|
+
if count < 2 or self.point_count() < 2:
|
|
1451
|
+
return self.duplicate()
|
|
1452
|
+
|
|
1453
|
+
total = self.length()
|
|
1454
|
+
result = self.duplicate()
|
|
1455
|
+
result.coords = []
|
|
1456
|
+
result.add_point(self.get_point(0))
|
|
1457
|
+
|
|
1458
|
+
for i in range(1, count - 1):
|
|
1459
|
+
result.add_point(self._point_at_length(total * float(i) / float(count - 1)))
|
|
1460
|
+
|
|
1461
|
+
result.add_point(self.get_point(self.point_count() - 1))
|
|
1462
|
+
|
|
1463
|
+
return result
|
|
1464
|
+
|
|
1465
|
+
@staticmethod
|
|
1466
|
+
def morph(a: Polyline, b: Polyline, t: float) -> Polyline:
|
|
1467
|
+
"""Return the pointwise blend at t, the polyline with fewer points resampled to the larger count."""
|
|
1468
|
+
|
|
1469
|
+
count = max(a.point_count(), b.point_count())
|
|
1470
|
+
pa = a.resampled(count)
|
|
1471
|
+
pb = b.resampled(count)
|
|
1472
|
+
result = a.duplicate()
|
|
1473
|
+
result.coords = []
|
|
1474
|
+
|
|
1475
|
+
for i in range(min(pa.point_count(), pb.point_count())):
|
|
1476
|
+
result.add_point(Point.lerp(pa.get_point(i), pb.get_point(i), t))
|
|
1477
|
+
|
|
1478
|
+
return result
|
|
1479
|
+
|
|
1447
1480
|
@staticmethod
|
|
1448
1481
|
def interpolate_points(
|
|
1449
1482
|
from_pt: Point, to_pt: Point, steps: int, kind: int = 0
|
|
@@ -829,6 +829,39 @@ def test_polyline_tween():
|
|
|
829
829
|
MINI_CHECK(TOLERANCE.is_close(tweened.get_point(1)[0], 2.0))
|
|
830
830
|
|
|
831
831
|
|
|
832
|
+
@MINI_TEST("Polyline", "Morph")
|
|
833
|
+
def test_polyline_morph():
|
|
834
|
+
from session_py import Polyline
|
|
835
|
+
from session_py import Point
|
|
836
|
+
|
|
837
|
+
pl = Polyline(
|
|
838
|
+
[
|
|
839
|
+
Point(0.0, 0.0, 0.0),
|
|
840
|
+
Point(2.0, 0.0, 0.0),
|
|
841
|
+
Point(2.0, 2.0, 0.0),
|
|
842
|
+
]
|
|
843
|
+
)
|
|
844
|
+
line = Polyline(
|
|
845
|
+
[
|
|
846
|
+
Point(0.0, 0.0, 1.0),
|
|
847
|
+
Point(1.0, 0.0, 1.0),
|
|
848
|
+
Point(2.0, 0.0, 1.0),
|
|
849
|
+
Point(3.0, 0.0, 1.0),
|
|
850
|
+
Point(4.0, 0.0, 1.0),
|
|
851
|
+
]
|
|
852
|
+
)
|
|
853
|
+
resampled = pl.resampled(5)
|
|
854
|
+
morphed = Polyline.morph(pl, line, 0.5)
|
|
855
|
+
|
|
856
|
+
MINI_CHECK(resampled.point_count() == 5)
|
|
857
|
+
MINI_CHECK(TOLERANCE.is_point_close(resampled.get_point(1), Point(1.0, 0.0, 0.0)))
|
|
858
|
+
MINI_CHECK(TOLERANCE.is_point_close(resampled.get_point(2), Point(2.0, 0.0, 0.0)))
|
|
859
|
+
MINI_CHECK(TOLERANCE.is_point_close(resampled.get_point(3), Point(2.0, 1.0, 0.0)))
|
|
860
|
+
MINI_CHECK(morphed.point_count() == 5)
|
|
861
|
+
MINI_CHECK(TOLERANCE.is_point_close(morphed.get_point(2), Point(2.0, 0.0, 0.5)))
|
|
862
|
+
MINI_CHECK(Polyline.morph(pl, line, 0.0) == resampled)
|
|
863
|
+
|
|
864
|
+
|
|
832
865
|
@MINI_TEST("Polyline", "Average Plane")
|
|
833
866
|
def test_polyline_average_plane():
|
|
834
867
|
from session_py import Polyline
|
|
@@ -58,6 +58,7 @@ if TYPE_CHECKING:
|
|
|
58
58
|
from pathlib import Path
|
|
59
59
|
from .color import Color
|
|
60
60
|
from .matrix import Matrix
|
|
61
|
+
from .text import Text
|
|
61
62
|
from .proto import session_pb2
|
|
62
63
|
|
|
63
64
|
|
|
@@ -944,6 +945,12 @@ class Session:
|
|
|
944
945
|
"""Add a matrix as its component (type_name Matrix, the matrix's guid), placed by set_xform on that guid; a guid already live adds nothing and returns the node that guid has."""
|
|
945
946
|
return self.add_component(matrix.to_component(), parent)
|
|
946
947
|
|
|
948
|
+
def add_text(
|
|
949
|
+
self, text: Text, parent: TreeNode | None = None
|
|
950
|
+
) -> TreeNode:
|
|
951
|
+
"""Add text as its component (type_name Text, the text's guid), placed by set_xform on that guid."""
|
|
952
|
+
return self.add_component(text.to_component(), parent)
|
|
953
|
+
|
|
947
954
|
def add_definition(self, definition: Any) -> str:
|
|
948
955
|
"""Add a definition, geometry in its own frame that instances share; returns its guid, also when that guid is already defined, and "" for None or a guid an object, instance or component holds."""
|
|
949
956
|
|
|
@@ -1492,6 +1499,19 @@ class Session:
|
|
|
1492
1499
|
self.bvh_cache_dirty = True
|
|
1493
1500
|
self.revision += 1
|
|
1494
1501
|
|
|
1502
|
+
def animate_xform(
|
|
1503
|
+
self,
|
|
1504
|
+
guid: str,
|
|
1505
|
+
xform: Xform,
|
|
1506
|
+
duration_ms: float = 650.0,
|
|
1507
|
+
delay_ms: float = 0.0,
|
|
1508
|
+
) -> None:
|
|
1509
|
+
"""Set a local transform and record its presentation duration and delay."""
|
|
1510
|
+
|
|
1511
|
+
self.set_xform(guid, xform)
|
|
1512
|
+
self.graph.set_vertex_attribute(guid, "xform_ms", duration_ms)
|
|
1513
|
+
self.graph.set_vertex_attribute(guid, "delay_ms", delay_ms)
|
|
1514
|
+
|
|
1495
1515
|
def remove_xform(self, guid: str) -> bool:
|
|
1496
1516
|
"""Removes an object's local transform, returning whether one was present."""
|
|
1497
1517
|
|
|
@@ -3685,5 +3685,31 @@ def test_session_set_node_color_descendants():
|
|
|
3685
3685
|
MINI_CHECK(point.color == Color.red())
|
|
3686
3686
|
|
|
3687
3687
|
|
|
3688
|
+
@MINI_TEST("Session", "Animate Xform")
|
|
3689
|
+
def test_session_animate_xform():
|
|
3690
|
+
from session_py import Point
|
|
3691
|
+
from session_py import Session
|
|
3692
|
+
from session_py import Xform
|
|
3693
|
+
|
|
3694
|
+
session = Session()
|
|
3695
|
+
point = Point(1.0, 2.0, 3.0)
|
|
3696
|
+
guid = point.guid
|
|
3697
|
+
xform = Xform.translation(4.0, 5.0, 6.0)
|
|
3698
|
+
session.add_point(point)
|
|
3699
|
+
session.animate_xform(
|
|
3700
|
+
guid,
|
|
3701
|
+
xform,
|
|
3702
|
+
900.0,
|
|
3703
|
+
150.0,
|
|
3704
|
+
)
|
|
3705
|
+
restored = Session.pb_loads(session.pb_dumps())
|
|
3706
|
+
duration = restored.graph.vertex_attribute(guid, "xform_ms")
|
|
3707
|
+
delay = restored.graph.vertex_attribute(guid, "delay_ms")
|
|
3708
|
+
|
|
3709
|
+
MINI_CHECK(restored.xform(guid) == xform)
|
|
3710
|
+
MINI_CHECK(duration == 900.0)
|
|
3711
|
+
MINI_CHECK(delay == 150.0)
|
|
3712
|
+
|
|
3713
|
+
|
|
3688
3714
|
if __name__ == "__main__":
|
|
3689
3715
|
run_all(language="python")
|