/** * Find the largest region that satisfies a constraint. * * There might be more than one solution. This function makes no * guarantees about which solution it will choose in this case. */ PedGeometry* ped_constraint_solve_max (const PedConstraint* constraint) { PedDevice* dev; PedGeometry full_dev; if (!constraint) return NULL; dev = constraint->start_range->dev; ped_geometry_init (&full_dev, dev, 0, dev->length - 1); return ped_constraint_solve_nearest (constraint, &full_dev); }
static int loop_partition_align (PedPartition* part, const PedConstraint* constraint) { PedGeometry* new_geom; new_geom = ped_constraint_solve_nearest (constraint, &part->geom); if (!new_geom) { ped_exception_throw ( PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL, _("Unable to satisfy all constraints on the " "partition.")); return 0; } ped_geometry_set (&part->geom, new_geom->start, new_geom->length); ped_geometry_destroy (new_geom); return 1; }
PyObject *py_ped_constraint_solve_nearest(PyObject *s, PyObject *args) { PyObject *in_geometry = NULL; PedConstraint *constraint = NULL; PedGeometry *out_geometry = NULL; PedGeometry *geometry = NULL; _ped_Geometry *ret = NULL; if (!PyArg_ParseTuple(args, "O!", &_ped_Geometry_Type_obj, &in_geometry)) { return NULL; } constraint = _ped_Constraint2PedConstraint(s); if (constraint == NULL) { return NULL; } out_geometry = _ped_Geometry2PedGeometry(in_geometry); if (out_geometry == NULL) { ped_constraint_destroy(constraint); return NULL; } geometry = ped_constraint_solve_nearest(constraint, out_geometry); ped_constraint_destroy(constraint); if (geometry) { ret = PedGeometry2_ped_Geometry(geometry); } else { PyErr_SetString(PyExc_ArithmeticError, "Could not find region nearest to constraint for given geometry"); return NULL; } return (PyObject *) ret; }