# Examples from pyvista.PolyData.face_connectivity
# ================================================

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

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

# Assign a new array instead. Here the winding of both triangles is reversed.
mesh.face_connectivity = [2, 1, 0, 2, 3, 1]
mesh.face_connectivity

# For a mesh large enough that the copy matters, keep the connectivity array and
# edit it in place.
import numpy as np
connectivity = np.array([0, 1, 2, 1, 3, 2], dtype=pv.ID_TYPE)
mesh.faces = pv.CellArray.from_arrays([0, 3, 6], connectivity, deep=False)
connectivity[:] = [0, 2, 1, 1, 2, 3]
mesh.face_connectivity

# Note that arrays derived from the old topology, such as `'Normals'`, are not
# recomputed by either approach and should be removed or regenerated.

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