PK!r++solid_toolbox/__init__.pyfrom solid_toolbox.units import * from solid_toolbox.transforms import * from solid_toolbox.poly import * from solid_toolbox.curves import * __all__ = [ # From 'units' "Vec", "Vec2d", "Point", "Point2d", "mm", "cm", "x_axis", "x_unit", "y_axis", "y_unit", "z_axis", "z_unit", # From transforms "noop", "rotate_with_fake_origin", # From poly "construct_polyhedron", "construct_polygon", # From curves "inclusive_range", "bezier_curve", ] PK!Liisolid_toolbox/__main__.py#!/usr/bin/env python3 from solid_toolbox.commands import run if __name__ == "__main__": run() PK![Esolid_toolbox/commands.py#!/usr/bin/env python3 from pathlib import Path import click class FolderType(click.ParamType): name = "Folder" def __init__(self): self.converter = click.Path( exists=False, file_okay=False, dir_okay=True, writable=True, readable=True, resolve_path=True, ) def convert(self, value, param, ctx): return Path(self.converter.convert(value, param, ctx)) @click.group() def run(): """Utilities for manipulating SolidPython and OpenSCAd code""" pass @run.command() @click.argument("project_path", type=FolderType()) def new(project_path): """Generates a new project located at the given path""" name = project_path.name generate_out_path = project_path / "generated" model_generator_path = project_path / f"{name}.py" project_path.mkdir(parents=True, exist_ok=True) generate_out_path.mkdir(parents=True, exist_ok=True) model_generator_path.write_text(TEMPLATE.format(name=name)) TEMPLATE = """#!/usr/bin/env python3 from solid import * from solid.utils import * from solid_toolbox import * def generate_model(): return rotate(60, x_axis)( cube(Vec(3, 3, 3), center=True), ) if __name__ == '__main__': model = generate_model() scad_render_to_file( model, 'generated/{name}.scad', include_orig_code=False, ) """ PK!lesolid_toolbox/curves.py#!/usr/bin/env python3 from solid_toolbox.units import Point2d _pascal_triangle = [[1], [1, 1], [1, 2, 1], [1, 3, 3, 1]] def inclusive_range(start, end): return range(start, end + 1) def binomial(n, k): # Expand cache while n >= len(_pascal_triangle): s = len(_pascal_triangle) prev_row = _pascal_triangle[s - 1] next_row = [0 for _ in range(s + 1)] next_row[0] = 1 for i in range(1, s): next_row[i] = prev_row[i - 1] + prev_row[i] next_row[s] = 1 _pascal_triangle.append(next_row) return _pascal_triangle[n][k] def bezier_curve(control_points, num_samples): def bezier(t): output = Point2d(0, 0) n = len(control_points) - 1 for k, point in enumerate(control_points): output += point * binomial(n, k) * (1 - t) ** (n - k) * t ** k return output return [bezier(i / (num_samples - 1)) for i in range(num_samples)] PK!nsolid_toolbox/poly.py#!/usr/bin/env python3 from solid import * from solid.utils import * def construct_polyhedron(faces): points = [] unique_points = {} translated_faces = [] for face in faces: translated_face = [] for point in face: if not isinstance(point, tuple): point = tuple(point) if point not in unique_points: unique_points[point] = len(points) points.append(point) translated_face.append(unique_points[point]) translated_faces.append(translated_face) return polyhedron(points=points, faces=translated_faces, convexity=10) def construct_polygon(*paths): unique_points = {} points_listing = [] path_indices = [] for path in paths: point_indices = [] for point in path: if point not in unique_points: unique_points[point] = len(unique_points) points_listing.append(point) point_indices.append(unique_points[point]) path_indices.append(point_indices) return polygon(points=points_listing, paths=path_indices) PK!bp&solid_toolbox/transforms.py#!/usr/bin/env python3 from solid import * from solid.utils import * def noop(*args): def func(transform): return transform return func def rotate_with_fake_origin(degree, axis, temp_origin): x, y, z = temp_origin def rotater(child): return translate((x, y, z))( rotate(degree, axis)(translate((-x, -y, -z))(child)) ) return rotater PK! solid_toolbox/units.py#!/usr/bin/env python3 class Vector: __slots__ = ("_items", "_len") def __init__(self, *items): self._items = items self._len = len(items) def __len__(self): return self._len def __getitem__(self, index): return self._items[index] def __iter__(self): return iter(self._items) def __repr__(self): return "[" + ", ".join(map(str, self._items)) + "]" def __str__(self): return self.__repr__() def __eq__(self, other): if type(self) == type(other) and len(self) == len(other): return all(a == b for a, b in zip(self, other)) else: return False def __hash__(self): return hash(self._items) def elem_op(self, op, other, allow_scalar=False): if isinstance(other, Vector) and len(self) == len(other): return type(self)(*[op(a, b) for a, b in zip(self._items, other._items)]) elif allow_scalar and isinstance(other, (int, float)): return type(self)(*[op(a, other) for a in self._items]) else: return NotImplemented def elem_rop(self, op, other, allow_scalar=False): if isinstance(other, Vector) and len(self) == len(other): return type(self)(*[op(a, b) for a, b in zip(other._items, self._items)]) elif allow_scalar and isinstance(other, (int, float)): return type(self)(*[op(other, a) for a in self._items]) else: return NotImplemented def __add__(self, other): return self.elem_op(lambda a, b: a + b, other) def __sub__(self, other): return self.elem_op(lambda a, b: a - b, other) def __mul__(self, other): return self.elem_op(lambda a, b: a * b, other, True) def __rmul__(self, other): return self.elem_rop(lambda a, b: a * b, other, True) def __truediv__(self, other): return self.elem_op(lambda a, b: a / b, other, True) def __rtruediv__(self, other): return self.elem_rop(lambda a, b: a / b, other, True) def __floordiv__(self, other): return self.elem_op(lambda a, b: a // b, other, True) def __rfloordiv__(self, other): return self.elem_rop(lambda a, b: a // b, other, True) def __matmul__(self, other): return self.dot(other) def dot(self, other): if isinstance(other, Vector) and len(self) == len(other): return sum((self * other)._items) else: return NotImplemented class Vec(Vector): def __init__(self, x, y, z): super().__init__(x, y, z) @property def x(self): return self[0] @property def y(self): return self[1] @property def z(self): return self[2] class Vec2d(Vector): def __init__(self, x, y): super().__init__(x, y) @property def x(self): return self[0] @property def y(self): return self[1] Point = Vec Point2d = Vec2d mm = 1 cm = 10 x_axis = x_unit = Vec(1, 0, 0) y_axis = y_unit = Vec(0, 1, 0) z_axis = z_unit = Vec(0, 0, 1) PK!SEE(solid_toolbox-0.0.4.dist-info/LICENSE.md# MIT License Copyright (c) 2018 Michael Lee Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. PK!HnHTU#solid_toolbox-0.0.4.dist-info/WHEEL A н#Z;/"d&F[xzw@Zpy3Fv]\fi4WZ^EgM_-]#0(q7PK!Hf#b&solid_toolbox-0.0.4.dist-info/METADATAMo1#qI$U"JTJJ ;٘kcBcʇr=̌gTH0DZ #U%Dgt]sfv@p/٪V^ *g V6Б64Fظp`eo«&D>ʲl4m5- ؍Tw}>e^ ۘ\wl%VHǷF "ϴM~9v:`,I 67*Fјnj %[a渚S7CpMP궁j.L4>WϯvL~x#I`p3p1~ş '6T %z6 |q30%Ϳx\HXwQ )byk [*{N2-SU6'}}|j,)/8cPK!HM;ps$solid_toolbox-0.0.4.dist-info/RECORDr@} 4. Qd6l(ZAFf*&/\Y<`\%x~)8^ Eg }vzG#$߰@f\ʼnvte BF^\4@~cKc9oZl{?&l(Z1'`^Ȏ2:IR,G Qү'Tnh] z:~̟=!=zQEe*@= ޠ9q@^?7~@9huz̻=jN3=`D'j}7 y~Y6[m5m_٩-"mȌ\:xT\Lq,hfŬUV.OU;ڪ~0Nf_x U&t픤߇Kpim-+P10>u!5OȞs]^1P+RԂQQjpѦDICw4r6PK!r++solid_toolbox/__init__.pyPK!Liibsolid_toolbox/__main__.pyPK![Esolid_toolbox/commands.pyPK!le solid_toolbox/curves.pyPK!n solid_toolbox/poly.pyPK!bp&solid_toolbox/transforms.pyPK! solid_toolbox/units.pyPK!SEE({ solid_toolbox-0.0.4.dist-info/LICENSE.mdPK!HnHTU#%solid_toolbox-0.0.4.dist-info/WHEELPK!Hf#b&%solid_toolbox-0.0.4.dist-info/METADATAPK!HM;ps$l'solid_toolbox-0.0.4.dist-info/RECORDPK 7)