# Examples from pyvista.PolyData.face_offsets
# ===========================================

import pyvista as pv
points = pv.Rectangle().points
mesh = pv.PolyData.from_regular_faces(points, [[0, 1, 2], [1, 3, 2]])
mesh.face_offsets

# The offsets and connectivity together describe each face.
mesh.face_connectivity[mesh.face_offsets[0] : mesh.face_offsets[1]]

# The array is read-only and writing to it raises a `ValueError`.
mesh.face_offsets.flags['WRITEABLE']

# Assign a new array instead. Here the six connectivity ids are re-partitioned
# into three 2-point cells.
mesh.face_offsets = [0, 2, 4, 6]
mesh.n_faces

# To replace the offsets and connectivity together, assign a
# `pyvista.CellArray` to `faces`.
mesh.faces = pv.CellArray.from_arrays([0, 4], [0, 1, 3, 2])
mesh.n_faces

# ----------------------------------------------------------------------
# Generated by sphinx-examples-as-code https://github.com/pyvista/sphinx-examples-as-code
