def test_planar_square_1(self): pts = np.array([[0, 0.5, 1, 1, 0], [0, 0, 0, 1, 1], [0, 0, 0, 0, 0]], dtype=np.float) pt = np.array([0.2, 0.3, 0]) self.assertTrue(cg.is_point_in_cell(pts, pt)) pt = np.array([1.1, 0.5, 0]) self.assertTrue(not cg.is_point_in_cell(pts, pt)) pt = np.array([-0.1, 0.5, 0]) self.assertTrue(not cg.is_point_in_cell(pts, pt)) pt = np.array([0.5, 1.1, 0]) self.assertTrue(not cg.is_point_in_cell(pts, pt)) pt = np.array([0.5, -0.1, 0]) self.assertTrue(not cg.is_point_in_cell(pts, pt)) pt = np.array([1.1, 1.1, 0]) self.assertTrue(not cg.is_point_in_cell(pts, pt)) pt = np.array([-0.1, 1.1, 0]) self.assertTrue(not cg.is_point_in_cell(pts, pt)) pt = np.array([-0.1, -0.1, 0]) self.assertTrue(not cg.is_point_in_cell(pts, pt)) pt = np.array([1.1, -0.1, 0]) self.assertTrue(not cg.is_point_in_cell(pts, pt))
def test_planar_convex(self): pts = np.array([[0, 1, 1.2, 0.5, -0.2], [0, 0, 1, 1.2, 1], [0, 0, 0, 0, 0]], dtype=np.float) pt = np.array([0.2, 0.3, 0]) assert cg.is_point_in_cell(pts, pt) pt = np.array([0.5, 1, 0]) assert cg.is_point_in_cell(pts, pt) pt = np.array([1.3, 0.5, 0]) assert not cg.is_point_in_cell(pts, pt) pt = np.array([-0.1, 0.5, 0]) assert not cg.is_point_in_cell(pts, pt) pt = np.array([1.1, -0.1, 0]) assert not cg.is_point_in_cell(pts, pt)
def plot_over_line(gb, pts, name, tol): values = np.zeros(pts.shape[1]) is_found = np.zeros(pts.shape[1], dtype=np.bool) for g, d in gb: if g.dim < gb.dim_max(): continue if not cg.is_planar(np.hstack((g.nodes, pts)), tol=1e-4): continue faces_cells, _, _ = sps.find(g.cell_faces) nodes_faces, _, _ = sps.find(g.face_nodes) normal = cg.compute_normal(g.nodes) for c in np.arange(g.num_cells): loc = slice(g.cell_faces.indptr[c], g.cell_faces.indptr[c + 1]) pts_id_c = np.array([ nodes_faces[g.face_nodes.indptr[f]:g.face_nodes.indptr[f + 1]] for f in faces_cells[loc] ]).T pts_id_c = sort_points.sort_point_pairs(pts_id_c)[0, :] pts_c = g.nodes[:, pts_id_c] mask = np.where(np.logical_not(is_found))[0] if mask.size == 0: break check = np.zeros(mask.size, dtype=np.bool) last = False for i, pt in enumerate(pts[:, mask].T): check[i] = cg.is_point_in_cell(pts_c, pt) if last and not check[i]: break is_found[mask] = check values[mask[check]] = d[name][c] return values