Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Second pull request attempt #227

Merged
merged 11 commits into from
Nov 25, 2024
33 changes: 33 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,39 @@ Extending Mesh objects
# Show the plot to the screen
pyplot.show()

Creating a single triangle
----------------------------------

.. code-block:: python

import numpy
from stl import mesh

# A unit triangle
tri_vectors = [[0,0,0],[0,1,0],[0,0,1]]

# Create the vector data. It’s a numpy structured array with N entries, where N is the number of triangles (here N=1), and each entry is in the format ('normals','vectors','attr')
data = numpy.array([(
0, # Set 'normals' to zero, and the mesh class will automatically calculate them at initialization
tri_vectors, # 'vectors'
0 # 'attr'
)], dtype = mesh.Mesh.dtype) # The structure defined by the mesh class (N x ('normals','vectors','attr'))

# Create the mesh object from the structured array
tri_mesh = mesh.Mesh(data)

# Optionally make a plot for fun
# Load the plot tools
from matplotlib import pyplot
from mpl_toolkits import mplot3d

# Create a new plot
figure = pyplot.figure()
axes = figure.add_subplot(projection='3d')

# Add mesh to plot
axes.add_collection3d(mplot3d.art3d.Poly3DCollection(tri_mesh.vectors)) # Just need the 'vectors' attribute for display

Creating Mesh objects from a list of vertices and faces
------------------------------------------------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ install:
build: false # Not a C# project, build stuff at the test step instead.

before_test:
- py -m pip install tox numpy cython wheel
- py -m pip install tox numpy cython wheel setuptools

test_script:
- "py -m tox -e %TOXENV%"
Expand Down
14 changes: 7 additions & 7 deletions stl/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,32 +140,32 @@ class BaseMesh(logger.Logged, abc.Mapping):

>>> len(mesh) == len(list(mesh))
True
>>> (mesh.min_ < mesh.max_).all()
>>> bool((mesh.min_ < mesh.max_).all())
True
>>> mesh.update_normals()
>>> mesh.units.sum()
>>> float(mesh.units.sum())
0.0
>>> mesh.v0[:] = mesh.v1[:] = mesh.v2[:] = 0
>>> mesh.points.sum()
>>> float(mesh.points.sum())
0.0

>>> mesh.v0 = mesh.v1 = mesh.v2 = 0
>>> mesh.x = mesh.y = mesh.z = 0

>>> mesh.attr = 1
>>> (mesh.attr == 1).all()
>>> bool((mesh.attr == 1).all())
True

>>> mesh.normals = 2
>>> (mesh.normals == 2).all()
>>> bool((mesh.normals == 2).all())
True

>>> mesh.vectors = 3
>>> (mesh.vectors == 3).all()
>>> bool((mesh.vectors == 3).all())
True

>>> mesh.points = 4
>>> (mesh.points == 4).all()
>>> bool((mesh.points == 4).all())
True
"""

Expand Down
9 changes: 9 additions & 0 deletions tests/test_ascii.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,15 @@ def test_ascii_io():
# Assert binary file is still only ascii characters.
fh.getvalue().decode('ascii')

import tempfile

with tempfile.NamedTemporaryFile(delete=False) as temp_file:
# Save the mesh to the temporary file
mesh_.save(temp_file.name, mode=Mode.ASCII)

# Read the mesh back from the temporary file
read = mesh.Mesh.from_file(temp_file.name)

# Read the mesh back in.
read = mesh.Mesh.from_file('anonymous.stl', fh=io.BytesIO(fh.getvalue()))
# Check what comes out is the same as what went in.
Expand Down
2 changes: 1 addition & 1 deletion tests/test_meshProperties.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from stl import stl


tolerance = 1e-6
tolerance = 1e-5


def close(a, b):
Expand Down