void MoleculeLayoutGraph::_assignFirstCycle (const Cycle &cycle) { // TODO: Start drawing from vertex with maximum code and continue to the right with one of two which has maximum code int i, n; float phi; n = cycle.vertexCount(); for (i = 0; i < n; i++) { _layout_vertices[cycle.getVertex(i)].type = ELEMENT_BOUNDARY; _layout_edges[cycle.getEdge(i)].type = ELEMENT_BOUNDARY; } _first_vertex_idx = cycle.getVertex(0); _layout_vertices[cycle.getVertex(0)].pos.set(0.f, 0.f); _layout_vertices[cycle.getVertex(1)].pos.set(1.f, 0.f); phi = (float)M_PI * (n - 2) / n; for (i = 1; i < n - 1; i++) { const Vec2f &v1 = _layout_vertices[cycle.getVertex(i - 1)].pos; const Vec2f &v2 = _layout_vertices[cycle.getVertex(i)].pos; _layout_vertices[cycle.getVertex(i + 1)].pos.rotateAroundSegmentEnd(v1, v2, phi); } }
// Split border in two parts by two vertices void MoleculeLayoutGraph::_splitBorder (int v1, int v2, Array<int> &part1v, Array<int> &part1e, Array<int> &part2v, Array<int> &part2e) const { Cycle border; _getBorder(border); int idx1 = border.findVertex(v1); int idx2 = border.findVertex(v2); int i; if (idx1 == -1 || idx2 == -1) throw Error("border division by non-boundary vertex"); if (idx1 > idx2) __swap(idx1, idx2, i); part1v.clear(); part1e.clear(); part2v.clear(); part2e.clear(); for (i = idx1; i < idx2 + 1; i++) { part1v.push(border.getVertex(i)); part1e.push(border.getEdge(i)); } part1e.pop(); // edge count is less for (i = idx2; i < border.vertexCount(); i++) { part2v.push(border.getVertex(i)); part2e.push(border.getEdge(i)); } for (i = 0; i < idx1 + 1; i++) { part2v.push(border.getVertex(i)); part2e.push(border.getEdge(i)); } part2e.pop(); // edge count is less }