/** * Return a constraint that requires a region to satisfy both \p a and \p b. * * Moreover, any region satisfying \p a and \p b will also satisfy the returned * constraint. * * \return \c NULL if no solution could be found (note that \c NULL is a valid * PedConstraint). */ PedConstraint* ped_constraint_intersect (const PedConstraint* a, const PedConstraint* b) { PedAlignment* start_align; PedAlignment* end_align; PedGeometry* start_range; PedGeometry* end_range; PedSector min_size; PedSector max_size; PedConstraint* constraint; if (!a || !b) return NULL; start_align = ped_alignment_intersect (a->start_align, b->start_align); if (!start_align) goto empty; end_align = ped_alignment_intersect (a->end_align, b->end_align); if (!end_align) goto empty_destroy_start_align; start_range = ped_geometry_intersect (a->start_range, b->start_range); if (!start_range) goto empty_destroy_end_align; end_range = ped_geometry_intersect (a->end_range, b->end_range); if (!end_range) goto empty_destroy_start_range; min_size = PED_MAX (a->min_size, b->min_size); max_size = PED_MIN (a->max_size, b->max_size); constraint = ped_constraint_new ( start_align, end_align, start_range, end_range, min_size, max_size); if (!constraint) goto empty_destroy_end_range; ped_alignment_destroy (start_align); ped_alignment_destroy (end_align); ped_geometry_destroy (start_range); ped_geometry_destroy (end_range); return constraint; empty_destroy_end_range: ped_geometry_destroy (end_range); empty_destroy_start_range: ped_geometry_destroy (start_range); empty_destroy_end_align: ped_alignment_destroy (end_align); empty_destroy_start_align: ped_alignment_destroy (start_align); empty: return NULL; }
PyObject *py_ped_alignment_intersect(PyObject *s, PyObject *args) { PyObject *in_b = NULL; PedAlignment *out_a = NULL, *out_b = NULL, *align = NULL; _ped_Alignment *ret = NULL; if (!PyArg_ParseTuple(args, "O!", &_ped_Alignment_Type_obj, &in_b)) { return NULL; } out_a = _ped_Alignment2PedAlignment(s); if (out_a == NULL) { return NULL; } out_b = _ped_Alignment2PedAlignment(in_b); if (out_b == NULL) { return NULL; } align = ped_alignment_intersect(out_a, out_b); ped_alignment_destroy(out_a); ped_alignment_destroy(out_b); if (align) { ret = PedAlignment2_ped_Alignment(align); } else { PyErr_SetString(PyExc_ArithmeticError, "Could not find alignment intersection"); return NULL; } ped_alignment_destroy(align); return (PyObject *) ret; }