@@ -227,6 +227,39 @@ PyObject* igraphmodule_set_status_handler(PyObject* self, PyObject* o) {
227227 Py_RETURN_NONE ;
228228}
229229
230+ PyObject * igraphmodule_align_layout (PyObject * self , PyObject * args , PyObject * kwds ) {
231+ static char * kwlist [] = {"graph" , "layout" , NULL };
232+ PyObject * pygraph , * pylayout ;
233+ PyObject * res ;
234+ const igraph_t * graph ;
235+ igraph_matrix_t layout ;
236+
237+ if (!PyArg_ParseTupleAndKeywords (args , kwds , "OO" , kwlist , & PyList_Type , & pygraph , & pylayout )) {
238+ return NULL ;
239+ }
240+
241+ graph = PyIGraph_ToCGraph (pygraph );
242+ if (graph == NULL ) {
243+ return NULL ;
244+ }
245+
246+ if (! igraphmodule_PyObject_to_matrix_t (pylayout , & layout , "layout" )) {
247+ return NULL ;
248+ }
249+
250+ if (! igraph_layout_align (graph , & layout )) {
251+ igraphmodule_handle_igraph_error ();
252+ igraph_matrix_destroy (& layout );
253+ return NULL ;
254+ }
255+
256+ res = igraphmodule_matrix_t_to_PyList (& layout , IGRAPHMODULE_TYPE_FLOAT );
257+
258+ igraph_matrix_destroy (& layout );
259+
260+ return res ;
261+ }
262+
230263PyObject * igraphmodule_convex_hull (PyObject * self , PyObject * args , PyObject * kwds ) {
231264 static char * kwlist [] = {"vs" , "coords" , NULL };
232265 PyObject * vs , * o , * o1 = 0 , * o2 = 0 , * o1_float , * o2_float , * coords = Py_False ;
@@ -790,6 +823,14 @@ static PyMethodDef igraphmodule_methods[] =
790823 METH_VARARGS | METH_KEYWORDS ,
791824 "_power_law_fit(data, xmin=-1, force_continuous=False, p_precision=0.01)\n--\n\n"
792825 },
826+ {"align_layout" , (PyCFunction )igraphmodule_align_layout ,
827+ METH_VARARGS | METH_KEYWORDS ,
828+ "align_layout(graph, layout)\n--\n\n"
829+ "Align a graph layout with the coordinate axes.\n\n"
830+ "@param graph: the graph whose layout to align\n"
831+ "@param layout: the vertex coordinates\n"
832+ "@return: the aligned vertex coordinates."
833+ },
793834 {"convex_hull" , (PyCFunction )igraphmodule_convex_hull ,
794835 METH_VARARGS | METH_KEYWORDS ,
795836 "convex_hull(vs, coords=False)\n--\n\n"
0 commit comments