Skip to content
This repository has been archived by the owner on Feb 9, 2021. It is now read-only.

Commit

Permalink
Merge pull request #242 from dcowden/tests
Browse files Browse the repository at this point in the history
Added tests for remaining Face functions that were not covered.
  • Loading branch information
jmwright committed Mar 16, 2018
2 parents 8f92e7d + 2e38be7 commit 96478e2
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 3 deletions.
6 changes: 3 additions & 3 deletions cadquery/freecad_impl/shapes.py
Original file line number Diff line number Diff line change
Expand Up @@ -660,17 +660,17 @@ def makeRuledSurface(cls, edgeOrWire1, edgeOrWire2, dist=None):

def cut(self, faceToCut):
"Remove a face from another one"
return Shape.cast(self.obj.cut(faceToCut.obj))
return Shape.cast(self.wrapped.cut(faceToCut.wrapped))

def fuse(self, faceToJoin):
return Shape.cast(self.obj.fuse(faceToJoin.obj))
return Shape.cast(self.wrapped.fuse(faceToJoin.wrapped))

def intersect(self, faceToIntersect):
"""
computes the intersection between the face and the supplied one.
The result could be a face or a compound of faces
"""
return Shape.cast(self.obj.common(faceToIntersect.obj))
return Shape.cast(self.wrapped.common(faceToIntersect.wrapped))


class Shell(Shape):
Expand Down
78 changes: 78 additions & 0 deletions tests/TestCadObjects.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,84 @@ def testRuledSurface(self):
self.assertEquals(surf1.ShapeType(), 'Face')
self.assertTrue(surf1.isValid())

def testCut(self):
"""
Tests cutting one face from another.
"""
# Face 1
edge1 = Part.makeLine((0, 0, 0), (0, 10, 0))
edge2 = Part.makeLine((0, 10, 0), (10, 10, 0))
edge3 = Part.makeLine((10, 10, 0), (10, 0, 0))
edge4 = Part.makeLine((10, 0, 0), (0, 0, 0))
wire1 = Part.Wire([edge1,edge2,edge3,edge4])
face1 = Part.Face(wire1)
cqFace1 = Face(face1)

# Face 2 (face to cut out of face 1)
edge1 = Part.makeLine((0, 0, 0), (0, 5, 0))
edge2 = Part.makeLine((0, 5, 0), (5, 5, 0))
edge3 = Part.makeLine((5, 5, 0), (5, 0, 0))
edge4 = Part.makeLine((5, 0, 0), (0, 0, 0))
wire1 = Part.Wire([edge1,edge2,edge3,edge4])
face2 = Part.Face(wire1)
cqFace2 = Face(face2)

# Face resulting from cut
cqFace3 = cqFace1.cut(cqFace2)

self.assertEquals(len(cqFace3.Faces()), 1)
self.assertEquals(len(cqFace3.Edges()), 6)

def testFuse(self):
"""
Tests fusing one face to another.
"""
# Face 1
edge1 = Part.makeLine((0, 0, 0), (0, 10, 0))
edge2 = Part.makeLine((0, 10, 0), (10, 10, 0))
edge3 = Part.makeLine((10, 10, 0), (10, 0, 0))
edge4 = Part.makeLine((10, 0, 0), (0, 0, 0))
wire1 = Part.Wire([edge1,edge2,edge3,edge4])
face1 = Part.Face(wire1)
cqFace1 = Face(face1)

# Face 2 (face to cut out of face 1)
edge1 = Part.makeCircle(4.0)
wire1 = Part.Wire([edge1])
face2 = Part.Face(wire1)
cqFace2 = Face(face2)

# Face resulting from fuse
cqFace3 = cqFace1.fuse(cqFace2)

self.assertEquals(len(cqFace3.Faces()), 3)
self.assertEquals(len(cqFace3.Edges()), 8)

def testIntersect(self):
"""
Tests finding the intersection of two faces.
"""
# Face 1
edge1 = Part.makeLine((0, 0, 0), (0, 10, 0))
edge2 = Part.makeLine((0, 10, 0), (10, 10, 0))
edge3 = Part.makeLine((10, 10, 0), (10, 0, 0))
edge4 = Part.makeLine((10, 0, 0), (0, 0, 0))
wire1 = Part.Wire([edge1,edge2,edge3,edge4])
face1 = Part.Face(wire1)
cqFace1 = Face(face1)

# Face 2 (face to cut out of face 1)
edge1 = Part.makeCircle(4.0)
wire1 = Part.Wire([edge1])
face2 = Part.Face(wire1)
cqFace2 = Face(face2)

# Face resulting from the intersection
cqFace3 = cqFace1.intersect(cqFace2)

self.assertEquals(len(cqFace3.Faces()), 1)
self.assertEquals(len(cqFace3.Edges()), 3)

def testVertices(self):
e = Shape.cast(Part.makeLine((0, 0, 0), (1, 1, 0)))
self.assertEqual(2, len(e.Vertices()))
Expand Down

0 comments on commit 96478e2

Please sign in to comment.