def printAll(): figures=objFigure.fromGfFigure(gf.figureGet()) if not figures: gf.echo("Nothing opened") else: if name: fileName=None if filePath: fileName=os.path.basename(filePath) n=name if fileName: n += ' (' + fileName + ')' if modified: n += ' (modified)' gf.echo(n) if description: gf.echo(str.join("\n", [" "+s for s in description.split("\n")])) gf.echo("Content:") cntsD=dict() groupLines=False for f in figures: cnts=counts(f) if cnts in cntsD: cntsD[cnts]+=1 groupLines=True else: cntsD[cnts]=1 for cnts in cntsD: if not groupLines: gf.echo(" "+countsToStr(cnts)) elif cntsD[cnts]==1: gf.echo(" "+countsToStr(cnts)) else: gf.echo(("%4d" % cntsD[cnts])+"x "+countsToStr(cnts))
def printAll(): figures = objFigure.fromGfFigure(gf.figureGet()) if not figures: gf.echo("Nothing opened") else: if name: fileName = None if filePath: fileName = os.path.basename(filePath) n = name if fileName: n += ' (' + fileName + ')' if modified: n += ' (modified)' gf.echo(n) if description: gf.echo( str.join("\n", [" " + s for s in description.split("\n")])) gf.echo("Content:") cntsD = dict() groupLines = False for f in figures: cnts = counts(f) if cnts in cntsD: cntsD[cnts] += 1 groupLines = True else: cntsD[cnts] = 1 for cnts in cntsD: if not groupLines: gf.echo(" " + countsToStr(cnts)) elif cntsD[cnts] == 1: gf.echo(" " + countsToStr(cnts)) else: gf.echo(("%4d" % cntsD[cnts]) + "x " + countsToStr(cnts))
def commandStellate(): figures=objFigure.fromGfFigure(gf.figureGet()) if figureInfo: name,desc=figureInfo.getNameDesc() figures=[stellateFigure(f) for f in figures] if name: name="Stellated " + name desc=None gf.figureOpen(objFigure.toGfFigure(figures), True) if figureInfo: figureInfo.setNameDescPath(name, desc)
def commandIsConvex(): figures=objFigure.fromGfFigure(gf.figureGet()) for f in figures: if not isFigureConvex(f): gf.echo("The figure is not convex.") return cnt=len(figures) if len(figures)>1: gf.echo("All figures are convex.") else: gf.echo("The figure is convex.")
def commandCreateDual(): figures=objFigure.fromGfFigure(gf.figureGet()) for f in figures: if not check.isFigureConvex(f): raise RuntimeError("The figure is not convex") if figureInfo: name, desc = figureInfo.getNameDesc() figures=[createDual(f) for f in figures] gf.figureOpen(objFigure.toGfFigure(figures), True) if figureInfo: figureInfo.setNameDescPath("Dual of " + name, None)
def createConvexObjFigure(vertices): import objFigure if vertices: gfFigure=[vertices]+[[]]*len(vertices[0]) gfFigure=gf.figureConvexHullUpdate(gfFigure) figures=objFigure.fromGfFigure(gfFigure) if len(figures)>1: figures=[f for f in figures if f.dim>0] if len(figures)!=1: raise RuntimeError("Unspecified error occurred") return figures.pop() else: return None
def createConvexObjFigure(vertices): import objFigure if vertices: gfFigure=[vertices]+[[]]*len(vertices[0]) gfFigure=gf.figureConvexHullUpdate(gfFigure) gfFigure[0]=vertices; # to avoid rounding, tuples will have the same hash as original figures=objFigure.fromGfFigure(gfFigure) if len(figures)>1: figures=[f for f in figures if f.dim>0] if len(figures)!=1: raise RuntimeError("Unspecified error occurred") return figures.pop() else: return None
def createConvexObjFigure(vertices): import objFigure if vertices: gfFigure = [vertices] + [[]] * len(vertices[0]) gfFigure = gf.figureConvexHullUpdate(gfFigure) gfFigure[0] = vertices # to avoid rounding, tuples will have the same hash as original figures = objFigure.fromGfFigure(gfFigure) if len(figures) > 1: figures = [f for f in figures if f.dim > 0] if len(figures) != 1: raise RuntimeError("Unspecified error occurred") return figures.pop() else: return None
def printAll(): figures=objFigure.fromGfFigure(gf.figureGet()) if not figures: gf.echo("Nothing opened") else: if name: fileName=None if filePath: fileName=os.path.basename(filePath) n=name if fileName: n += ' (' + fileName + ')' if modified: n += ' (modified)' gf.echo(n) if description: gf.echo(str.join("\n", [" "+s for s in description.split("\n")])) gf.echo("Content:") gf.echo(str.join("\n", [" "+counts(f) for f in figures]))
def commandCutOff(lastCoordinate=0): gfFigure=gf.figureGet() if gfFigure: gfFigure[0]=[gf.posRotate(p) for p in gfFigure[0]] figures=objFigure.fromGfFigure(gfFigure) if not figures: raise RuntimeError("Nothing opened") dim=figures[0].spaceDim hyperplane=algebra.Hyperplane((0,)*(dim-1)+(1,), lastCoordinate) newFigures=[] for f in figures: newFigures.extend(cutFigure(f, hyperplane)[0]) gfFigure=objFigure.toGfFigure(newFigures) if gfFigure: gfFigure[0]=[gf.posRotateBack(p) for p in gfFigure[0]] if figureInfo: name, desc=figureInfo.getNameDesc() gf.figureOpen(gfFigure, True) if figureInfo: figureInfo.setNameDescPath("Truncated "+name, None)
def commandCutFigure(lastCoordinate=0): gfFigure=gf.figureGet() gfFigure[0]=[gf.posRotate(p) for p in gfFigure[0]] figures=objFigure.fromGfFigure(gfFigure) if not figures: raise RuntimeError("Nothing opened") dim=figures[0].spaceDim if dim<=0: raise RuntimeError("The figure cannot be cut") hyperplane=algebra.Hyperplane((0,)*(dim-1)+(1,), lastCoordinate) newFigures=[] for f in figures: newFigures.extend(cutFigure(f, hyperplane)[1]) gfFigure=objFigure.toGfFigure(newFigures) if gfFigure: gfFigure[0]=[p[:-1] for p in gfFigure[0]] del gfFigure[dim] if figureInfo: name, desc=figureInfo.getNameDesc() gf.figureOpen(gfFigure) if figureInfo: figureInfo.setNameDescPath("Cross-section of "+name, None)
def commandCutFaces(dim=2, ratio=0.1): if ratio>=1 or ratio<=0: raise RuntimeError("Wrong ratio") figures=objFigure.fromGfFigure(gf.figureGet()) for f in figures: if not check.isFigureConvex(f): raise RuntimeError("The figure is not convex") if figureInfo: name, desc = figureInfo.getNameDesc() figures2=[] for f in figures: figures2.extend(cutOffFacesDim(f, ratio, dim)) gf.figureOpen(objFigure.toGfFigure(figures2), True) gf.clear() if dim==0: name = name + " with vertices cut off" elif dim==1: name = name + " with edges cut off" else: name = name + " with " + str(dim) + "-faces cut off" if figureInfo: figureInfo.setNameDescPath(name, None)