splitting tests
This commit is contained in:
@@ -0,0 +1,89 @@
|
||||
import pytest
|
||||
from specklepy.objects.geometry.arc import Arc
|
||||
from specklepy.objects.geometry.plane import Plane
|
||||
from specklepy.objects.geometry.point import Point
|
||||
from specklepy.objects.geometry.vector import Vector
|
||||
from specklepy.objects.other import Transform
|
||||
from specklepy.objects.primitive import Interval
|
||||
from specklepy.core.api.operations import serialize, deserialize
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def sample_arc():
|
||||
plane = Plane(
|
||||
origin=Point(x=0, y=0, z=0, units="m"),
|
||||
normal=Vector(x=0, y=0, z=1, units="m"),
|
||||
xdir=Vector(x=1, y=0, z=0, units="m"),
|
||||
ydir=Vector(x=0, y=1, z=0, units="m"),
|
||||
units="m"
|
||||
)
|
||||
|
||||
return Arc(
|
||||
plane=plane,
|
||||
startPoint=Point(x=1, y=0, z=0, units="m"),
|
||||
midPoint=Point(x=0.7071, y=0.7071, z=0, units="m"),
|
||||
endPoint=Point(x=0, y=1, z=0, units="m"),
|
||||
domain=Interval.unit_interval(),
|
||||
units="m"
|
||||
)
|
||||
|
||||
|
||||
def test_arc_basic_properties(sample_arc):
|
||||
assert pytest.approx(sample_arc.radius, 0.001) == 1.0
|
||||
assert sample_arc.units == "m"
|
||||
|
||||
|
||||
def test_arc_transform(sample_arc):
|
||||
transform = Transform(matrix=[
|
||||
2, 0, 0, 1,
|
||||
0, 2, 0, 1,
|
||||
0, 0, 2, 1,
|
||||
0, 0, 0, 1
|
||||
], units="m")
|
||||
|
||||
success, transformed = sample_arc.transform_to(transform)
|
||||
assert success is True
|
||||
assert pytest.approx(transformed.radius, 0.001) == 2.0
|
||||
|
||||
|
||||
def test_arc_serialization(sample_arc):
|
||||
serialized = serialize(sample_arc)
|
||||
deserialized = deserialize(serialized)
|
||||
|
||||
assert deserialized.units == sample_arc.units
|
||||
assert pytest.approx(deserialized.radius, 0.001) == sample_arc.radius
|
||||
|
||||
assert pytest.approx(deserialized.startPoint.x,
|
||||
0.001) == sample_arc.startPoint.x
|
||||
assert pytest.approx(deserialized.startPoint.y,
|
||||
0.001) == sample_arc.startPoint.y
|
||||
assert pytest.approx(deserialized.startPoint.z,
|
||||
0.001) == sample_arc.startPoint.z
|
||||
|
||||
assert pytest.approx(deserialized.midPoint.x,
|
||||
0.001) == sample_arc.midPoint.x
|
||||
assert pytest.approx(deserialized.midPoint.y,
|
||||
0.001) == sample_arc.midPoint.y
|
||||
assert pytest.approx(deserialized.midPoint.z,
|
||||
0.001) == sample_arc.midPoint.z
|
||||
|
||||
assert pytest.approx(deserialized.endPoint.x,
|
||||
0.001) == sample_arc.endPoint.x
|
||||
assert pytest.approx(deserialized.endPoint.y,
|
||||
0.001) == sample_arc.endPoint.y
|
||||
assert pytest.approx(deserialized.endPoint.z,
|
||||
0.001) == sample_arc.endPoint.z
|
||||
|
||||
|
||||
def test_arc_measure(sample_arc):
|
||||
assert pytest.approx(sample_arc.measure, 0.001) == 1.5708
|
||||
|
||||
|
||||
def test_arc_length(sample_arc):
|
||||
assert pytest.approx(sample_arc.length, 0.001) == 1.5708
|
||||
|
||||
|
||||
def test_arc_domain(sample_arc):
|
||||
assert sample_arc.domain.start == 0.0
|
||||
assert sample_arc.domain.end == 1.0
|
||||
assert sample_arc._domain == sample_arc.domain
|
||||
@@ -1,379 +0,0 @@
|
||||
import unittest
|
||||
from specklepy.objects.geometry.point import Point
|
||||
from specklepy.objects.geometry.vector import Vector
|
||||
from specklepy.objects.geometry.line import Line
|
||||
from specklepy.objects.geometry.plane import Plane
|
||||
from specklepy.objects.geometry.arc import Arc
|
||||
from specklepy.objects.geometry.mesh import Mesh
|
||||
from specklepy.objects.geometry.polyline import Polyline
|
||||
from specklepy.objects.models.units import Units
|
||||
from specklepy.objects.other import Transform
|
||||
from specklepy.objects.primitive import Interval
|
||||
from specklepy.core.api.operations import serialize, deserialize
|
||||
|
||||
|
||||
class TestPoint(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.p1 = Point(x=1.0, y=2.0, z=3.0, units=Units.m)
|
||||
self.p2 = Point(x=4.0, y=6.0, z=8.0, units=Units.m)
|
||||
self.p3 = Point(x=1000.0, y=2000.0, z=3000.0, units=Units.mm)
|
||||
|
||||
def test_creation(self):
|
||||
self.assertEqual(self.p1.x, 1.0)
|
||||
self.assertEqual(self.p1.y, 2.0)
|
||||
self.assertEqual(self.p1.z, 3.0)
|
||||
self.assertEqual(self.p1.units, Units.m.value)
|
||||
|
||||
def test_distance_to(self):
|
||||
distance = self.p1.distance_to(self.p2)
|
||||
expected = ((3.0**2 + 4.0**2 + 5.0**2) ** 0.5)
|
||||
self.assertAlmostEqual(distance, expected)
|
||||
|
||||
distance = self.p1.distance_to(self.p3)
|
||||
self.assertAlmostEqual(distance, 0.0)
|
||||
|
||||
def test_transformation(self):
|
||||
transform = Transform(matrix=[
|
||||
2.0, 0.0, 0.0, 1.0,
|
||||
0.0, 2.0, 0.0, 1.0,
|
||||
0.0, 0.0, 2.0, 1.0,
|
||||
0.0, 0.0, 0.0, 1.0
|
||||
], units=Units.m)
|
||||
|
||||
success, transformed = self.p1.transform_to(transform)
|
||||
self.assertTrue(success)
|
||||
self.assertEqual(transformed.x, 3.0)
|
||||
self.assertEqual(transformed.y, 5.0)
|
||||
self.assertEqual(transformed.z, 7.0)
|
||||
|
||||
def test_serialization(self):
|
||||
serialized = serialize(self.p1)
|
||||
deserialized = deserialize(serialized)
|
||||
|
||||
self.assertEqual(deserialized.x, self.p1.x)
|
||||
self.assertEqual(deserialized.y, self.p1.y)
|
||||
self.assertEqual(deserialized.z, self.p1.z)
|
||||
self.assertEqual(deserialized.units, self.p1.units)
|
||||
|
||||
|
||||
class TestVector(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.v1 = Vector(x=1.0, y=2.0, z=3.0, units=Units.m)
|
||||
self.v2 = Vector(x=4.0, y=5.0, z=6.0, units=Units.m)
|
||||
|
||||
def test_creation(self):
|
||||
self.assertEqual(self.v1.x, 1.0)
|
||||
self.assertEqual(self.v1.y, 2.0)
|
||||
self.assertEqual(self.v1.z, 3.0)
|
||||
self.assertEqual(self.v1.units, Units.m.value)
|
||||
|
||||
def test_length(self):
|
||||
length = self.v1.length
|
||||
expected = (1.0**2 + 2.0**2 + 3.0**2) ** 0.5
|
||||
self.assertAlmostEqual(length, expected)
|
||||
|
||||
def test_transformation(self):
|
||||
transform = Transform(matrix=[
|
||||
2.0, 0.0, 0.0, 1.0,
|
||||
0.0, 2.0, 0.0, 1.0,
|
||||
0.0, 0.0, 2.0, 1.0,
|
||||
0.0, 0.0, 0.0, 1.0
|
||||
], units=Units.m)
|
||||
|
||||
success, transformed = self.v1.transform_to(transform)
|
||||
self.assertTrue(success)
|
||||
self.assertEqual(transformed.x, 2.0)
|
||||
self.assertEqual(transformed.y, 4.0)
|
||||
self.assertEqual(transformed.z, 6.0)
|
||||
|
||||
def test_serialization(self):
|
||||
serialized = serialize(self.v1)
|
||||
deserialized = deserialize(serialized)
|
||||
|
||||
self.assertEqual(deserialized.x, self.v1.x)
|
||||
self.assertEqual(deserialized.y, self.v1.y)
|
||||
self.assertEqual(deserialized.z, self.v1.z)
|
||||
self.assertEqual(deserialized.units, self.v1.units)
|
||||
|
||||
|
||||
class TestLine(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.p1 = Point(x=0.0, y=0.0, z=0.0, units=Units.m)
|
||||
self.p2 = Point(x=3.0, y=4.0, z=0.0, units=Units.m)
|
||||
self.line = Line(start=self.p1, end=self.p2, units=Units.m)
|
||||
|
||||
def test_creation(self):
|
||||
self.assertEqual(self.line.start.x, 0.0)
|
||||
self.assertEqual(self.line.end.x, 3.0)
|
||||
self.assertEqual(self.line.units, Units.m.value)
|
||||
|
||||
def test_length(self):
|
||||
self.assertEqual(self.line.length, 5.0)
|
||||
|
||||
def test_transformation(self):
|
||||
transform = Transform(matrix=[
|
||||
2.0, 0.0, 0.0, 1.0,
|
||||
0.0, 2.0, 0.0, 1.0,
|
||||
0.0, 0.0, 2.0, 1.0,
|
||||
0.0, 0.0, 0.0, 1.0
|
||||
], units=Units.m)
|
||||
|
||||
success, transformed = self.line.transform_to(transform)
|
||||
self.assertTrue(success)
|
||||
self.assertEqual(transformed.start.x, 1.0)
|
||||
self.assertEqual(transformed.end.x, 7.0)
|
||||
|
||||
def test_serialization(self):
|
||||
serialized = serialize(self.line)
|
||||
deserialized = deserialize(serialized)
|
||||
|
||||
self.assertEqual(deserialized.start.x, self.line.start.x)
|
||||
self.assertEqual(deserialized.end.x, self.line.end.x)
|
||||
self.assertEqual(deserialized.units, self.line.units)
|
||||
|
||||
|
||||
class TestPolyline(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.vertices = [0.0, 0.0, 0.0,
|
||||
1.0, 0.0, 0.0,
|
||||
1.0, 1.0, 0.0,
|
||||
0.0, 1.0, 0.0]
|
||||
self.polyline = Polyline(
|
||||
value=self.vertices,
|
||||
closed=True,
|
||||
units=Units.m,
|
||||
domain=Interval(start=0.0, end=1.0)
|
||||
)
|
||||
|
||||
def test_creation(self):
|
||||
self.assertEqual(len(self.polyline.value), 12)
|
||||
self.assertTrue(self.polyline.closed)
|
||||
self.assertEqual(self.polyline.units, Units.m.value)
|
||||
|
||||
def test_length(self):
|
||||
expected_length = 4.0
|
||||
self.assertAlmostEqual(self.polyline.length, expected_length)
|
||||
|
||||
def test_get_points(self):
|
||||
points = self.polyline.get_points()
|
||||
self.assertEqual(len(points), 4)
|
||||
self.assertEqual(points[0].x, 0.0)
|
||||
self.assertEqual(points[1].x, 1.0)
|
||||
|
||||
def test_transformation(self):
|
||||
transform = Transform(matrix=[
|
||||
2.0, 0.0, 0.0, 1.0,
|
||||
0.0, 2.0, 0.0, 1.0,
|
||||
0.0, 0.0, 2.0, 1.0,
|
||||
0.0, 0.0, 0.0, 1.0
|
||||
], units=Units.m)
|
||||
|
||||
success, transformed = self.polyline.transform_to(transform)
|
||||
self.assertTrue(success)
|
||||
points = transformed.get_points()
|
||||
self.assertEqual(points[0].x, 1.0)
|
||||
self.assertEqual(points[1].x, 3.0)
|
||||
|
||||
def test_serialization(self):
|
||||
serialized = serialize(self.polyline)
|
||||
deserialized = deserialize(serialized)
|
||||
|
||||
self.assertEqual(deserialized.value, self.polyline.value)
|
||||
self.assertEqual(deserialized.closed, self.polyline.closed)
|
||||
self.assertEqual(deserialized.units, self.polyline.units)
|
||||
|
||||
|
||||
class TestMesh(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.vertices = [
|
||||
0.0, 0.0, 0.0,
|
||||
1.0, 0.0, 0.0,
|
||||
1.0, 1.0, 0.0,
|
||||
0.0, 1.0, 0.0
|
||||
]
|
||||
self.faces = [3, 0, 1, 2, 3, 0, 2, 3]
|
||||
self.colors = [255, 0, 0, 255] * 4
|
||||
self.area = 1.0
|
||||
self.volume = 0.0
|
||||
|
||||
self.mesh = Mesh(
|
||||
vertices=self.vertices.copy(),
|
||||
faces=self.faces.copy(),
|
||||
colors=self.colors.copy(),
|
||||
units=Units.m,
|
||||
area=self.area,
|
||||
volume=self.volume
|
||||
)
|
||||
|
||||
def test_creation(self):
|
||||
self.assertEqual(self.mesh.vertices_count, 4)
|
||||
self.assertEqual(self.mesh.faces_count, 2)
|
||||
self.assertEqual(self.mesh.units, Units.m.value)
|
||||
self.assertEqual(self.mesh.area, self.area)
|
||||
self.assertEqual(self.mesh.volume, self.volume)
|
||||
|
||||
def test_get_point(self):
|
||||
point = self.mesh.get_point(1)
|
||||
self.assertEqual(point.x, 1.0)
|
||||
self.assertEqual(point.y, 0.0)
|
||||
self.assertEqual(point.z, 0.0)
|
||||
self.assertEqual(point.units, Units.m.value)
|
||||
|
||||
def test_get_face_vertices(self):
|
||||
face_vertices = self.mesh.get_face_vertices(0)
|
||||
self.assertEqual(len(face_vertices), 3)
|
||||
self.assertEqual(face_vertices[0].x, 0.0)
|
||||
self.assertEqual(face_vertices[1].x, 1.0)
|
||||
self.assertEqual(face_vertices[0].units, Units.m.value)
|
||||
|
||||
def test_transformation(self):
|
||||
transform = Transform(matrix=[
|
||||
2.0, 0.0, 0.0, 1.0,
|
||||
0.0, 2.0, 0.0, 1.0,
|
||||
0.0, 0.0, 2.0, 1.0,
|
||||
0.0, 0.0, 0.0, 1.0
|
||||
], units=Units.m)
|
||||
|
||||
test_mesh = Mesh(
|
||||
vertices=self.vertices.copy(),
|
||||
faces=self.faces.copy(),
|
||||
colors=self.colors.copy(),
|
||||
units=Units.m,
|
||||
area=1.0,
|
||||
volume=0.0
|
||||
)
|
||||
|
||||
success, transformed = test_mesh.transform_to(transform)
|
||||
|
||||
self.assertTrue(success)
|
||||
point = transformed.get_point(0)
|
||||
self.assertEqual(point.x, 1.0)
|
||||
self.assertEqual(point.y, 1.0)
|
||||
self.assertEqual(transformed.area, test_mesh.area)
|
||||
self.assertEqual(transformed.volume, test_mesh.volume)
|
||||
|
||||
def test_is_closed(self):
|
||||
self.assertFalse(self.mesh.is_closed())
|
||||
|
||||
def test_serialization(self):
|
||||
serialized = serialize(self.mesh)
|
||||
deserialized = deserialize(serialized)
|
||||
|
||||
self.assertEqual(deserialized.vertices, self.mesh.vertices)
|
||||
self.assertEqual(deserialized.faces, self.mesh.faces)
|
||||
self.assertEqual(deserialized.colors, self.mesh.colors)
|
||||
self.assertEqual(deserialized.units, self.mesh.units)
|
||||
self.assertEqual(deserialized.area, self.mesh.area)
|
||||
self.assertEqual(deserialized.volume, self.mesh.volume)
|
||||
|
||||
|
||||
class TestPlane(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.origin = Point(x=0.0, y=0.0, z=0.0, units=Units.m)
|
||||
self.normal = Vector(x=0.0, y=0.0, z=1.0, units=Units.m)
|
||||
self.xdir = Vector(x=1.0, y=0.0, z=0.0, units=Units.m)
|
||||
self.ydir = Vector(x=0.0, y=1.0, z=0.0, units=Units.m)
|
||||
self.plane = Plane(
|
||||
origin=self.origin,
|
||||
normal=self.normal,
|
||||
xdir=self.xdir,
|
||||
ydir=self.ydir,
|
||||
units=Units.m
|
||||
)
|
||||
|
||||
def test_creation(self):
|
||||
self.assertEqual(self.plane.origin.x, 0.0)
|
||||
self.assertEqual(self.plane.normal.z, 1.0)
|
||||
self.assertEqual(self.plane.units, Units.m.value)
|
||||
|
||||
def test_transformation(self):
|
||||
transform = Transform(matrix=[
|
||||
2.0, 0.0, 0.0, 1.0,
|
||||
0.0, 2.0, 0.0, 1.0,
|
||||
0.0, 0.0, 2.0, 1.0,
|
||||
0.0, 0.0, 0.0, 1.0
|
||||
], units=Units.m)
|
||||
|
||||
success, transformed = self.plane.transform_to(transform)
|
||||
self.assertTrue(success)
|
||||
self.assertEqual(transformed.origin.x, 1.0)
|
||||
self.assertEqual(transformed.xdir.x, 2.0)
|
||||
|
||||
def test_serialization(self):
|
||||
serialized = serialize(self.plane)
|
||||
deserialized = deserialize(serialized)
|
||||
|
||||
self.assertEqual(deserialized.origin.x, self.plane.origin.x)
|
||||
self.assertEqual(deserialized.normal.z, self.plane.normal.z)
|
||||
self.assertEqual(deserialized.units, self.plane.units)
|
||||
|
||||
|
||||
class TestArc(unittest.TestCase):
|
||||
def setUp(self):
|
||||
plane = Plane(
|
||||
origin=Point(x=0, y=0, z=0, units="m"),
|
||||
normal=Vector(x=0, y=0, z=1, units="m"),
|
||||
xdir=Vector(x=1, y=0, z=0, units="m"),
|
||||
ydir=Vector(x=0, y=1, z=0, units="m"),
|
||||
units="m"
|
||||
)
|
||||
|
||||
self.arc = Arc(
|
||||
plane=plane,
|
||||
startPoint=Point(x=1, y=0, z=0, units="m"),
|
||||
midPoint=Point(x=0.7071, y=0.7071, z=0, units="m"),
|
||||
endPoint=Point(x=0, y=1, z=0, units="m"),
|
||||
units="m"
|
||||
)
|
||||
|
||||
def test_basic_properties(self):
|
||||
self.assertAlmostEqual(self.arc.radius, 1.0, places=3)
|
||||
self.assertEqual(self.arc.units, "m")
|
||||
|
||||
def test_transform(self):
|
||||
transform = Transform(matrix=[
|
||||
2, 0, 0, 1,
|
||||
0, 2, 0, 1,
|
||||
0, 0, 2, 1,
|
||||
0, 0, 0, 1
|
||||
], units="m")
|
||||
|
||||
success, transformed = self.arc.transform_to(transform)
|
||||
self.assertTrue(success)
|
||||
self.assertAlmostEqual(transformed.radius, 2.0, places=3)
|
||||
|
||||
def test_serialization(self):
|
||||
|
||||
serialized = serialize(self.arc)
|
||||
deserialized = deserialize(serialized)
|
||||
|
||||
self.assertEqual(deserialized.units, self.arc.units)
|
||||
self.assertAlmostEqual(deserialized.radius, self.arc.radius, places=3)
|
||||
|
||||
self.assertAlmostEqual(deserialized.startPoint.x,
|
||||
self.arc.startPoint.x, places=3)
|
||||
self.assertAlmostEqual(deserialized.startPoint.y,
|
||||
self.arc.startPoint.y, places=3)
|
||||
self.assertAlmostEqual(deserialized.startPoint.z,
|
||||
self.arc.startPoint.z, places=3)
|
||||
|
||||
self.assertAlmostEqual(deserialized.midPoint.x,
|
||||
self.arc.midPoint.x, places=3)
|
||||
self.assertAlmostEqual(deserialized.midPoint.y,
|
||||
self.arc.midPoint.y, places=3)
|
||||
self.assertAlmostEqual(deserialized.midPoint.z,
|
||||
self.arc.midPoint.z, places=3)
|
||||
|
||||
self.assertAlmostEqual(deserialized.endPoint.x,
|
||||
self.arc.endPoint.x, places=3)
|
||||
self.assertAlmostEqual(deserialized.endPoint.y,
|
||||
self.arc.endPoint.y, places=3)
|
||||
self.assertAlmostEqual(deserialized.endPoint.z,
|
||||
self.arc.endPoint.z, places=3)
|
||||
|
||||
self.assertAlmostEqual(deserialized.plane.origin.x,
|
||||
self.arc.plane.origin.x, places=3)
|
||||
self.assertAlmostEqual(deserialized.plane.origin.y,
|
||||
self.arc.plane.origin.y, places=3)
|
||||
self.assertAlmostEqual(deserialized.plane.origin.z,
|
||||
self.arc.plane.origin.z, places=3)
|
||||
@@ -0,0 +1,63 @@
|
||||
import pytest
|
||||
from specklepy.objects.geometry.line import Line
|
||||
from specklepy.objects.geometry.point import Point
|
||||
from specklepy.objects.models.units import Units
|
||||
from specklepy.objects.other import Transform
|
||||
from specklepy.objects.primitive import Interval
|
||||
from specklepy.core.api.operations import serialize, deserialize
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def sample_line():
|
||||
p1 = Point(x=0.0, y=0.0, z=0.0, units=Units.m)
|
||||
p2 = Point(x=3.0, y=4.0, z=0.0, units=Units.m)
|
||||
return Line(start=p1, end=p2, units=Units.m, domain=Interval(start=0.0, end=1.0))
|
||||
|
||||
|
||||
def test_line_creation(sample_line):
|
||||
assert sample_line.start.x == 0.0
|
||||
assert sample_line.end.x == 3.0
|
||||
assert sample_line.units == Units.m.value
|
||||
|
||||
|
||||
def test_line_length(sample_line):
|
||||
assert sample_line.length == 5.0
|
||||
|
||||
|
||||
def test_line_transformation(sample_line):
|
||||
transform = Transform(matrix=[
|
||||
2.0, 0.0, 0.0, 1.0,
|
||||
0.0, 2.0, 0.0, 1.0,
|
||||
0.0, 0.0, 2.0, 1.0,
|
||||
0.0, 0.0, 0.0, 1.0
|
||||
], units=Units.m)
|
||||
|
||||
success, transformed = sample_line.transform_to(transform)
|
||||
assert success is True
|
||||
assert transformed.start.x == 1.0
|
||||
assert transformed.end.x == 7.0
|
||||
assert transformed.units == sample_line.units
|
||||
|
||||
|
||||
def test_line_serialization(sample_line):
|
||||
serialized = serialize(sample_line)
|
||||
deserialized = deserialize(serialized)
|
||||
|
||||
assert deserialized.start.x == sample_line.start.x
|
||||
assert deserialized.end.x == sample_line.end.x
|
||||
assert deserialized.units == sample_line.units
|
||||
|
||||
|
||||
def test_line_from_list():
|
||||
coords = [0.0, 0.0, 0.0, 3.0, 4.0, 0.0]
|
||||
line = Line.from_list(coords, Units.m)
|
||||
assert line.start.x == 0.0
|
||||
assert line.end.x == 3.0
|
||||
assert line.units == Units.m.value
|
||||
|
||||
|
||||
def test_line_from_coords():
|
||||
line = Line.from_coords(0.0, 0.0, 0.0, 3.0, 4.0, 0.0, Units.m.value)
|
||||
assert line.start.x == 0.0
|
||||
assert line.end.x == 3.0
|
||||
assert line.units == Units.m.value
|
||||
@@ -0,0 +1,136 @@
|
||||
import pytest
|
||||
from specklepy.objects.geometry.mesh import Mesh
|
||||
from specklepy.objects.geometry.point import Point
|
||||
from specklepy.objects.models.units import Units
|
||||
from specklepy.objects.other import Transform
|
||||
from specklepy.core.api.operations import serialize, deserialize
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def sample_mesh():
|
||||
vertices = [
|
||||
0.0, 0.0, 0.0,
|
||||
1.0, 0.0, 0.0,
|
||||
1.0, 1.0, 0.0,
|
||||
0.0, 1.0, 0.0
|
||||
]
|
||||
faces = [3, 0, 1, 2, 3, 0, 2, 3]
|
||||
colors = [255, 0, 0, 255] * 4
|
||||
area = 1.0
|
||||
volume = 0.0
|
||||
|
||||
return Mesh(
|
||||
vertices=vertices,
|
||||
faces=faces,
|
||||
colors=colors,
|
||||
units=Units.m,
|
||||
area=area,
|
||||
volume=volume
|
||||
)
|
||||
|
||||
|
||||
def test_mesh_creation(sample_mesh):
|
||||
assert sample_mesh.vertices_count == 4
|
||||
assert sample_mesh.faces_count == 2
|
||||
assert sample_mesh.units == Units.m.value
|
||||
assert sample_mesh.area == 1.0
|
||||
assert sample_mesh.volume == 0.0
|
||||
|
||||
|
||||
def test_mesh_get_point(sample_mesh):
|
||||
point = sample_mesh.get_point(1)
|
||||
assert point.x == 1.0
|
||||
assert point.y == 0.0
|
||||
assert point.z == 0.0
|
||||
assert point.units == Units.m.value
|
||||
|
||||
|
||||
def test_mesh_get_points(sample_mesh):
|
||||
points = sample_mesh.get_points()
|
||||
assert len(points) == 4
|
||||
assert all(isinstance(p, Point) for p in points)
|
||||
assert points[0].x == 0.0
|
||||
assert points[1].x == 1.0
|
||||
|
||||
|
||||
def test_mesh_get_face_vertices(sample_mesh):
|
||||
face_vertices = sample_mesh.get_face_vertices(0)
|
||||
assert len(face_vertices) == 3
|
||||
assert face_vertices[0].x == 0.0
|
||||
assert face_vertices[1].x == 1.0
|
||||
assert face_vertices[0].units == Units.m.value
|
||||
|
||||
|
||||
def test_mesh_transform(sample_mesh):
|
||||
transform = Transform(matrix=[
|
||||
2.0, 0.0, 0.0, 1.0,
|
||||
0.0, 2.0, 0.0, 1.0,
|
||||
0.0, 0.0, 2.0, 1.0,
|
||||
0.0, 0.0, 0.0, 1.0
|
||||
], units=Units.m)
|
||||
|
||||
success, transformed = sample_mesh.transform_to(transform)
|
||||
assert success is True
|
||||
|
||||
point = transformed.get_point(0)
|
||||
assert point.x == 1.0
|
||||
assert point.y == 1.0
|
||||
assert transformed.area == sample_mesh.area
|
||||
assert transformed.volume == sample_mesh.volume
|
||||
|
||||
|
||||
def test_mesh_is_closed(sample_mesh):
|
||||
assert sample_mesh.is_closed() is False
|
||||
|
||||
vertices = [
|
||||
0.0, 0.0, 0.0, # 0
|
||||
1.0, 0.0, 0.0, # 1
|
||||
1.0, 1.0, 0.0, # 2
|
||||
0.0, 1.0, 0.0, # 3
|
||||
0.0, 0.0, 1.0, # 4
|
||||
1.0, 0.0, 1.0, # 5
|
||||
1.0, 1.0, 1.0, # 6
|
||||
0.0, 1.0, 1.0 # 7
|
||||
]
|
||||
faces = [
|
||||
3, 0, 1, 2, # front
|
||||
3, 0, 2, 3,
|
||||
3, 4, 5, 6, # back
|
||||
3, 4, 6, 7,
|
||||
3, 0, 4, 7, # left
|
||||
3, 0, 7, 3,
|
||||
3, 1, 5, 6, # right
|
||||
3, 1, 6, 2,
|
||||
3, 3, 2, 6, # top
|
||||
3, 3, 6, 7,
|
||||
3, 0, 1, 5, # bottom
|
||||
3, 0, 5, 4
|
||||
]
|
||||
closed_mesh = Mesh(vertices=vertices, faces=faces,
|
||||
units=Units.m, area=6.0, volume=1.0)
|
||||
assert closed_mesh.is_closed() is True
|
||||
|
||||
|
||||
def test_mesh_serialization(sample_mesh):
|
||||
serialized = serialize(sample_mesh)
|
||||
deserialized = deserialize(serialized)
|
||||
|
||||
assert deserialized.vertices == sample_mesh.vertices
|
||||
assert deserialized.faces == sample_mesh.faces
|
||||
assert deserialized.colors == sample_mesh.colors
|
||||
assert deserialized.units == sample_mesh.units
|
||||
assert deserialized.area == sample_mesh.area
|
||||
assert deserialized.volume == sample_mesh.volume
|
||||
|
||||
|
||||
def test_mesh_convert_units(sample_mesh):
|
||||
sample_mesh.convert_units(Units.mm)
|
||||
assert sample_mesh.units == Units.mm.value
|
||||
|
||||
point = sample_mesh.get_point(1)
|
||||
assert point.x == 1000.0
|
||||
assert point.units == Units.mm.value
|
||||
|
||||
assert sample_mesh.area == 1.0 * (1000 ** 2)
|
||||
|
||||
assert sample_mesh.volume == 0.0
|
||||
@@ -0,0 +1,71 @@
|
||||
import pytest
|
||||
from specklepy.objects.geometry.plane import Plane
|
||||
from specklepy.objects.geometry.point import Point
|
||||
from specklepy.objects.geometry.vector import Vector
|
||||
from specklepy.objects.models.units import Units
|
||||
from specklepy.objects.other import Transform
|
||||
from specklepy.core.api.operations import serialize, deserialize
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def sample_plane():
|
||||
return Plane(
|
||||
origin=Point(x=0.0, y=0.0, z=0.0, units=Units.m),
|
||||
normal=Vector(x=0.0, y=0.0, z=1.0, units=Units.m),
|
||||
xdir=Vector(x=1.0, y=0.0, z=0.0, units=Units.m),
|
||||
ydir=Vector(x=0.0, y=1.0, z=0.0, units=Units.m),
|
||||
units=Units.m
|
||||
)
|
||||
|
||||
|
||||
def test_plane_creation(sample_plane):
|
||||
assert sample_plane.origin.x == 0.0
|
||||
assert sample_plane.normal.z == 1.0
|
||||
assert sample_plane.xdir.x == 1.0
|
||||
assert sample_plane.ydir.y == 1.0
|
||||
assert sample_plane.units == Units.m.value
|
||||
|
||||
|
||||
def test_plane_transformation(sample_plane):
|
||||
transform = Transform(matrix=[
|
||||
2.0, 0.0, 0.0, 1.0,
|
||||
0.0, 2.0, 0.0, 1.0,
|
||||
0.0, 0.0, 2.0, 1.0,
|
||||
0.0, 0.0, 0.0, 1.0
|
||||
], units=Units.m)
|
||||
|
||||
success, transformed = sample_plane.transform_to(transform)
|
||||
assert success is True
|
||||
assert transformed.origin.x == 1.0
|
||||
assert transformed.xdir.x == 2.0
|
||||
assert transformed.units == sample_plane.units
|
||||
|
||||
|
||||
def test_plane_serialization(sample_plane):
|
||||
serialized = serialize(sample_plane)
|
||||
deserialized = deserialize(serialized)
|
||||
|
||||
assert deserialized.origin.x == sample_plane.origin.x
|
||||
assert deserialized.normal.z == sample_plane.normal.z
|
||||
assert deserialized.units == sample_plane.units
|
||||
|
||||
|
||||
def test_plane_to_list(sample_plane):
|
||||
coords = sample_plane.to_list()
|
||||
assert len(coords) == 13
|
||||
|
||||
|
||||
def test_plane_from_list():
|
||||
coords = [
|
||||
0.0, 0.0, 0.0, # origin
|
||||
0.0, 0.0, 1.0, # normal
|
||||
1.0, 0.0, 0.0, # xdir
|
||||
0.0, 1.0, 0.0, # ydir
|
||||
1 # units encoding (1 = mm)
|
||||
]
|
||||
plane = Plane.from_list(coords)
|
||||
assert plane.origin.x == 0.0
|
||||
assert plane.normal.z == 1.0
|
||||
assert plane.xdir.x == 1.0
|
||||
assert plane.ydir.y == 1.0
|
||||
assert plane.units == "mm"
|
||||
@@ -0,0 +1,53 @@
|
||||
import pytest
|
||||
from specklepy.objects.geometry.point import Point
|
||||
from specklepy.objects.models.units import Units
|
||||
from specklepy.objects.other import Transform
|
||||
from specklepy.core.api.operations import serialize, deserialize
|
||||
|
||||
|
||||
def test_point_creation():
|
||||
p1 = Point(x=1.0, y=2.0, z=3.0, units=Units.m)
|
||||
assert p1.x == 1.0
|
||||
assert p1.y == 2.0
|
||||
assert p1.z == 3.0
|
||||
assert p1.units == Units.m.value
|
||||
|
||||
|
||||
def test_point_distance_calculation():
|
||||
p1 = Point(x=1.0, y=2.0, z=3.0, units=Units.m)
|
||||
p2 = Point(x=4.0, y=6.0, z=8.0, units=Units.m)
|
||||
p3 = Point(x=1000.0, y=2000.0, z=3000.0, units=Units.mm)
|
||||
|
||||
distance = p1.distance_to(p2)
|
||||
expected = ((3.0**2 + 4.0**2 + 5.0**2) ** 0.5)
|
||||
assert distance == pytest.approx(expected)
|
||||
|
||||
distance = p1.distance_to(p3)
|
||||
assert distance == pytest.approx(0.0)
|
||||
|
||||
|
||||
def test_point_transformation():
|
||||
p1 = Point(x=1.0, y=2.0, z=3.0, units=Units.m)
|
||||
transform = Transform(matrix=[
|
||||
2.0, 0.0, 0.0, 1.0,
|
||||
0.0, 2.0, 0.0, 1.0,
|
||||
0.0, 0.0, 2.0, 1.0,
|
||||
0.0, 0.0, 0.0, 1.0
|
||||
], units=Units.m)
|
||||
|
||||
success, transformed = p1.transform_to(transform)
|
||||
assert success is True
|
||||
assert transformed.x == 3.0
|
||||
assert transformed.y == 5.0
|
||||
assert transformed.z == 7.0
|
||||
|
||||
|
||||
def test_point_serialization():
|
||||
p1 = Point(x=1.0, y=2.0, z=3.0, units=Units.m)
|
||||
serialized = serialize(p1)
|
||||
deserialized = deserialize(serialized)
|
||||
|
||||
assert deserialized.x == p1.x
|
||||
assert deserialized.y == p1.y
|
||||
assert deserialized.z == p1.z
|
||||
assert deserialized.units == p1.units
|
||||
@@ -0,0 +1,130 @@
|
||||
import pytest
|
||||
from specklepy.objects.geometry.polyline import Polyline
|
||||
from specklepy.objects.geometry.point import Point
|
||||
from specklepy.objects.models.units import Units
|
||||
from specklepy.objects.other import Transform
|
||||
from specklepy.objects.primitive import Interval
|
||||
from specklepy.core.api.operations import serialize, deserialize
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def square_vertices():
|
||||
return [
|
||||
0.0, 0.0, 0.0,
|
||||
1.0, 0.0, 0.0,
|
||||
1.0, 1.0, 0.0,
|
||||
0.0, 1.0, 0.0
|
||||
]
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def sample_polyline(square_vertices):
|
||||
return Polyline(
|
||||
value=square_vertices,
|
||||
closed=True,
|
||||
units=Units.m,
|
||||
domain=Interval(start=0.0, end=1.0)
|
||||
)
|
||||
|
||||
|
||||
def test_polyline_creation(square_vertices):
|
||||
polyline = Polyline(
|
||||
value=square_vertices,
|
||||
closed=True,
|
||||
units=Units.m,
|
||||
domain=Interval(start=0.0, end=1.0)
|
||||
)
|
||||
|
||||
assert len(polyline.value) == 12
|
||||
assert polyline.closed is True
|
||||
assert polyline.units == Units.m.value
|
||||
assert isinstance(polyline.domain, Interval)
|
||||
assert polyline.domain.start == 0.0
|
||||
assert polyline.domain.end == 1.0
|
||||
|
||||
|
||||
def test_polyline_get_points(sample_polyline):
|
||||
points = sample_polyline.get_points()
|
||||
|
||||
assert len(points) == 4
|
||||
|
||||
assert all(isinstance(p, Point) for p in points)
|
||||
|
||||
assert points[0].x == 0.0 and points[0].y == 0.0 and points[0].z == 0.0
|
||||
assert points[1].x == 1.0 and points[1].y == 0.0 and points[1].z == 0.0
|
||||
|
||||
assert all(p.units == Units.m.value for p in points)
|
||||
|
||||
|
||||
def test_polyline_length(sample_polyline):
|
||||
|
||||
assert pytest.approx(sample_polyline.length) == 4.0
|
||||
|
||||
sample_polyline.closed = False
|
||||
assert pytest.approx(sample_polyline.length) == 3.0
|
||||
|
||||
|
||||
def test_polyline_transformation(sample_polyline):
|
||||
transform = Transform(matrix=[
|
||||
2.0, 0.0, 0.0, 1.0,
|
||||
0.0, 2.0, 0.0, 1.0,
|
||||
0.0, 0.0, 2.0, 1.0,
|
||||
0.0, 0.0, 0.0, 1.0
|
||||
], units=Units.m)
|
||||
|
||||
success, transformed = sample_polyline.transform_to(transform)
|
||||
assert success is True
|
||||
|
||||
points = transformed.get_points()
|
||||
|
||||
assert points[0].x == 1.0
|
||||
assert points[0].y == 1.0
|
||||
assert points[0].z == 1.0
|
||||
|
||||
assert points[1].x == 3.0
|
||||
assert points[1].y == 1.0
|
||||
assert points[1].z == 1.0
|
||||
|
||||
assert transformed.units == sample_polyline.units
|
||||
|
||||
|
||||
def test_polyline_serialization(sample_polyline):
|
||||
serialized = serialize(sample_polyline)
|
||||
deserialized = deserialize(serialized)
|
||||
|
||||
assert deserialized.value == sample_polyline.value
|
||||
assert deserialized.closed == sample_polyline.closed
|
||||
assert deserialized.units == sample_polyline.units
|
||||
assert deserialized.domain.start == sample_polyline.domain.start
|
||||
assert deserialized.domain.end == sample_polyline.domain.end
|
||||
|
||||
|
||||
def test_polyline_to_list(sample_polyline):
|
||||
result = sample_polyline.to_list()
|
||||
|
||||
assert isinstance(result, list)
|
||||
assert result[2] == 1
|
||||
assert result[3] == 0.0
|
||||
assert result[4] == 1.0
|
||||
assert result[5] == len(sample_polyline.value)
|
||||
|
||||
|
||||
def test_polyline_from_list():
|
||||
input_list = [
|
||||
18, "Objects.Geometry.Polyline",
|
||||
1,
|
||||
0.0, 1.0,
|
||||
12,
|
||||
0.0, 0.0, 0.0,
|
||||
1.0, 0.0, 0.0,
|
||||
1.0, 1.0, 0.0,
|
||||
0.0, 1.0, 0.0
|
||||
]
|
||||
|
||||
polyline = Polyline.from_list(input_list, Units.m)
|
||||
|
||||
assert polyline.closed is True
|
||||
assert len(polyline.value) == 12
|
||||
assert polyline.units == Units.m.value
|
||||
assert polyline.domain.start == 0.0
|
||||
assert polyline.domain.end == 1.0
|
||||
@@ -0,0 +1,70 @@
|
||||
import pytest
|
||||
from specklepy.objects.geometry.vector import Vector
|
||||
from specklepy.objects.models.units import Units
|
||||
from specklepy.objects.other import Transform
|
||||
from specklepy.core.api.operations import serialize, deserialize
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def sample_vectors():
|
||||
return (
|
||||
Vector(x=1.0, y=2.0, z=3.0, units=Units.m),
|
||||
Vector(x=4.0, y=5.0, z=6.0, units=Units.m)
|
||||
)
|
||||
|
||||
|
||||
def test_vector_creation(sample_vectors):
|
||||
v1, _ = sample_vectors
|
||||
assert v1.x == 1.0
|
||||
assert v1.y == 2.0
|
||||
assert v1.z == 3.0
|
||||
assert v1.units == Units.m.value
|
||||
|
||||
|
||||
def test_vector_length(sample_vectors):
|
||||
v1, _ = sample_vectors
|
||||
expected = (1.0**2 + 2.0**2 + 3.0**2) ** 0.5
|
||||
assert v1.length == pytest.approx(expected)
|
||||
|
||||
|
||||
def test_vector_transformation(sample_vectors):
|
||||
v1, _ = sample_vectors
|
||||
transform = Transform(matrix=[
|
||||
2.0, 0.0, 0.0, 1.0,
|
||||
0.0, 2.0, 0.0, 1.0,
|
||||
0.0, 0.0, 2.0, 1.0,
|
||||
0.0, 0.0, 0.0, 1.0
|
||||
], units=Units.m)
|
||||
|
||||
success, transformed = v1.transform_to(transform)
|
||||
assert success is True
|
||||
assert transformed.x == 2.0
|
||||
assert transformed.y == 4.0
|
||||
assert transformed.z == 6.0
|
||||
assert transformed.units == v1.units
|
||||
|
||||
|
||||
def test_vector_serialization(sample_vectors):
|
||||
v1, _ = sample_vectors
|
||||
serialized = serialize(v1)
|
||||
deserialized = deserialize(serialized)
|
||||
|
||||
assert deserialized.x == v1.x
|
||||
assert deserialized.y == v1.y
|
||||
assert deserialized.z == v1.z
|
||||
assert deserialized.units == v1.units
|
||||
|
||||
|
||||
def test_vector_from_list():
|
||||
coords = [1.0, 2.0, 3.0]
|
||||
v = Vector.from_list(coords, Units.m)
|
||||
assert v.x == 1.0
|
||||
assert v.y == 2.0
|
||||
assert v.z == 3.0
|
||||
assert v.units == Units.m.value
|
||||
|
||||
|
||||
def test_vector_to_list(sample_vectors):
|
||||
v1, _ = sample_vectors
|
||||
coords = v1.to_list()
|
||||
assert coords == [1.0, 2.0, 3.0]
|
||||
Reference in New Issue
Block a user