[docs]defwrap_list(list_,idx):# type: (list, int) -> Any"""Return value at index, wrapping if necessary. Parameters ---------- list_ : :class:`list` List to wrap around. idx : :class:`int` Index of item to return in list. Returns ------- :class:`list` element Item at given index, index will be wrapped if necessary. """returnlist_[idx%len(list_)]
[docs]defensure_frame(frame_like):# type: (Any) -> cg.Frame"""Convert geometry objects to :class:`compas.geometry.Frame`. Parameters ---------- frame_like Frame like object, currently :class:`compas.geometry.Frame`, :class:`compas.geometry.Plane`, :class:`compas.geometry.Point`, :class:`Rhino.Geometry.Plane`, or :class:`Rhino.Geometry.Point3d`. Returns ------- :class:`compas.geometry.Frame` Notes ----- If a point is given the point is used as the frames origin and the X and Y will be the X and Y unit vectors. :class:`compas.geometry.Plane` is defined only by origin and normal, the X and Y axis will be chosen arbitrarely, see :meth:`compas.geometry.Frame.from_plane`. """ifisinstance(frame_like,cg.Frame):returnframe_likeifisinstance(frame_like,cg.Plane):returncg.Frame.from_plane(frame_like)ifisinstance(frame_like,cg.Point):returncg.Frame(frame_like,[1,0,0],[0,1,0])try:# try to compare to Rhino objectsimportRhino.Geometryasrgfromrapid_clay_formations_fab.rhinoimportrgplane_to_cgframefromrapid_clay_formations_fab.rhinoimportrgpoint_to_cgpointifisinstance(frame_like,rg.Plane):returnrgplane_to_cgframe(frame_like)ifisinstance(frame_like,rg.Point3d):pt=rgpoint_to_cgpoint(frame_like)returncg.Frame(pt,[1,0,0],[0,1,0])exceptImportError:passraiseTypeError("Can't convert {} to compas.geometry.Frame".format(type(frame_like)))