Files
cadquery/tests/__init__.py
Fedor Kotov d5ce1321ca Added AreaNthSelector (#688)
* Added AreaNthSelector

Added AreaNthSelector that is useful for nested features selection. Especially to select one of coplanar nested wires for subsequent extrusion, cutting or filleting.

* LengthNthSelector

* Explicitly marked _NthSelector class and _NthSelector.key(..) method as abstract using standard abc package

* AreaNthSelector ignores "bad" Wires

AreaNthSelector.key raises ValueError if temporary face creation fails for a wire for any reason (non-planar, non-closed). That causes _NthSelector that it inherits to ignore such wires. Done so for consistency with RadiusNthSelector that ignores anything it can not get radius from.

Co-authored-by: Marcus Boyd <mwb@geosol.com.au>
2021-03-17 14:14:37 +10:30

66 lines
1.4 KiB
Python

from cadquery import *
from OCP.gp import gp_Vec
import unittest
import sys
import os
def readFileAsString(fileName):
f = open(fileName, "r")
s = f.read()
f.close()
return s
def writeStringToFile(strToWrite, fileName):
f = open(fileName, "w")
f.write(strToWrite)
f.close()
def makeUnitSquareWire():
V = Vector
return Wire.makePolygon(
[V(0, 0, 0), V(1, 0, 0), V(1, 1, 0), V(0, 1, 0), V(0, 0, 0)]
)
def makeUnitCube(centered=True):
return makeCube(1.0, centered)
def makeCube(size, xycentered=True):
if xycentered:
return Workplane().rect(size, size).extrude(size).val()
else:
return Solid.makeBox(size, size, size)
def toTuple(v):
"""convert a vector or a vertex to a 3-tuple: x,y,z"""
if type(v) == gp_Vec:
return (v.X(), v.Y(), v.Z())
elif type(v) == Vector:
return v.toTuple()
else:
raise RuntimeError("dont know how to convert type %s to tuple" % str(type(v)))
class BaseTest(unittest.TestCase):
def assertTupleAlmostEquals(self, expected, actual, places, msg=None):
for i, j in zip(actual, expected):
self.assertAlmostEqual(i, j, places, msg=msg)
__all__ = [
"TestCadObjects",
"TestCadQuery",
"TestCQGI",
"TestCQSelectors",
"TestCQSelectors",
"TestExporters",
"TestImporters",
"TestJupyter",
"TestWorkplanes",
]