.. rst-class:: lead
COMPAS 2 introduced a number of breaking changes with respect to COMPAS 1. This page summarises the changes that are most likely to affect existing code, and shows how to update it.
Note
This is a condensed overview.
The complete list of changes is available in the changelog,
in particular in the entries for 2.0.0-alpha.1 up to 2.0.0.
compas.artists no longer exists.
Visualisation is handled by :class:`compas.scene.Scene` and the corresponding scene objects.
# COMPAS 1.x
from compas_rhino.artists import MeshArtist
artist = MeshArtist(mesh, layer="Test")
artist.draw()# COMPAS 2.x
from compas.scene import Scene
scene = Scene()
scene.add(mesh)
scene.draw()*Artistclasses are renamed to*SceneObjectand live incompas.scene,compas_rhino.scene,compas_ghpython.scene, andcompas_blender.scene.- Context related functions (
register,build,redraw,clear) moved tocompas.scene.context, andScene.redrawwas renamed toScene.draw. - The naming convention of the color dict attributes changed,
for example from
vertex_colortovertexcolor, and fromnode_colortonodecolor. - What is drawn is controlled with flags rather than with keyword arguments:
show,show_points,show_lines,show_surfaces,show_vertices,show_edges,show_faces,show_cells. Each of these optionally accepts a sequence of keys instead of a boolean. - Scene objects form a tree, with
parent,children,add(),frame, andworldtransformation. Scenes are serialisable. - The label drawing methods (
draw_vertexlabels,draw_edgelabels,draw_facelabels,draw_celllabels) and the keyword arguments ofdrawwere removed. Set the corresponding attributes on the scene object instead.
The interface of :class:`compas.data.Data` is based on dunder attributes.
| COMPAS 1.x | COMPAS 2.x |
|---|---|
obj.data |
obj.__data__ |
obj.dtype |
obj.__dtype__ |
Cls.from_data(data) |
Cls.__from_data__(data) |
obj.to_data() |
removed, use obj.__data__ |
obj.data = data |
removed, there are no data setters |
- The JSON schema machinery was removed:
DATASCHEMA,JSONSCHEMANAME,validate_data,validate_json,validate_jsondata,validate_jsonstring,json_validate, and the bundled schema files. - :meth:`compas.data.Data.to_jsonstring` and :meth:`compas.data.Data.from_jsonstring` were added, as well as :func:`compas.json_dumpz` and :func:`compas.json_loadz` for ZIP compressed JSON files.
to_json,to_jsonstring, :func:`compas.json_dump`, and :func:`compas.json_dumps` take an additionalcompact=Falseparameter.Data.nameis only included in the serialised data if it was explicitly set.
Because of the datastructure changes described below, JSON files written with COMPAS 1 cannot be read with COMPAS 2, and vice versa.
Halfedgewas merged into :class:`compas.datastructures.Mesh`,Halffaceinto :class:`compas.datastructures.VolMesh`, andNetworkinto :class:`compas.datastructures.Graph`.Networkremains available as an alias ofGraph, butGraphis preferred.The standalone functions were replaced by methods.
COMPAS 1.x
COMPAS 2.x
mesh_weld(mesh)mesh.weld()meshes_join(meshes)Mesh.join(meshes)mesh_offset(mesh, d)mesh.offset(d)mesh_thicken(mesh, t)mesh.thickened(t)mesh_transform(mesh, T)mesh.transform(T)mesh_quads_to_triangles(mesh)mesh.quads_to_triangles()mesh_unify_cycles(mesh)mesh.unify_cycles()mesh_bounding_box(mesh)mesh.aabb()mesh_explode(mesh)mesh.exploded()network_shortest_path(network, u, v)graph.shortest_path(u, v)network_adjacency_matrix(network)graph.adjacency_matrix()Edges are identified by a single identifier instead of by two separate vertices.
# COMPAS 1.x mesh.edge_length(u, v) # COMPAS 2.x mesh.edge_length((u, v))
This applies to all edge based methods, among others
edge_faces,halfedge_face,halfedge_after,halfedge_before,edge_point,edge_midpoint,edge_vector,split_edge, andcollapse_edge.Methods returning geometry now return COMPAS geometry objects instead of tuples:
vertex_normal,vertex_laplacian,neighborhood_centroid,edge_vector,edge_direction,edge_point,edge_midpoint,face_normal,face_centroid,face_center, andface_plane.key_indexandindex_keywere replaced byvertex_index/index_vertex,node_index/index_node, andedge_index/index_edge.mesh.subdivide()was renamed tomesh.subdivided().:class:`compas.datastructures.Datastructure` provides
transform(ed),translate(d),rotate(d), andscale(d).:class:`compas.datastructures.Tree`, :class:`compas.datastructures.TreeNode`, and :class:`compas.datastructures.CellNetwork` were added.
compas.PRECISION and compas.set_precision were replaced by
:class:`compas.tolerance.Tolerance` and its singleton instance TOL.
# COMPAS 1.x
import compas
from compas.utilities import geometric_key
compas.set_precision(3)
key = geometric_key(point)# COMPAS 2.x
from compas.tolerance import TOL
TOL.precision = 3
key = TOL.geometric_key(point)TOL exposes absolute, relative, angular, approximation, precision,
and lineardeflection, together with comparison helpers such as is_zero, is_close,
is_allclose, and formatting helpers such as format_number.
See :doc:`advanced.tolerance` for more information.
Note that __str__ of :class:`compas.geometry.Point` and :class:`compas.geometry.Vector`
uses a limited number of decimals (based on TOL.precision),
whereas __repr__ maintains full precision.
| COMPAS 1.x | COMPAS 2.x |
|---|---|
compas.robots |
compas_robots (including the URDF parser, previously in compas.files) |
compas.numerical.fd_numpy |
compas_fd |
compas.numerical.dr, compas.numerical.dr_numpy |
compas_dr |
compas.numerical.topop_numpy |
compas_topopt |
compas.numerical.pca_numpy |
compas.geometry.pca_numpy |
compas.numerical.scalarfield_contours |
compas.geometry.scalarfield_contours |
compas.numerical.mma, lma, ga, devo, descent |
removed |
compas.brep |
compas.geometry.brep |
compas.utilities.itertools |
compas.itertools |
compas_rhino.forms |
removed |
compas.rpc.XFunc |
removed |
The CAD packages were flattened as well:
compas_rhino.utilities.objects became compas_rhino.objects,
compas_rhino.utilities.layers became compas_rhino.layers,
and the drawing modules of compas_rhino, compas_ghpython, and compas_blender
moved out of their respective utilities subpackages.
compas_ghpython.utilities was removed entirely in 2.5.
compas.geometry.Primitivewas removed. :class:`compas.geometry.Arc`, :class:`compas.geometry.Bezier`, :class:`compas.geometry.Circle`, :class:`compas.geometry.Ellipse`, :class:`compas.geometry.Line`, and :class:`compas.geometry.Polyline` are derived from :class:`compas.geometry.Curve`, and :class:`compas.geometry.Transformation` is derived from :class:`compas.data.Data`.- Analytical surfaces were added: :class:`compas.geometry.PlanarSurface`, :class:`compas.geometry.CylindricalSurface`, :class:`compas.geometry.SphericalSurface`, :class:`compas.geometry.ConicalSurface`, and :class:`compas.geometry.ToroidalSurface`, as well as the curves :class:`compas.geometry.Hyperbola` and :class:`compas.geometry.Parabola`.
NurbsSurface.u_spaceandv_spacebecamespace_uandspace_v, andu_isocurveandv_isocurvebecameisocurve_uandisocurve_v.Brep.from_step_filewas renamed toBrep.from_step, and the signature ofBrep.slicechanged.- The X and Y axis are optional in the constructor of :class:`compas.geometry.Frame`.
- Indexed attribute access was removed from all geometry classes except
Point,Vector,Line,Polygon, andPolyline. - The conversion classes of
compas_rhino.conversionswere replaced by functions, for examplemesh_to_rhino,mesh_to_compas,box_to_rhino,curve_to_compas.
- :func:`compas.geometry.oriented_bounding_box_numpy` minimizes volume, which means results can differ from COMPAS 1.
Graph.delete_edgeno longer deletes the edge in the opposite direction.- :func:`compas.geometry.earclip_polygon` was reimplemented, because the previous implementation did not handle all cases.
is_planarrelies on NetworkX (>=3.0) instead of onplanarity.__all__was removed beyond the second level of the package, so deep imports of previously re-exported names may need to be updated.