Skip to content

Commit

Permalink
Merge 5298060 into ee5db2a
Browse files Browse the repository at this point in the history
  • Loading branch information
mikedh committed Jan 6, 2020
2 parents ee5db2a + 5298060 commit 9c6ce65
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 22 deletions.
22 changes: 20 additions & 2 deletions tests/test_bounds.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,14 +228,32 @@ def test_obb_order(self):
b.bounds)

# unordered extents and transforms
transform, extents = g.trimesh.bounds.oriented_bounds(b, ordered=False)
assert g.np.allclose(g.np.sort(extents), extents_ordered)
transform, extents = g.trimesh.bounds.oriented_bounds(
b, ordered=False)
assert g.np.allclose(g.np.sort(extents),
extents_ordered)
# create a box from the unordered OBB information
box = g.trimesh.creation.box(
extents=extents, transform=g.np.linalg.inv(transform))
# make sure it is a real OBB too
assert g.np.allclose(box.bounds, b.bounds)

def test_bounds_tree(self):
# test r-tree intersections
for dimension in (2, 3):
# create some (n, 2, 3) bounds
bounds = g.np.array([[i.min(axis=0), i.max(axis=0)]
for i in
[g.random((4, dimension))
for i in range(10)]])
tree = g.trimesh.util.bounds_tree(bounds)
for i, b in enumerate(bounds):
assert i in set(tree.intersection(b.ravel()))
# construct tree with per-row bounds
tree = g.trimesh.util.bounds_tree(bounds.reshape((-1, dimension * 2)))
for i, b in enumerate(bounds):
assert i in set(tree.intersection(b.ravel()))


if __name__ == '__main__':
g.trimesh.util.attach_to_log()
Expand Down
4 changes: 3 additions & 1 deletion tests/test_dxf.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ def test_dxf(self):
text = d.export(file_type='dxf')

# DXF files are always pairs of lines
assert (len(str.splitlines(str(text))) % 2) == 0
lines = str.splitlines(str(text))
assert (len(lines) % 2) == 0
assert all(len(L.strip()) > 0 for L in lines)

# reload the file by name and by stream
rc = [g.trimesh.load(temp_name),
Expand Down
4 changes: 2 additions & 2 deletions tests/test_points.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,9 @@ def test_kmeans(self,
"""
clustered = []
for i in range(cluster_count):
# use repeatable random- ish coordinatez
# use repeatable random- ish coordinates
clustered.append(
g.random((points_per_cluster, 3)) + (i * 10.0))
g.random((points_per_cluster, 3)) * (1e-3) + (i * 10.0))
clustered = g.np.vstack(clustered)

# run k- means clustering on our nicely separated data
Expand Down
9 changes: 6 additions & 3 deletions tests/test_repair.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ def test_fill_holes(self):
assert not mesh.is_volume

# color some faces
g.trimesh.repair.broken_faces(mesh,
color=[255, 0, 0, 255])
g.trimesh.repair.broken_faces(
mesh, color=[255, 0, 0, 255])

hashes.append({mesh._data.crc(),
mesh._data.md5(),
Expand All @@ -52,9 +52,12 @@ def test_fill_holes(self):
hashes.append({mesh._data.crc(),
mesh._data.md5(),
mesh._data.fast_hash()})

assert hashes[1] != hashes[2]

# try broken faces on a watertight mesh
g.trimesh.repair.broken_faces(
mesh, color=[255, 255, 0, 255])

def test_fix_normals(self):
for mesh in g.get_meshes(5):
mesh.fix_normals()
Expand Down
2 changes: 1 addition & 1 deletion trimesh/repair.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ def broken_faces(mesh, color=None):
broken = [k for k, v in dict(adjacency.degree()).items()
if v != 3]
broken = np.array(broken)
if color is not None:
if color is not None and broken.size != 0:
# if someone passed a broken color
color = np.array(color)
if not (color.shape == (4,) or color.shape == (3,)):
Expand Down
12 changes: 6 additions & 6 deletions trimesh/resources/dxf.json.template

Large diffs are not rendered by default.

15 changes: 12 additions & 3 deletions trimesh/resources/helpers/dxf_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import os
import json
import numpy as np


def get_json(file_name='../dxf.json.template'):
Expand Down Expand Up @@ -37,9 +38,17 @@ def replace_whitespace(text, SAFE_SPACE='|<^>|', insert=True):
else:
# replace safe space chr with whitespace
args = (SAFE_SPACE, ' ')

return '\n'.join(line.strip().replace(*args)
for line in str.splitlines(text))
lines = [line.strip().replace(*args)
for line in str.splitlines(text)]
# remove any blank lines
if any(len(L) == 0 for L in lines):
shaped = np.reshape(lines, (-1, 2))
mask = np.ones(len(shaped), dtype=np.bool)
for i, v in enumerate(shaped[:, 1]):
if len(v) == 0:
mask[i] = False
lines = shaped[mask].ravel()
return '\n'.join(lines)


def write_files(template, destination='./dxf'):
Expand Down
12 changes: 9 additions & 3 deletions trimesh/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -1582,7 +1582,7 @@ def bounds_tree(bounds):
Parameters
------------
bounds : (n, dimension * 2) float
bounds : (n, dimension * 2) or (n, 2, dimension) float
Non-interleaved bounds, i.e. for a 2D bounds tree:
[(minx, miny, maxx, maxy), ...]
Expand All @@ -1596,8 +1596,14 @@ def bounds_tree(bounds):

# make sure we've copied bounds
bounds = np.array(bounds, dtype=np.float64, copy=True)
if len(bounds.shape) != 2:
raise ValueError('Bounds must be (n,dimension*2)!')
if len(bounds.shape) == 3:
# should be min-max per bound
if bounds.shape[1] != 2:
raise ValueError('bounds not (n, 2, dimension)!')
# reshape to one-row-per-hyperrectangle
bounds = bounds.reshape((len(bounds), -1))
elif len(bounds.shape) != 2:
raise ValueError('Bounds must be (n, dimension * 2)!')

# check to make sure we have correct shape
dimension = bounds.shape[1]
Expand Down
2 changes: 1 addition & 1 deletion trimesh/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '3.5.12'
__version__ = '3.5.13'

0 comments on commit 9c6ce65

Please sign in to comment.