From daa5bb4f965e62e2d2bdbf1e7ad5fcfe0c0ee10b Mon Sep 17 00:00:00 2001 From: B R S Recht Date: Wed, 3 May 2017 20:55:43 -0400 Subject: [PATCH] Various fixes --- antitile/off.py | 26 +++++++++++++++----------- bin/breakdown.py | 1 + bin/cellular.py | 19 +++++++++---------- bin/factor.py | 1 - bin/sgsstats.py | 4 +++- bin/svg_subdiv.py | 1 + bin/view_off.py | 2 +- setup.py | 2 +- 8 files changed, 31 insertions(+), 25 deletions(-) diff --git a/antitile/off.py b/antitile/off.py index dde4195..d14fafc 100644 --- a/antitile/off.py +++ b/antitile/off.py @@ -84,11 +84,11 @@ def load_off(file): faces.append(vx) facecolors.append(colorspec) - edges = np.array(edges, dtype=int) - verts = np.array(verts, dtype=int) - facecolors = np.array(facecolors) - edgecolors = np.array(edgecolors) - vertexcolors = np.array(vertexcolors) + edges = None if len(edges) == 0 else np.array(edges, dtype=int) + verts = None if len(verts) == 0 else np.array(verts, dtype=int) + facecolors = None if len(facecolors) == 0 else np.array(facecolors) + edgecolors = None if len(edgecolors) == 0 else np.array(edgecolors) + vertexcolors = None if len(vertexcolors) == 0 else np.array(vertexcolors) return (vertices, faces, facecolors, edges, edgecolors, verts, vertexcolors) @@ -107,21 +107,25 @@ def write_off(vertices, faces, facecolors=None, edges=None, edgecolors=None, vertexcolors: List of colors corresponding to each vertex """ #align the "faces" into a single list - if facecolors is None and faces is not None: + if (facecolors is None or len(facecolors) == 0) and faces is not None: facecolors = ['']*len(faces) - if edgecolors is None and edges is not None: + if (edgecolors is None or len(edgecolors) == 0) and edges is not None: edgecolors = ['']*len(edges) - if vertexcolors is None and verts is not None: + if (vertexcolors is None or len(vertexcolors) == 0) and verts is not None: + print('woo') vertexcolors = ['']*len(verts) elif vertexcolors is not None and verts is None: verts = list(range(len(vertices))) if len(faces) != len(facecolors): - raise ValueError("Different number of face colors than faces") + msg = "Different number of face colors than faces: {}, {}" + raise ValueError(msg.format(len(faces), len(facecolors))) elif edgecolors is not None and len(edges) != len(edgecolors): - raise ValueError("Different number of edge colors than edges") + msg ="Different number of edge colors than edges: {}, {}" + raise ValueError(msg.format(len(edges), len(edgecolors))) elif vertexcolors is not None and len(verts) != len(vertexcolors): - raise ValueError("Different number of vertex colors than vertices") + msg = "Different number of vertex colors than vertices: {}, {}" + raise ValueError(msg.format(len(verts), len(vertexcolors))) flist = list(faces) if edges is not None: diff --git a/bin/breakdown.py b/bin/breakdown.py index 228af63..8119403 100644 --- a/bin/breakdown.py +++ b/bin/breakdown.py @@ -1,3 +1,4 @@ +#! /usr/bin/env python3 # -*- coding: utf-8 -*- """ Demonstrative figures of the different breakdowns and methods. diff --git a/bin/cellular.py b/bin/cellular.py index b58c865..72b0c58 100644 --- a/bin/cellular.py +++ b/bin/cellular.py @@ -1,9 +1,7 @@ +#! /usr/bin/env python3 # -*- coding: utf-8 -*- """ -Created on Fri Apr 14 15:01:28 2017 - -@author: Bstone -""" +Cellular automata on the faces (or vertices) of polyhedra""" import argparse from sys import stdin @@ -46,7 +44,7 @@ def main(): parser.add_argument("-v", help=NEIGHBOR, action='store_true') parser.add_argument("-d", action='store_true', help="Color the vertices " "as if the cellular automata were operating on " - "the dual polyhedron/tiling") + "the dual polyhedron/tiling") parser.add_argument("-o", help="Output prefix.", default="cellular") args = parser.parse_args() file = open(args.filename) if args.filename else stdin @@ -55,8 +53,9 @@ def main(): init = vc if args.d else fc if init is None: init = np.random.randint(2, size=len(faces)) - elif len(init.shape) > 1: - raise ValueError("Need color indexes, not color values") + init = np.asarray(init) + if len(init.shape) > 1: + raise ValueError("Need color indexes, not color values") poly = tiling.Tiling(vertices, faces) if args.d: adj = poly.vertex_f_adjacency if args.v else poly.vertex_adjacency @@ -74,10 +73,10 @@ def main(): result = this_state.astype(int) if args.d: string = off.write_off(vertices, faces, facecolors=fc, edges=e, - edgecolors=ec, vertexcolors=result) + edgecolors=ec, vertexcolors=result) else: - string = off.write_off(vertices, faces, facecolors=result, edges=e, - edgecolors=ec, vertexcolors=vc) + string = off.write_off(vertices, faces, facecolors=result, + edges=e, edgecolors=ec, vertexcolors=vc) fn = file_template.format(i + 1) with open(fn, 'w') as f: f.write(string) diff --git a/bin/factor.py b/bin/factor.py index df29f1a..aba3b88 100644 --- a/bin/factor.py +++ b/bin/factor.py @@ -7,7 +7,6 @@ import argparse from collections import Counter -#norm, mod, natural prime mod class DOMAINS = {"i": factor.Integer, "g": factor.Gaussian, "e": factor.Eisenstein, diff --git a/bin/sgsstats.py b/bin/sgsstats.py index 5e0f4d7..aff71d2 100644 --- a/bin/sgsstats.py +++ b/bin/sgsstats.py @@ -1,6 +1,8 @@ +#! /usr/bin/env python3 # -*- coding: utf-8 -*- """ - +Statistics of polyhedra, with a focus on using similar grid subdivision +polyhedra to approximate the sphere """ import argparse import csv diff --git a/bin/svg_subdiv.py b/bin/svg_subdiv.py index e440214..efbae69 100644 --- a/bin/svg_subdiv.py +++ b/bin/svg_subdiv.py @@ -1,3 +1,4 @@ +#! /usr/bin/env python3 # -*- coding: utf-8 -*- """ Creates SVG files for each subdivision square diff --git a/bin/view_off.py b/bin/view_off.py index 44e4a4c..a83da8a 100644 --- a/bin/view_off.py +++ b/bin/view_off.py @@ -1,4 +1,4 @@ -#! /usr/bin/env python +#! /usr/bin/env python3 # -*- coding: utf-8 -*- """ Visualizes OFF files using matplotlib, which allows for export to png, svg, diff --git a/setup.py b/setup.py index 76043ff..161ec4e 100755 --- a/setup.py +++ b/setup.py @@ -4,7 +4,7 @@ from setuptools import setup setup(name='antitile', - version='20170427', + version='20170503', description='Tiling subdivision scripts, for use with Antiprism', url='http://github.com/brsr/antitile', author='B R S Recht',