Skip to content

Commit f85982a

Browse files
committed
feat: align_layout()
1 parent bddaefb commit f85982a

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

src/_igraph/igraphmodule.c

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
230263
PyObject* 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"

src/igraph/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
TREE_UNDIRECTED,
6363
Vertex,
6464
WEAK,
65+
align_layout,
6566
arpack_options as default_arpack_options,
6667
community_to_membership,
6768
convex_hull,
@@ -1202,6 +1203,7 @@ def write(graph, filename, *args, **kwds):
12021203
"VertexCover",
12031204
"VertexDendrogram",
12041205
"VertexSeq",
1206+
"align_layout",
12051207
"autocurve",
12061208
"color_name_to_rgb",
12071209
"color_name_to_rgba",

0 commit comments

Comments
 (0)