Skip to content

Commit

Permalink
Merge 1b0bbbd into 5ed9dc9
Browse files Browse the repository at this point in the history
  • Loading branch information
mikedh committed Nov 3, 2019
2 parents 5ed9dc9 + 1b0bbbd commit 48a5e03
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 15 deletions.
44 changes: 44 additions & 0 deletions tests/test_repr.py
@@ -0,0 +1,44 @@
try:
from . import generic as g
except BaseException:
import generic as g


class ReprTest(g.unittest.TestCase):

def test_repr(self):
m = g.trimesh.creation.icosphere()
r = str(m)
assert 'trimesh.Trimesh' in r
assert 'vertices' in r
assert 'faces' in r

s = m.scene()
assert isinstance(s, g.trimesh.Scene)
r = str(s)
assert 'Scene' in r
assert 'geometry' in r

p = g.trimesh.PointCloud(m.vertices)
r = str(p)
assert 'trimesh.PointCloud' in r
assert 'vertices' in r

p = g.trimesh.path.creation.rectangle([[0, 0], [1, 1]])
assert isinstance(p, g.trimesh.path.Path2D)
r = str(p)
assert 'trimesh.Path2D' in r
assert 'entities' in r
assert 'vertices' in r

p = p.to_3D()
assert isinstance(p, g.trimesh.path.Path3D)
r = str(p)
assert 'trimesh.Path3D' in r
assert 'entities' in r
assert 'vertices' in r


if __name__ == '__main__':
g.trimesh.util.attach_to_log()
g.unittest.main()
13 changes: 13 additions & 0 deletions trimesh/parent.py
Expand Up @@ -39,6 +39,19 @@ def apply_transform(self, matrix):
def is_empty(self):
pass

def __repr__(self):
"""
Print quick summary of the current geometry without computing properties.
"""
elements = []
if hasattr(self, 'vertices'):
elements.append('vertices.shape={}'.format(self.vertices.shape))
if hasattr(self, 'faces'):
elements.append('faces.shape={}'.format(self.faces.shape))
if hasattr(self, 'geometry') and isinstance(self.geometry, dict):
elements.append('len(geometry)={}'.format(len(self.geometry)))
return '<trimesh.{}( {} )>'.format(type(self).__name__, ', '.join(elements))

def apply_translation(self, translation):
"""
Translate the current mesh.
Expand Down
10 changes: 10 additions & 0 deletions trimesh/path/path.py
Expand Up @@ -98,6 +98,16 @@ def __init__(self,
# aren't merged properly
self.merge_vertices()

def __repr__(self):
"""
Print a quick summary of the number of vertices and entities.
"""
r = '<trimesh.{}( len(entities)={}, len(vertices)={} )>'.format(
type(self).__name__,
len(self.entities),
len(self.vertices))
return r

def process(self):
"""
Apply basic cleaning functions to the Path object, in- place.
Expand Down
25 changes: 11 additions & 14 deletions trimesh/primitives.py
Expand Up @@ -34,6 +34,9 @@ def __init__(self, *args, **kwargs):
self._data.clear()
self._validate = False

def __repr__(self):
return '<trimesh.primitives.{}>'.format(type(self).__name__)

@property
def faces(self):
stored = self._cache['faces']
Expand Down Expand Up @@ -250,7 +253,7 @@ def moment_inertia(self):
transform=self.primitive.transform)
return tensor

@property
@caching.cache_decorator
def direction(self):
"""
The direction of the cylinder's axis.
Expand Down Expand Up @@ -306,11 +309,7 @@ def buffer(self, distance):
return buffered

def _create_mesh(self):
log.info('Creating cylinder mesh with r=%f, h=%f %d sections',
self.primitive.radius,
self.primitive.height,
self.primitive.sections)

log.debug('creating mesh for Cylinder primitive')
mesh = creation.cylinder(radius=self.primitive.radius,
height=self.primitive.height,
sections=self.primitive.sections,
Expand Down Expand Up @@ -344,7 +343,7 @@ def __init__(self, *args, **kwargs):
defaults,
kwargs)

@property
@caching.cache_decorator
def direction(self):
"""
The direction of the capsule's axis.
Expand All @@ -357,10 +356,7 @@ def direction(self):
return axis

def _create_mesh(self):
log.info('Creating capsule mesh with r=%f, h=%f and %d sections',
self.primitive.radius,
self.primitive.height,
self.primitive.sections)
log.debug('creating mesh for Capsule primitive')

mesh = creation.capsule(radius=self.primitive.radius,
height=self.primitive.height)
Expand Down Expand Up @@ -467,6 +463,7 @@ def moment_inertia(self):
return tensor

def _create_mesh(self):
log.debug('creating mesh for Sphere primitive')
unit = creation.icosphere(subdivisions=self.primitive.subdivisions)
unit.vertices *= self.primitive.radius
unit.vertices += self.primitive.center
Expand Down Expand Up @@ -577,7 +574,7 @@ def volume(self):
return volume

def _create_mesh(self):
log.debug('Creating mesh for box Primitive')
log.debug('creating mesh for Box primitive')
box = creation.box(extents=self.primitive.extents,
transform=self.primitive.transform)

Expand Down Expand Up @@ -650,7 +647,7 @@ def volume(self):
self.primitive.height)
return volume

@property
@caching.cache_decorator
def direction(self):
"""
Based on the extrudes transform what is the
Expand Down Expand Up @@ -757,7 +754,7 @@ def buffer(self, distance, distance_height=None, **kwargs):
return buffered

def _create_mesh(self):
log.debug('Creating mesh for extrude Primitive')
log.debug('creating mesh for Extrusion primitive')
# extrude the polygon along Z
mesh = creation.extrude_polygon(
polygon=self.primitive.polygon,
Expand Down
2 changes: 1 addition & 1 deletion trimesh/version.py
@@ -1 +1 @@
__version__ = '3.3.3'
__version__ = '3.3.4'

0 comments on commit 48a5e03

Please sign in to comment.