Rectilinear Planarity of Partial 2-Trees

A graph is rectilinear planar if it admits a planar orthogonal drawing without bends. While testing rectilinear planarity is NP-hard in general (Garg and Tamassia, 2001), it is a long-standing open problem to establish a tight upper bound on its complexity for partial 2-trees, i.e., graphs whose biconnected components are series-parallel. We describe a new O(n^2)-time algorithm to test rectilinear planarity of partial 2-trees, which improves over the current best bound of O(n^3 \log n) (Di Giacomo et al., 2022). Moreover, for partial 2-trees where no two parallel-components in a biconnected component share a pole, we are able to achieve optimal O(n)-time complexity. Our algorithms are based on an extensive study and a deeper understanding of the notion of orthogonal spirality, introduced several years ago (Di Battista et al, 1998) to describe how much an orthogonal drawing of a subgraph is rolled-up in an orthogonal drawing of the graph.


Introduction
In an orthogonal drawing of a graph each vertex is a distinct point of the plane and each edge is a chain of horizontal and vertical segments. Rectilinear planarity testing asks whether a planar 4-graph (i.e., with vertex-degree at most four) admits a planar orthogonal drawing without edge bends. It is a classical subject of study in graph drawing, partly for its theoretical beauty and partly because it is at the heart of the algorithms that compute bend-minimum orthogonal drawings, which find applications in several domains (see, e.g., [5,8,13,20,21,22]). Rectilinear planarity testing is NP-hard [16], it belongs to the XP-class when parameterized by treewidth [7], and it is FPT when parameterized by the number of degree-4 vertices [11]. Polynomial-time solutions exist for restricted versions of the problem. Namely, if the algorithm must preserve a given planar embedding, rectilinear planarity testing can be solved in subquadratic time for general graphs [2,15], and in linear time for planar 3-graphs [24] and for biconnected series-parallel graphs (SP-graphs for short) [9]. When the planar embedding is not fixed, linear-time solutions exist for (families of) planar 3-graphs [12,18,23,26] and for outerplanar graphs [14]. A polynomial-time solution for SP-graphs has been known for a long time [6], but establishing a tight complexity bound for rectilinear planarity testing of SP-graphs remains a long-standing open problem.
In this paper we provide significant advances on this problem. Our main contribution is twofold: -We present an O(n 2 log 2 n)-time algorithm to test rectilinear planarity of partial 2-trees, i.e., graphs whose biconnected components are SP-graphs. This result improves the current best known bound of O(n 3 log n) [7]. -We give an O(n)-time algorithm for those SP-graphs where no two parallelcomponents share a pole. We also show a logarithmic lower bound on the spirality that an orthogonal component of a graph in this family can take.
Our algorithms are based on an extensive study and a deeper understanding of the notion of orthogonal spirality, introduced in 1998 to describe how much an orthogonal drawing of a subgraph is rolled-up in an orthogonal drawing of the graph [6]. In the concluding remarks we also mention some of the pitfalls behind an O(n)-time algorithm for partial 2-trees.

Preliminaries
A planar orthogonal drawing can be computed in linear time from a so-called planar orthogonal representation, which describes the sequences of bends along the edges and the angles at the vertices [25]. Hence, rectilinear planarity testing is equivalent to asking whether a graph has a planar rectilinear representation, i.e., a planar orthogonal representation without bends. We study graphs that are not simple cycles, as otherwise rectilinear planarity testing is trivial. We just use the term "rectilinear representation" in place of "planar rectilinear representation".
A biconnected graph G is a series-parallel graph (or SP-graph) when none of its triconnected components is a triconnected graph. A partial 2-tree is a graph whose biconnected components are SP-graphs. If G is an SP-graph, the SPQtree T of G describes the decomposition of G into its triconnected components. It can be computed in linear time [5,17,19] and consists of three types of nodes: S-, P-, and Q-nodes. The degree-1 nodes of T are Q-nodes, each corresponding to a distinct edge of G. If ν is an S-node (resp. a P-node) it represents a series-component (resp. a parallel-component), denoted as skel(ν) and called the skeleton of ν. If ν is an S-node, skel(ν) is a simple cycle of length at least three; if ν is a P-node, skel(ν) is a bundle of at least three multiple edges. Any two S-nodes (resp. P-nodes) are never adjacent in T . A real edge (resp. virtual edge) in skel(ν) corresponds to a Q-node (resp. an S-or a P-node) adjacent to ν in T .
We use a variant of SPQ-tree called SPQ * -tree (refer to Fig. 1). In an SPQ *tree, each degree-1 node of T is a Q * -node, and represents a maximal chain of edges of G starting and ending at vertices of degree larger than two and passing P [17,18,20] [17,19,20] [0,17] [20,25,26] [0, 21,22,23,24,26]   through a sequence of degree-2 vertices only. If ν is an S-or a P-node, an edge of skel(ν) corresponding to a Q * -node µ is virtual if µ is a chain of at least two edges, else it is a real edge. For any given Q * -node ρ of T , denote by T ρ the tree T rooted at ρ. The chain of edges represented by ρ is the reference chain of G w.r.t. T ρ . If ν is an S-or a P-node distinct from the root child of T ρ , then skel(ν) contains a virtual edge that has a counterpart in the skeleton of its parent; this edge is the reference edge of skel(ν). If ν is the root child, the reference edge of skel(ν) is the edge corresponding to ρ. For any S-or P-node ν of T ρ , the end-vertices of the reference edge of skel(ν) are the poles of ν and of skel(ν). Note that skel(ν) does not change if we change ρ. For any S-or P-node ν of T ρ , the pertinent graph G ν,ρ of ν is the subgraph of G formed by the union of the chains represented by the leaves in the subtree of T ρ rooted at ν. The poles of G ν,ρ are the poles of ν. The pertinent graph of a Q * -node ν (including the root) is the chain represented by ν, and its poles are the poles of ν. Any graph G ν,ρ is also called a component of G (w.r.t. ρ). If µ is a child of ν, G µ,ρ a child component of ν. If H is a rectilinear representation of G, for any node ν of T ρ , the restriction H ν,ρ of H to G ν,ρ is a component of H (w.r.t. ρ). We use T ρ to describe all planar embeddings of G with the reference chain on the external face; they are obtained by permuting the edges of the skeletons of the P-nodes distinct from the reference edges. For each P-node ν, each permutation of the edges in skel(ν) gives a different left-to-right order of the children of ν in T ρ .

Rectilinear Planarity Testing of Partial 2-Trees
Let G be a partial 2-tree. We describe a rectilinear planarity testing algorithm that visits the block-cutvertex tree (BC-tree) of G and the SPQ * -tree of each block of G, for all possible roots of these trees (the definition of BC-tree is recalled in the appendix). We revisit the notion of "spirality values" for the blocks of G and present new ideas to efficiently compute these values (Section 3.1). The algorithm exploits a combination of dynamic programming techniques (Section 3.2).

Spirality of SP-graphs
Let G be a degree-4 SP-graph and H be a rectilinear representation of G. Let T ρ be a rooted SPQ * -tree of G, H ν,ρ be a component in H, and {u, v} be the poles of ν, ordered according to some st-numbering of G, where s and t are the poles of ρ. For each pole w ∈ {u, v}, let indeg ν (w) and outdeg ν (w) be the degree of w inside and outside H ν,ρ , respectively. Define two (possibly coincident) alias vertices of w, denoted by w and w , as follows: (i) if indeg ν (w) = 1, then w = w = w; (ii) if indeg ν (w) = outdeg ν (w) = 2, then w and w are dummy vertices, each splitting one of the two distinct edges incident to w outside H ν,ρ ; (iii) if indeg ν (w) > 1 and outdeg ν (w) = 1, then w = w is a dummy vertex that splits the edge incident to w outside H ν,ρ . Let A w be the set of distinct alias vertices of a pole w. Let P uv be any simple path from u to v inside H ν,ρ and let u and v be the alias vertices of u and of v, respectively. The path S u v obtained concatenating (u , u), P uv , and (v, v ) is called a spine of H ν,ρ . Denote by n(S u v ) the number of right turns minus the number of left turns encountered along S u v while moving from u to v . The spirality σ(H ν,ρ ) of H ν,ρ , introduced in [6], is either an integer or a semi-integer number, defined as follows (see Fig. 2): It has been proved that the spirality of H ν,ρ does not depend on the choice of P uv [6]. Also, a component H ν,ρ of H can always be substituted by any other representation H ν,ρ of the pertinent graph G ν,ρ with the same spirality, getting a new valid orthogonal representation with the same set of bends on the edges of H that are not in H ν,ρ (see [6] and also Theorem 1 in [10]). For brevity, we shall denote by σ ν the spirality of a rectilinear representation of G ν,ρ . Lemmas 1 to 3 relate, for any S-or P-node ν, the spirality values for a rectilinear representation of G ν,ρ to those of the rectilinear representations of the child components of G ν,ρ [6]. See Fig. 3.
Let ν be a P-node of T ρ with two children, H be a rectilinear representation of G with the reference chain on the external face. By orienting upward the edges of H according to the st-numbering, we can naturally talk about leftmost and rightmost incoming (outgoing) edges of every vertex. For a pole w ∈ {u, v} of ν, the angle formed by the two leftmost (rightmost) edges incident to w (one incoming and one outgoing) is the leftmost angle (rightmost angle) at w in H ν,ρ . Let α l w and α r w be variables defined as: α l w = 0 (α r w = 0) if the leftmost (rightmost) angle at w in H is 180 • , while α l w = 1 (α r w = 1) if this angle is 90 • . Also let k l w and k r w be variables defined as: Let ν be a P-node of T ρ with two children µ l and µ r , and poles u and v. G ν,ρ has a rectilinear representation with spirality σ ν , where G µ l ,ρ and G µr,ρ are in this left-to-right order, if and only if there exist values σ µ l , σ µr , α l u , α r u , α l v , α r v such that: (i) G µ l ,ρ and G µr,ρ have rectilinear representations with spirality σ µ l and σ µr , respectively; Spirality sets. Let G be an SP-graph with n vertices, T ρ be a rooted SPQ * -tree of G, and ν be a node of T ρ . We say that G ν,ρ , or directly ν, admits spirality σ ν σ µ2 = 1 in T ρ if there exists a rectilinear representation H ν,ρ with spirality σ ν in some rectilinear representation H of G. The rectilinear spirality set Σ ν,ρ of ν in T ρ (and of G ν,ρ ) is the set of spirality values for which G ν,ρ admits a rectilinear representation. Σ ν,ρ is representative of all "shapes" that G ν,ρ can take in a rectilinear representation of G with the reference chain on the external face. If G ν,ρ is not rectilinear planar, Σ ν,ρ is empty. If N ν is the number of vertices of G ν,ρ , we have |Σ ν,ρ | = O(N ν ) = O(n), as the spirality of any rectilinear representation of G ν,ρ cannot exceed the length of the longest spine in this component. A keyingredient for our testing algorithm is how to efficiently compute the spirality sets of each node in a bottom-up visit of the SPQ * -tree of G for each possible choice of its root. We give a core lemma regarding S-nodes.
Lemma 4. Let G be an SP-graph, T be the SPQ * -tree of G, and ν be an S-node of T with n ν children. Let ρ 1 , ρ 2 , . . . , ρ h be a sequence of Q * -nodes of T such that, for each child µ of ν in T ρi , the set Σ µ,ρi is given. The set Σ ν,ρi can be computed in O(n ν n log 2 n) time for i = 1 and in O(n log n) time for 2 ≤ i ≤ h.
Sketch of proof: Let A and B be two sets of numbers. The Cartesian sum A + B is the set {a + b|a ∈ A, b ∈ B}. If A and B are sets of O(n) numbers of O(n) size, A + B can be computed in O(n log n) time (see, e.g., [1]). Even for the cases of negative integers or semi-integers, simple modifications allow us to apply this technique. We extensively apply Cartesian sums between the spirality sets of the children of ν. Indeed, based on Lemma 1, the series composition of two components admits a set of spirality values that is the Cartesian sum of the ν,ρ 1 = Σ1,2 + Σµ 4 ,ρ 1 + Σ5, 6,7,8. sets of the combined components. Since the spirality sets resulting from this composition still contain O(n) distinct values of size O(n) and each spirality value is either an integer or a semi-integer, we compute each Cartesian sum between two of these sets in O(n log n) time. Let µ 1 , . . . , µ s be the children of ν in T ρ1 , with s = n ν .
Case i = 1. When we process ν in T ρ1 we construct the following sets: The spirality set Σ ν,ρ1 of ν and, for each 1 ≤ j ≤ s, a set ∆ ν,ρ1 corresponding to the Cartesian sum of the spirality sets of all children of ν except µ j . Set ∆ (−j) ν,ρ1 will be used to efficiently compute the spirality set of ν when µ j becomes the parent of ν in some tree T ρi i > 1. To compute Σ ν,ρ1 and ∆ (−j) ν,ρ1 we apply this procedure: Step 1. Let d be the minimum integer such that s + d = 2 k , for an integer k > 0. Note that d < s. If d > 0, temporarily add d dummy children µ s+1 , . . . , µ s+d to ν, with spirality sets Σ µs+1,ρ1 = · · · = Σ µ s+d ,ρ1 = {0}.
Step 3. For each j = 1, . . . , s, compute ∆ (−j) ν,ρ1 as follows (see Fig. 4(b)). Let π be the path in τ from the root to the leaf corresponding to µ j , and let ψ be the node along π at level of τ (ψ 0 being the root). For each non-leaf node ψ , let φ +1 be the sibling of ψ +1 in τ . ∆ ν,ρ1 is computed as the Cartesian sum of all sets stored at the nodes φ +1 , for each non-leaf node ψ . Case i > 1. Let µ be the parent of ν in T ρ1 . If µ is also the parent of ν in T ρi , we do not recompute Σ ν,ρi , as Σ ν,ρi = Σ ν,ρ1 . Else, µ is a child of ν in T ρi , and one of the children of ν in T ν,ρ1 , say µ j , is the parent of ν in T ρi . To compute Σ ν,ρi we execute, in O(n log n) time, the Cartesian sum between ∆ (−j) ν,ρ1 and Σ µ,ρi .

Testing Algorithm
Lemma 5. Let G be an n-vertex SP-graph. There exists an O(n 2 log 2 n)-time algorithm that tests whether G is rectilinear planar and that computes a rectilinear representation of G in the positive case.
Sketch of proof: We sketch here the testing phase, which elaborates on ideas in [6] and exploits Lemma 4. Let T be the SPQ * -tree of G and let {ρ 1 , . . . , ρ h } be a sequence of its Q * -nodes. Denote by i the length of the chain corresponding to ρ i ; the spirality set of ρ i consists of all integer values in the interval [−( i −1), ( i − 1)]. For each i = 1, . . . , h, the testing algorithm performs a post-order visit of T ρi . For every visited non-root node ν of T ρi the algorithm computes the set Σ ν,ρi by combining the spirality sets of the children of ν, based on Lemmas 1-3. If Σ ν,ρi = ∅, the algorithm stops the visit, discards T ρi , and starts visiting T ρi+1 (if i < h). If the algorithm achieves the root child ν and if Σ ν,ρi = ∅, it checks whether G is rectilinear planar by verifying if there exists a value σ ν ∈ Σ ν,ρi and a value σ ρi ∈ Σ ρi,ρi = [−( i − 1), ( i − 1)] such that σ ν − σ ρi = 4 (we show in the appendix that this condition is necessary and sufficient). If so, the test is positive and the algorithm does not visit the remaining trees.
We now explain how to perform the testing algorithm in O(n 2 log 2 n) time. Tree T is computed in O(n) time [5,17,19]. Let T ρi be the currently visited tree, and let ν be a node of T ρi . Denote by n ν the number of children of ν. If the parent of ν in T ρi coincides with the parent of T ρj for some j ∈ {1, . . . , i−1}, and if Σ ν,ρj was previously computed, then the algorithm does not need to compute Σ ν,ρi , because Σ ν,ρi = Σ ν,ρj . Hence, for each node ν, the number of computations of its rectilinear spirality sets that are performed over all possible trees T ρi is at most n ν + 1 = O(n ν ) (one for each different way of choosing the parent of ν).
If ν is a Q * -node, Σ ν,ρi is easily computed in O(1) time. If ν is a P-node with three children, it is sufficient to check, for each of the six permutations of the children of ν and for each value in the rectilinear spirality set of one of the three children, whether the sets of the other two children contain the values that satisfy condition (ii) of Lemma 2. Hence, Σ ν,ρi can be computed in O(n) time. If ν is a P-node with two children, Σ ν,ρi is computed in O(n) with a similar approach, using Lemma 3. Since ν deg(ν) = O(n), the computation of the rectilinear spirality sets of all P-nodes takes O(n 2 ) time, over all T ρi (i = 1, . . . , h).
Suppose now that ν is an S-node. By Lemma 4, in the first rooted tree for which we are able to compute the rectilinear spirality set of ν (i.e., in the first rooted tree for which all children of ν admit a rectilinear representation), we spend O(n ν n log 2 n) time to compute such a set. For each of the other O(n ν ) trees in which the parent of ν changes, we spend O(n log n) time to recompute the rectilinear spirality set of ν. Thus, for each S-node ν we spend in total O(n ν n log 2 n) time over all visits of T ρi (i = 1, . . . , h), and hence, since ν deg(ν) = O(n), we spend O(n 2 log 2 n) time over all S-nodes of the tree. Theorem 1. Let G be an n-vertex partial 2-tree. There exists an O(n 2 log 2 n) time algorithm that tests whether G is rectilinear planar and that computes a rectilinear representation of G in the positive case.
Sketch of proof: Let T be the BC-tree of G, and let B 1 , . . . , B q be the blocks of G (q ≥ 2). We denote by β(B i ) the block-node of T corresponding to B i (1 ≤ i ≤ q) and by T Bi the tree T rooted at β(B i ). For a cutvertex c of G, we denote by χ(c) the node of T that corresponds to c. Each T Bi describes a class of planar embeddings of G such that, for each non-root node β(B j ) (1 ≤ j ≤ q) with parent node χ(c), the cutvertex c lies in the external face of B j . We say that G is rectilinear planar with respect to T Bi if it is rectilinear planar for some planar embedding in the class described by T Bi . To check whether G is rectilinear planar with respect to T Bi , we have to perform a constrained rectilinear planarity testing for every block B 1 , . . . , B q so to guarantee that the rectilinear representations of the different blocks can be merged together at the shared cutvertices. The different types of constraints for a cutvertex c of B j are defined based on the degree of c in G and in B j , as well as on the number of blocks sharing c with B j . The testing for B j must consider the planar embeddings in which none of the cutvertices is forced to be on the external face (when β(B j ) is the root of the BC-tree) and those in which a prescribed cutvertex (the one corresponding to the parent of β(B j )) must be on the external face. By adapting the technique in Lemma 5, a constrained rectilinear planarity testing for B j can still be executed in O(n 2 Bj log 2 n Bj ) over all these planar embeddings, where n Bj is the number of vertices of B j (see the appendix for details). For a block B j , the choice of which cutvertex-node is the parent (if any) of β(B j ) and of which cutvertex-nodes are the children of β(B j ) is a configuration of B j . Note that, each rooted BC-tree defines a configuration for each block.
In a pre-processing phase, we perform the constrained rectilinear planarity testing for each block of the BC-tree and for each configuration of this block. Also, for each configuration of the cutvertex-nodes incident to β(B j ), we store at β(B j ) a Boolean local label that is either true if B j is rectilinear planar for that configuration or false otherwise. Since each block B j is processed in O(n 2 Bj log 2 n Bj ), the pre-processing phase is executed in O(n 2 log 2 n) time. After the pre-processing phase, we first visit T B1 bottom-up. For each node of T B1 (either a block-node or a cutvertex-node) we compute a Boolean cumulative label that is the conjunction of those of its children; the cumulative label of a leaf coincides with its local label. This is easily done in O(n) time for all nodes of T B1 . After the visit of T B1 one of the following three cases holds: (i) The cumulative label of the root is true. In this case the test is positive. (ii) There are two blocknodes γ 1 and γ 2 in T B1 with cumulative label false and they are along two distinct paths from a leaf to the root. In this case the test is negative, as for any other T Bi (i = 2, . . . , q), at least one of the subtrees rooted at γ 1 and γ 2 remains unchanged. (iii) Let β(B j ) be the deepest node along the unique path that contains of block-nodes with cumulative label false. It is sufficient to test all rooted BC-trees whose root β(B i ) is a leaf of the subtree rooted at β(B j ). For each of these trees we repeat the procedure above and compute the cumulative label of a node γ of T Bi only if the subtree of γ has changed with respect to any previous visits. For a node γ whose parent has changed, its cumulative label is computed in O(1) time (γ has at most one child whose cumulative label is false).
Therefore: For each node γ of T of degree n γ , the cumulative label of γ is computed in O(n γ ) time for T B1 and in O(1) for T Bi (i > 1). Since each node γ changes its parent O(n γ ) times, summing up over all γ, the testing phase that follows the pre-processing phase takes in total O(n) time.
Indeed, the absence of regularity is an obstacle to the design of a succinct description based on whether a component is rectilinear planar for consecutive spirality values. By carefully analyzing the spirality properties of independent-parallel SPgraphs, in Sections 4.2 and 4.3 we show how to overcome these difficulties and design a linear-time rectilinear planarity testing algorithm for this graph family.

Spirality Lower Bound
Theorem 2. For infinitely many integer values of n, there exists an n-vertex independent-parallel SP-graph for which every rectilinear representation has a component with spirality Ω(log n).

Sketch of proof:
We describe an infinite family of graphs, schematically illustrated in Fig. 6, that have components whose spirality is not bounded by a constant in any rectilinear representation. For any even integer N ≥ 2, we construct an independent-parallel SP-graph G with n = O(3 N ) vertices whose rectilinear representations require a component with spirality larger than N . Namely, let L = N 2 + 1. For k ∈ {0, . . . , L}, let G k be the SP-graph inductively defined as follows: (i) G 0 is a chain of N + 4 vertices; (ii) G 1 is a parallel composition of three copies of G 0 , with coincident poles ( Fig. 6(a)); (iii) for k ≥ 2, G k is a parallel composition of three series composition, each starting and ending with an edge, and having G k−1 in the middle ( Fig. 6(b)). Graph G is obtained by composing in a cycle two chains p 1 and p 2 of length three, with two copies of G L (Fig. 6(c)). The graph G L for N = 4 is in Fig. 7(d). In any representation of G, at least one of the G 0 components has spirality larger than N . See Fig. 7(e), where N = 4.
The main result of this subsection is Theorem 3, which proves that if G is an independent-parallel SP-graph, there is a limited number of possible structures for the sets Σ + ν,ρ (see also  Theorem 3. Let G be a rectilinear planar independent-parallel SP-graph and let G ν,ρ be a component of G. The non-negative rectilinear spirality set Σ + ν,ρ of G ν,ρ has one the following six structures:

Rectilinear Planarity Testing
Let G be an independent-parallel SP-graph, T be its SPQ * -tree, and {ρ 1 , . . . , ρ h } be the Q * -nodes of T . To test whether G is rectilinear planar, we exploit a similar strategy as in Lemma 5. For each possible choice of the root ρ ∈ {ρ 1 , . . . , ρ h }, the algorithm visits T ρ bottom-up and computes, for each visited node ν, the non-negative spirality set Σ + ν,ρ , based on the sets of the children of ν. Using Theorem 3, we prove that this computation can be done in O(1) time for each type of node, including the S-nodes which require the most expensive operations for general SP-graphs. At the level of the root, when ν is the root child, we prove that it is sufficient to test whether there exist two values σ ν ∈ Σ + ν,ρ and σ ρ ∈ Σ + ρ,ρ , such that σ ν + σ ρ = 4 (see the appendix for details). Thus we spend O(1) time also at the root level. An O(n)-time testing algorithm over all choices of the root ρ is achieved through the same reusability principle described in Lemma 5, where again we can prove that updating the spirality set of each type of node can be done in O(1) by Theorem 3. Theorem 4. Let G be an n-vertex independent-parallel SP-graph. There exists an O(n)-time algorithm that tests whether G is rectilinear planar and that computes a rectilinear representation of G in the positive case.

Final Remarks and Open Problems
We proved that rectilinear planarity can be tested in O(n 2 log 2 n) time for general partial 2-trees and in O(n) time for independent-parallel SP-graphs. Establishing a tight bound on the complexity of rectilinear planarity testing algorithm for partial 2-trees remains an open problem. A pitfall to achieve O(n)-time complexity in the general case is that, in contrast with the independent-parallel SP-graphs, the spirality set of a component may not exhibit a regular behavior. Even extending Theorem 4 to non-biconnected partial 2-trees whose blocks are independent-parallel is not immediate, as the constraints for the angles at the cutvertices affect the regularity of the spirality sets. Fig. 8. Component that admits spiralities 0,1,3,4,5. Spirality 2 needs a bend (×).

Introduction
In an orthogonal drawing of a graph each vertex is a distinct point of the plane and each edge is a chain of horizontal and vertical segments. Rectilinear planarity testing asks whether a planar 4-graph (i.e., with vertex-degree at most four) admits a planar orthogonal drawing without edge bends. It is a classical subject of study in graph drawing, partly for its theoretical beauty and partly because it is at the heart of the algorithms that compute bend-minimum orthogonal drawings, which find applications in several domains (see, e.g., [5,8,13,20,21,22]). Rectilinear planarity testing is NP-hard [16], it belongs to the XP-class when parameterized by treewidth [7], and it is FPT when parameterized by the number of degree-4 vertices [11]. Polynomial-time solutions exist for restricted versions of the problem. Namely, if the algorithm must preserve a given planar embedding, rectilinear planarity testing can be solved in subquadratic time for general graphs [2,15], and in linear time for planar 3-graphs [24] and for biconnected series-parallel graphs (SP-graphs for short) [9]. When the planar embedding is not fixed, linear-time solutions exist for (families of) planar 3-graphs [12,18,23,26] and for outerplanar graphs [14]. A polynomial-time solution for SP-graphs has been known for a long time [6], but establishing a tight complexity bound for rectilinear planarity testing of SP-graphs remains a long-standing open problem.
In this paper we provide significant advances on this problem. Our main contribution is twofold: -We present an O(n 2 log 2 n)-time algorithm to test rectilinear planarity of partial 2-trees, i.e., graphs whose biconnected components are SP-graphs. This result improves the current best known bound of O(n 3 log n) [7]. -We give an O(n)-time algorithm for those SP-graphs where no two parallelcomponents share a pole. We also show a logarithmic lower bound on the spirality that an orthogonal component of a graph in this family can take.
Our algorithms are based on an extensive study and a deeper understanding of the notion of orthogonal spirality, introduced in 1998 to describe how much an orthogonal drawing of a subgraph is rolled-up in an orthogonal drawing of the graph [6]. In the concluding remarks we also mention some of the pitfalls behind an O(n)-time algorithm for partial 2-trees.

Preliminaries
A planar orthogonal drawing Γ of a planar graph is a crossing-free drawing that maps each vertex to a distinct point of the plane and each edge to a sequence of horizontal and vertical segments between its end-points [5,13,22]. A graph is rectilinear planar if it admits a planar orthogonal drawing without bends. A planar orthogonal representation H describes the shape of a class of orthogonal drawings in terms of sequences of bends along the edges and angles at the vertices. A drawing Γ of H can be computed in linear time [25]. If H has no bend, it is a planar rectilinear representation. Since we only deal with planar drawings, we just use the term "rectilinear representation" in place of "planar rectilinear representation".
SP-graphs and SPQ * -trees. Let G be a biconnected graph. The SPQR-tree T of G describes the decomposition of G into its triconnected components, and can be computed in linear time [5,17,19]. If every triconnected component of G is not a triconnected graph, G is a series-parallel graph, or SP-graph for short. In this case T is simply called SPQ-tree and contains three types of nodes: S-, P-, and Q-nodes. The degree-1 nodes of T are Q-nodes, each corresponding to a distinct edge of G. If ν is an S-node (resp. a P-node) it represents a series-component (resp. a parallel-component), denoted as skel(ν) and called the skeleton of ν. If ν is an S-node, skel(ν) is a simple cycle of length at least three; if ν is a P-node, skel(ν) is a bundle of at least three multiple edges. Any two S-nodes (resp. P-nodes) are never adjacent in T . A real edge (resp. virtual edge) in skel(ν) corresponds to a Q-node (resp. an S-or a P-node) adjacent to ν in T .
Testing whether a simple cycle is rectilinear planar is trivial (if and only if it has at least four vertices). Hence, we shall assume that G is a biconnected SP-graph different from a simple cycle and we use a variant of the SPQ-tree called SPQ * -tree (refer to Fig. 1). In an SPQ * -tree, each degree-1 node of T is a Q * -node, and represents a maximal chain of edges of G (possibly a single edge) starting and ending at vertices of degree larger than two and passing through a sequence of degree-2 vertices only (possibly none). If ν is an S-or a P-node, an edge of skel(ν) corresponding to a Q * -node µ is virtual if µ is a chain of at least two edges, else it is a real edge.
For any given Q * -node ρ of T , denote by T ρ the tree T rooted at ρ. The chain of edges represented by ρ is the reference chain of G with respect to T ρ . If ν is an S-or a P-node distinct from the root child of T ρ , then skel(ν) contains a virtual edge that has a counterpart in the skeleton of its parent; this edge is the reference edge of skel(ν). If ν is the root child, the reference edge of skel(ν) is the edge corresponding to ρ. For any S-or P-node ν of T ρ , the end-vertices of the reference edge of skel(ν) are the poles of ν and of skel(ν). We remark that skel(ν) does not change if we change ρ. However, if ν is an S-node, its poles depend on ρ; namely, if ρ is a Q * -node in the subtree of T ρ rooted at ν, the poles of ν in T ρ are different from those in T ρ . Conversely, the poles of a P-node stay the same independent of the root of T . For a Q * -node ν of T ρ (including ρ), the poles of ν are the end-vertices of the corresponding chain, and do not change when the root of T changes. For any S-or P-node ν of T ρ , the pertinent graph G ν,ρ of ν is the subgraph of G formed by the union of the chains represented by the leaves in the subtree of T ρ rooted at ν. The poles of G ν,ρ are the poles of ν. The pertinent graph of a Q * -node ν (including the root) is the chain represented by ν, and its poles are the poles of ν. Any graph G ν,ρ is also called a component of G (with respect to ρ). If µ is a child of ν, we call G µ,ρ a child component of ν. If H is a rectilinear representation of G, for any     node ν of T ρ , the restriction H ν,ρ of H to G ν,ρ is a component of H (with respect to ρ). Tree T ρ is used to describe all planar embeddings of G having the reference chain on the external face. These embeddings are obtained by permuting in all possible ways the edges of the skeletons of the P-nodes distinct from the reference edges, around the poles. For each P-node ν, each permutation of the edges in skel(ν) corresponds to a different left-to-right order of the children of ν in T ρ and of their associated components. Namely, assume given an st-numbering of G such that s and t coincide with the poles of ρ. For each P-node ν of T ρ , let u and v be its poles where u precedes v in the st-numbering. Denote by e ν the reference edge of skel(ν), by e 1 , . . . , e h the edges of skel(ν) distinct from e ν , and by µ 1 , . . . , µ h the children of ν corresponding to e 1 , . . . , e h . Each permutation of e 1 , . . . , e h defines a class of planar embeddings of G ν,ρ with u and v on the external face, where the components G µ1,ρ , . . . , G µ h ,ρ are incident to u and v in the order of the permutation. More precisely, if e i1 , . . . , e i h is one of these permutations (i j ∈ {1, . . . , h}), the clockwise (resp. counterclockwise) sequence of edges incident to u (resp. v) in skel(ν) is e ν , e i1 , . . . , e i h ; we say that, according to this permutation, µ i1 , . . . , µ i h and their corresponding components appear in this left-to-right order. Partial 2-trees and BC-trees. A 1-connected graph G is a partial 2-tree if every biconnected component of G is an SP-graph. A biconnected component of G is also called a block. A block is trivial if it consists of a single edge. The blockcutvertex tree T of G, also called BC-tree of G, describes the decomposition of G in terms of its blocks (see, e.g., [3]). Each node of T either represents a block of G or it represents a cutvertex of G. A block-node (resp. a cutvertex-node) of T is a node that represents a block (resp. a cutvertex) of G. There is an edge between two nodes of T if and only if one node represents a cutvertex of G and the other node represents a block that contains the cutvertex. A block is trivial if it consists of a single edge.

Rectilinear Planarity Testing of Partial 2-Trees
Let G be a partial 2-tree. We describe a rectilinear planarity testing algorithm that visits the block-cutvertex tree (BC-tree) of G and the SPQ * -tree of each block of G, for each possible choice of the roots of both decomposition trees. Our algorithm revisits the notion of "spirality values" for the blocks of G, and introduces new concepts to efficiently compute these values (Section 3.1). It is based on a combination of dynamic programming techniques (Section 3.2).

Spirality of SP-graphs
Let G be a degree-4 SP-graph and let H be a rectilinear representation of G. Let T ρ be a rooted SPQ * -tree of G, let H ν,ρ be a component of H (i.e., the restriction of H to G ν,ρ ), and let {u, v} be the poles of ν, conventionally ordered according to an st-numbering of G, where s and t are the poles of ρ. For each pole w ∈ {u, v}, let indeg ν (w) and outdeg ν (w) be the degree of w inside and outside H ν,ρ , respectively. Define two (possibly coincident) alias vertices of w, denoted by w and w , as follows: (i) if indeg ν (w) = 1, then w = w = w; (ii) if indeg ν (w) = outdeg ν (w) = 2, then w and w are dummy vertices, each splitting one of the two distinct edge segments incident to w outside H ν,ρ ; (iii) if indeg ν (w) > 1 and outdeg ν (w) = 1, then w = w is a dummy vertex that splits the edge segment incident to w outside H ν,ρ . Let A w be the set of distinct alias vertices of a pole w. Let P uv be any simple path from u to v inside H ν,ρ and let u and v be the alias vertices of u and of v, respectively. The path S u v obtained concatenating (u , u), P uv , and (v, v ) is called a spine of H ν,ρ . Denote by n(S u v ) the number of right turns minus the number of left turns encountered along S u v while moving from u to v . The spirality σ(H ν,ρ ) of H ν,ρ , introduced in [6], is either an integer or a semi-integer number, defined based on the following cases (see Fig. 2 for an example): 2. An orthogonal representation H and three of its components with respect to the reference chain with poles s and t. For each component, its alias vertices (white squares) and its spirality are reported.
It is proved that the spirality of H ν,ρ does not depend on the choice of P uv [6]. Also, a component H ν,ρ of H can always be substituted by any other component H ν,ρ with the same spirality, getting a new valid orthogonal representation with the same set of bends on the edges of H that are not in H ν,ρ (see [6] and also Theorem 1 in [10]). For brevity, we shall denote by σ ν the spirality of a rectilinear representation of G ν,ρ . Lemmas 1 to 3 relate, for any S-or P-node ν, the values of spirality for a rectilinear representation of G ν,ρ to the values of spirality of the rectilinear representations of the child components of G ν,ρ (i.e., the components corresponding to the children of ν) [6]. See Fig. 3 for a schematic illustration.
For a P-node ν of T ρ with two children we need some more notation. Let H be an orthogonal representation of G with ρ on the external face and let H ν,ρ be the restriction of H to G ν,ρ . For each pole w ∈ {u, v} of ν, the leftmost angle (resp. rightmost angle) at w in H ν,ρ is the angle formed by the leftmost (resp. rightmost) external edge and the leftmost (resp. rightmost) internal edge of H ν,ρ incident to w. Define two binary variables α l w and α r w as follows: α l w = 0 (α r w = 0) if the leftmost (rightmost) angle at w in H is 180 • , while α l w = 1 (α r w = 1) if this angle is 90 • . Also define two variables k l w and k r w as follows: Lemma 3.
[6] Let ν be a P-node of T ρ with two children µ l and µ r , and poles u and v. G ν,ρ has a rectilinear representation with spirality σ ν , where G µ l ,ρ and G µr,ρ are in this left-to-right order, if and only if there exist values σ µ l , σ µr , α l u , α r u , α l v , α r v such that: (i) G µ l ,ρ and G µr,ρ have rectilinear representations with spirality σ µ l and σ µr , respectively; (ii) α l w , α r w ∈ {0, 1}, 1 ≤ α l w + α r w ≤ 2 with w ∈ {u, v}; and (iii) Spirality sets. Let G be an SP-graph (distinct from a simple cycle) with n vertices, T ρ be a rooted SPQ * -tree of G, and ν be a node of T ρ . We say that G ν,ρ , or directly ν, admits spirality σ ν in T ρ if there exists a rectilinear representation H ν,ρ with spirality σ ν in some rectilinear representation H of G. The rectilinear spirality set Σ ν,ρ of ν in T ρ (and of G ν,ρ ) is the set of spirality values for which G ν,ρ admits a rectilinear representation. Σ ν,ρ is representative of all "shapes" that G ν,ρ can take in a rectilinear representation of G with the reference chain on the external face. If G ν,ρ is not rectilinear planar, Σ ν,ρ is empty. If N ν is the number of vertices of G ν,ρ , we have |Σ ν,ρ | = O(N ν ) = O(n), as the spirality of any rectilinear representation of G ν,ρ cannot exceed the length of the longest spine in this component. Our rectilinear planarity algorithm for G elaborates and refines ideas of [6]. It is based on a dynamic programming technique that visits the SPQ * -tree of G for each possible choice of the root; for each tree, either the root is reached and a rectilinear representation is found (in which case the test stops and returns the solution), or a node with empty rectilinear spirality set is encountered (in which case the visit is interrupted and the tree is discarded). With respect to [6], our algorithm exploits two new fundamental ingredients to significantly reduce the overall time complexity, namely: (a) a faster procedure to process the S-nodes of the SPQ * -tree; (b) a re-usability principle that makes it possible to process all rooted SPQ * -tree in the same asymptotic time needed to process a single SPQ * -tree. Ingredient (a) is based on the following key lemma.
Lemma 4. Let G be an SP-graph, T be the SPQ * -tree of G, and ν be an S-node of T with n ν children. Let ρ 1 , ρ 2 , . . . , ρ h be a sequence of Q * -nodes of T such that, for each child µ of ν in T ρi , the set Σ µ,ρi is given. The set Σ ν,ρi can be computed in O(n ν n log 2 n) time for i = 1 and in O(n log n) time for 2 ≤ i ≤ h.  [1]). If at least one of A and B contains some negative integers, we can still compute A + B in O(n) time as follows: We add to each element of A and B the minimum positive number p that makes all the elements in the two sets non-negative; we then compute the Cartesian sum of the modified sets, and finally we subtract the number 2p to each element, which gives the Cartesian sum A + B. Also, if A and B contain semi-integers, we can just multiply by a factor of 2 each element of the two sets, execute the Cartesian sum of the modified sets in O(n log n) time, and divide by 2 the resulting elements. In our approach, we extensively apply Cartesian sums between the spirality sets of the children of ν. Indeed, based on Lemma 1, the series composition of two components admits a set of spirality values that is the Cartesian sum of the sets of the combined components. Since the spirality sets resulting from such a composition still contains O(n) distinct values each of size O(n), and since each spirality value is either an integer or a semi-integer, we can perform each Cartesian sum between two of these sets in O(n log n) time. Let µ 1 , . . . , µ s be the children of ν in T ρ1 , where s = n ν .
Case i = 1. When we process ν in T ρ1 we compute the following sets: The spirality set Σ ν,ρ1 of ν and, for each 1 ≤ j ≤ s, a set ∆ will be used to efficiently compute the spirality set of ν when µ j becomes the parent of ν in some tree T ρi with i > 1. To compute Σ ν,ρ1 and ∆ (−j) ν,ρ1 we apply the following procedure.  Step 1. Let d be the minimum integer such that s + d = 2 k , for some integer k > 0. Note that d < s. If d > 0, temporarily add d dummy children µ s+1 , . . . , µ s+d to ν, with spirality sets Σ µs+1,ρ1 = · · · = Σ µ s+d ,ρ1 = {0}.
Step 2. Construct a data structure consisting of a complete rooted binary tree τ , such that (see Fig. 4(a)): (i) the leaves of τ correspond to µ 1 , . . . , µ s+d , in this left-to-right order; (ii) the leaf of τ corresponding to µ j is equipped with the set Σ µj ,ρi (1 ≤ j ≤ s + d); (iii) each internal node of τ is equipped with the Cartesian sum of the two sets stored at its two children. This means that each internal node ψ of τ is equipped with the Cartesian sum of all sets stored at the leaves of the subtree of τ rooted at ψ. We denote by Σ j1,j2,...,jg the set stored at ψ, where µ j1 , µ j2 , . . . , µ jg are the leaves of the subtree rooted at ψ (j a+1 = j a + 1, for 1 ≤ a ≤ g − 1). Thus the root of τ is equipped with the set Σ 1,...,s+d , which is the Cartesian sum Σ µ1,ρ1 + · · · + Σ µs,ρ1 = Σ ν,ρ1 (each set Σ µ s+b = {0}, with 1 ≤ b ≤ d, acts as a neutral element for the Cartesian sum operation).
Step 3. For each j = 1, . . . , s, compute ∆ (−j) ν,ρ1 as follows (see Fig. 4(b)). Let π be the path in τ from the root to the leaf corresponding to µ j , and let ψ be the node along π at level of τ (ψ 0 being the root). For each non-leaf node ψ , let φ +1 be the sibling of ψ +1 in τ . ∆ (−j) ν,ρ1 is computed as the Cartesian sum of all sets stored at the nodes φ +1 , for each non-leaf node ψ . In Fig. 4(b) we highlighted in yellow the nodes of τ involved in the computation of ∆ Case i > 1. Denote by µ the parent of ν in T ρ1 . If T ρi is such that the parent of ν is µ, then we do not need to compute Σ ν,ρi , because Σ ν,ρi = Σ ν,ρ1 . Otherwise, node µ is a child of ν in T ρi , and one of the children of ν in T ν,ρ1 , call it µ j , is the parent of ν in T ρi . To compute Σ ν,ρi , we execute the Cartesian sum between ∆ (−j) ν,ρ1 and Σ µ,ρi , which takes O(n log n).

Testing Algorithm
We first consider SP-graphs and then partial 2-trees that are not biconnected.
Lemma 5. Let G be an n-vertex SP-graph. There exists an O(n 2 log 2 n)-time algorithm that tests whether G is rectilinear planar and that computes a rectilinear representation of G in the positive case.
Proof. We first describe the testing algorithm and then show how to construct a rectilinear representation if the test is positive. Testing algorithm. Assume that G is not a simple cycle, otherwise the test is trivial. Let T be the SPQ * -tree of G and let {ρ 1 , . . . , ρ h } be a sequence of all Q * -nodes of T . Denote by i the length of the chain corresponding to ρ i ; the spirality set of ρ i consists of all integer values in the interval [−( i − 1), ( i − 1)]. Namely, the chain of ρ i takes value −( i − 1) (resp. ( i − 1)) when there is a left (resp. right) turn at each vertex of the chain. For each i = 1, . . . , h, the testing algorithm performs a post-order visit of T ρi . During this visit of T ρi , for every non-root node ν of T ρi the algorithm computes the set Σ ν,ρi by combining the spirality sets of the children of ν, according to the relations given in Lemmas 1-3. If Σ ν,ρi = ∅, the algorithm stops the visit, discards T ρi , and starts visiting T ρi+1 (if i < h). If the algorithm achieves the root child ν and if Σ ν,ρi = ∅, it checks whether G is rectilinear planar by verifying if there exists a value σ ν ∈ Σ ν,ρi and a value σ ρi ∈ Σ ρi,ρi = [−( i − 1), ( i − 1)] such that σ ν − σ ρi = 4. if so, the test is positive and the algorithm does not visit the remaining trees; otherwise it discards T ρi and starts visiting T ρi+1 (if i < h). Note that, denoted by s and t the poles of ν (which coincide with those of ρ i ), the final condition σ ν − σ ρi = 4 is necessary and sufficient for the existence of a rectilinear representation due to the following observations: (i) In any orthogonal representation of G, the difference k between the number of right and left turns encountered walking clockwise along the boundary of any simple cycle that passes through the reference chain is k = 4; (ii) since the alias vertices of the poles of ν are vertices that subdivide the two edges of the reference chain incident to s and t, the value k equals the spirality of σ ν plus the difference σ ρi between the number of right and left turns along the reference chain while moving from t to s; (iii) σ ρi = −σ ρi , where σ ρi ∈ [−( i − 1), ( i − 1)] is the spirality of the chain corresponding to ρ i .
We now explain how to perform the testing algorithm in O(n 2 log 2 n) time. Tree T is computed in O(n) time [5,17,19]. Let T ρi be the currently visited tree, and let ν be a node of T ρi . Denote by n ν the number of children of ν. If the parent of ν in T ρi coincides with the parent of T ρj for some j ∈ {1, . . . , i−1}, and if Σ ν,ρj was previously computed, then the algorithm does not need to compute Σ ν,ρi , because Σ ν,ρi = Σ ν,ρj . Hence, for each node ν, the number of computations of its rectilinear spirality sets that are performed over all possible trees T ρi is at most n ν + 1 = O(n ν ) (one for each different way of choosing the parent of ν).
If ν is a Q * -node, ν admits all integer spirality values in [−( − 1), ( − 1)], where is the length of the chain corresponding to ν. Thus Σ ν,ρi is computed in O(1) time, assuming that the value is stored at ν when T is computed.
If ν is a P-node with three children, Σ ν,ρi is computed in O(n) time. Namely, it is sufficient to check, for each of the six permutations of the children of ν and for each value in the rectilinear spirality set of one of the three children, whether the sets of the other two children contain the values that satisfy condition (ii) of Lemma 2. If ν is a P-node with two children, Σ ν,ρi is computed in O(n) with a similar approach: For each of the two permutations of the children of ν, for each value in the rectilinear spirality set of one of the two children, and for each combination of values α d w (w ∈ {u, v}, d ∈ {l, r}), check whether the set of the other children contains the value that satisfies condition (iii) of Lemma 3. Note that, there are O(n) possible spirality values that must be checked for each Pnode ν, and checking whether a specific value of spirality exists in the set of a child of ν takes O(1) time by assuming that we keep, at each node of the tree, a Boolean array of linear size that informs about the spirality values admitted for that node. Since ν deg(ν) = O(n), the computation of the rectilinear spirality sets of all P-nodes takes O(n 2 ) time, over all T ρi (i = 1, . . . , h).
Suppose now that ν is an S-node. By Lemma 4, in the first rooted tree for which we are able to compute the rectilinear spirality set of ν (i.e., in the first rooted tree for which all children of ν admit a rectilinear representation), we spend O(n ν n log 2 n) time to compute such a set. For each of the other O(n ν ) trees in which the parent of ν changes, we spend O(n log n) time to recompute the rectilinear spirality set of ν. Thus, for each S-node ν we spend in total O(n ν n log 2 n) + O(n ν n log n) = O(n ν n log 2 n) time over all visits of T ρi (i = 1, . . . , h), and hence, since ν deg(ν) = O(n), we spend O(n 2 log 2 n) time over all S-nodes of the tree.
Construction algorithm. Suppose that the test is positive for some rooted tree T ρi , with 1 ≤ i ≤ h. This implies that the final condition σ ν −σ ρi = 4 holds when ν is the root child, for some suitable values σ ν ∈ Σ ν,ρi and σ ρi ∈ [−( i − 1), ( i − 1)]. In order to construct a rectilinear representation of G with the reference edge corresponding to ρ i on the external face, we proceed as follows: First we assign spirality σ ν to the root child ν; then we visit T ρi top-down and assign a suitable value of spirality to each visited node, according to the spirality value already assigned to its parent; for each P-node, we also determine the permutation of its children that yields the desired value of spirality. Once the spirality values of each all nodes have been assigned and the permutation of the children of each P-node has been fixed, we apply the algorithm in [9] (which works for plane SP-graphs) to construct a rectilinear representation of G in linear time. More in detail, suppose that during the top-down visit we have assigned a spirality value σ ν to a node ν. If ν is not a Q * -node, we determine the spirality values that can be assigned to its children based on whether ν is a P-node or an S-node, namely: -ν is a P-node with three children. By Lemma 2, we check, for each of the six left-to-right orders (permutations) µ l , µ c , µ r of the three children of ν, whether Σ µ l ,ρi , Σ µc,ρi , and Σ µr,ρi contain the values σ µ l = σ ν + 2, σ µc = σ ν , and σ µr = σ ν − 2, respectively. If so, assign these values of spiralities to three children of ν and fix this order of the children for ν. This test takes O(1) time.
By the analysis above, the time complexity of the construction is dominated by the assignment of spirality values to the S-nodes, which is O(n 2 log n). Theorem 1. Let G be an n-vertex partial 2-tree. There exists an O(n 2 log 2 n) time algorithm that tests whether G is rectilinear planar and that computes a rectilinear representation of G in the positive case.
Proof. Let T be the BC-tree of G, and let B 1 , . . . , B q be the blocks of G (q ≥ 2). We denote by β(B i ) the block-node of T corresponding to B i (1 ≤ i ≤ q) and by T Bi the tree T rooted at β(B i ). For a cutvertex c of G, we denote by χ(c) the node of T that corresponds to c. Each T Bi describes a class of planar embeddings of G such that, for each non-root node β(B j ) (1 ≤ j ≤ q) with parent node χ(c), the cutvertex c lies in the external face of B j . We say that G is rectilinear planar with respect to T Bi if it is rectilinear planar for some planar embedding in the class described by T Bi . To check whether G is rectilinear planar with respect to T Bi , we have to perform a constrained rectilinear planarity testing for every block B 1 , . . . , B q so to guarantee that the rectilinear representations of the different blocks can be merged together at the shared cutvertices. The constraints for each block B j depend on whether j = i or not and by the angles that we may have to impose on each cutvertex c of B j . We denote by deg(c) the degree of c in G and by deg(c|B j ) the degree of c in B j . We first define the type of constraints that we need to impose for the cutvertices of B j , by distinguishing the cases j = i and j = i. Then, we explain how to handle these constraints in the rectilinear planarity testing. Case j = i. Let χ(c) be the parent node of β(B j ); we must restrict to those rectilinear representations of B j with c on the external face. If deg(c|B j ) = 1 then B j is a trivial block and we do not need to impose any constraint for B j . Hence, assume that deg(c|B j ) ≥ 2 and let β(B k ) be the parent node of χ(c) in T Bi . We distinguish different types of external constraints on c, based on the following cases: (i) If deg(c) = 4 and deg(c|B k ) = deg(c|B j ) = 2, then we impose an external reflex-angle constraint on c, which forces c to have a reflex angle on the external face f of any rectilinear representation of B j . A rectilinear representation of B k (if any) will be embedded in f . (ii) If deg(c) = 4 with deg(c|B k ) = 1 (i.e., B k is a trivial block) and deg(c|B j ) = 2, then B j has a sibling B h , which is a trivial block. In this case, we impose an external nonright-angle constraint on c, which forces c to have an angle larger than 90 • (i.e., either a flat or a reflex angle) in the external face f ; a rectilinear representation of B k (if any) will be embedded in f , while a rectilinear representation of B h (if any) will be embedded either in f (if c has a reflex angle in f ) or in the other face of B j incident to c (if c has a flat angle in f ). (iii) If deg(c) = 4 with deg(c|B k ) = 1 and deg(c|B j ) = 3, we impose an external flat-angle constraint on c, which forces c to have its unique flat angle in the external face f ; again, a rectilinear representation of B k (if any) will be embedded in f . (iv) If deg(c) = 3 and deg(c|B j ) = 2 (which implies deg(c|B k ) = 1), we impose an external nonright-angle constraint on c, as in case (ii).
Observe that, by definition, there is at most one external constraint on c in B j . Additionally, for any cutvertex c = c of B j , we impose a reflex-angle constraint on c when there is exactly one block B h that shares c with B j and deg(c |B j ) = deg(c |B h ) = 2.
We now describe how to handle the different types of constraints of B j in order to perform a constrained rectilinear planarity testing on B j . For each cutvertex c of B j such that there is a reflex-angle constraint or an external reflexangle constraint on c , we enhance B j with a gadget, called a reflex-angle gadget for c , depicted in Fig. 5. It consists of two vertices u and v, each subdividing one of the two edges incident to c in B j , and of two edge-disjoint paths connecting u and v, one having length two and the other having length four. Call B j the block resulting from B j after the addition of all reflex-angle constraints (including the external-reflex-angle constraint if any). B j is still an SP-graph and each cutvertex c with a reflex-angle constraint gadget is forced to have a reflex angle in any rectilinear representation of the block. Also, since each reflex-angle gadget consists of a constant number of nodes and edges, the size of B j is linear in the size of B j . From a rectilinear representation of B j we will obtain a constrained rectilinear representation of B j by simply ignoring the reflex-angle gadgets (once we have possibly exchanged the identity of c with the degree-2 vertex of the path of the gadget having length two).
If B j = B i (i.e., B j is the root of the BC-tree), we just execute on B j the rectilinear planarity testing in Lemma 5. Suppose vice-versa that c is a cutvertex of B j such that χ(c) is the parent of β(B j ). In this case we execute on B j a slight variant of the test in Lemma 5, depending on whether there is an external constraint on c or not, and depending on the type of external constraint on c, if any. More precisely: (i) If there is an external reflex-angle-constraint on c, execute on B j the test in Lemma 5, restricted to the only root of SPQ * -tree of B j whose reference chain is the path of length four of the reflex-angle gadget for c. This guarantees that c will be on the external face in any rectilinear representation of B j (after the removal of the gadget at the end of the test), and that its reflex angle will be in the external face. (ii) If there is an external flat-angle constraint on c, we know that deg(c|B j ) = 3. Denote by π 1 , π 2 , and π 3 the three chains incident to c in B j . We execute the test of Lemma 5 restricted to the roots of the SPQ * -tree of B j corresponding to π 1 , π 2 , and π 3 . For each of these three roots, c is the pole of a P-node ν with two children. Assuming, w.l.o.g., that c is the top pole of ν, we restrict the spirality set of ν by considering only those values that satisfy the relationship of Lemma 3 with α l c = 0 (i.e., the external angle at c must be a flat angle). (iii) Finally, if there is an external non-right-angle constraint on c, we know that deg(c|B j ) = 2. We execute the test of Lemma 5 restricted to the only root ρ of the SPQ * -tree whose reference chain π contains c. Denote by the length of π and let s and t be the two poles of π. Since c is not allowed to have a 90 • angle on the external face, the spirality σ ρ is restricted to take values in the range [−( −1), ( −2)], instead of [−( −1), ( −1)] (σ ρ = ( −1) corresponds to having a 90 • angle on the external face at all degree-2 vertices of π). Hence, in the rectilinear planarity testing, we just take into account such a restriction when we have to check the condition σ ν − σ ρ = 4 at the root level, where σ ν is a spirality value admitted by the root child ν.
We now clarify how to test in O(n 2 log 2 n) time whether G admits a rectilinear representation with respect to T Bi , over all i = 1, . . . , q. In a pre-processing phase, for each each block B j , we execute a constrained rectilinear planarity testing for each possible configuration of the cutvertex-nodes incident to β(B j ) in which either all these cutvertex-nodes are children of β(B j ) in a rooted BCtree of G (i.e., β(B j ) is the root) or one of them is chosen as the parent of β(B j ) and the remaining ones are the children of β(B j ). Based on Lemma 5 and on the analysis described above, this test can be executed in O(n 2 Bj log 2 n Bj ) time over all these configurations, where n Bj is the number of vertices in B j . Summing-up over all B j , this pre-processing phase is executed in O(n 2 log 2 n) time. During the execution of the pre-processing phase, for each configuration of the cutvertexnodes incident to β(B j ), we store at β(B j ) a Boolean local label that is either true if B j is rectilinear planar for that configuration or false otherwise. Note that, for each block-node we store a number of local labels equal to its degree plus one, thus in total we store O(n) local labels at the nodes of the BC-tree.
After the pre-processing phase, we first consider the rooted BC-tree T B1 . We visit T B1 bottom-up and for each node γ of T B1 (either a block-node or a cutvertex-node) we compute a Boolean cumulative label that is either true or false depending on whether all blocks in the sub-tree of T B1 rooted at γ (included γ) have a cumulative label true or not. Namely, for a leaf γ = β(B j ), its cumulative label coincides with the local label of β(B j ) for its current configuration of cutvertices. For each cutvertex-node, its cumulative label is the Boolean logic AND of the cumulative labels of its children. For each internal block-node, its cumulative label is the Boolean logic AND of its children and of its local label. Computing the cumulative labels of each node of T B1 takes O(n) time. At this point, one of the following three cases holds: Case 1. The cumulative label of the root is true. In this case the test is positive, as G is rectilinear planar with respect to T B1 .

Case 2.
There are two block-nodes γ 1 and γ 2 in T B1 with cumulative label false and that are along two distinct paths from a leaf to the root (which implies that there is a node with two children whose cumulative labels are false). In this case the test is negative, as for any other T Bi (i = 2, . . . , q), at least one of the subtrees rooted at γ 1 and γ 2 remains unchanged.
Case 3. All block-nodes with cumulative label false (possibly one block-node) are on the same path from a leaf to the root. In this case, let β(B j ) be the deepest node along this path (note that β(B j ) could also be the root). The rest of the test can be restricted to considering all rooted BC-trees whose root β(B i ) is a leaf of the subtree rooted at β(B j ). For each of these roots we repeat the procedure above, by visiting T Bi bottom-up and by computing the cumulative label of each node γ of T Bi only if the subtree of γ has changed with respect to any previous visit (otherwise we just reuse the cumulative label of γ computed in a previous tree without visiting its subtree again). Also, for a node γ whose parent has changed, the cumulative label of γ can be easily computed in O(1) time by looking at the cumulative label of γ in T B1 , at the cumulative label of the child of γ in T B1 that becomes its parent in T Bi , and at the cumulative label of the parent of γ in T B1 (if γ = β(B 1 )) that becomes its child in T Bi (recall that γ has at most one child whose cumulative label is false).
With the described algorithm, for each node γ of T of degree n γ , the cumulative label of γ is computed in O(n γ ) time for T B1 and in O(1) in each subsequent rooted BC-tree in which it changes the parent. Since each node γ changes its parent O(n γ ) times, summing up over all γ we conclude that the testing phase that follows the pre-processing phase takes in total O(n) time.
graphs, in Sections 4.2 and 4.3 we show how to overcome these difficulties and design a linear-time rectilinear planarity testing algorithm for this graph family.

Spirality Lower Bound
Theorem 2. For infinitely many integer values of n, there exists an n-vertex independent-parallel SP-graph for which every rectilinear representation has a component with spirality Ω(log n).
Proof. For any arbitrarily large even integer N ≥ 2, we construct an independentparallel SP-graph G with n = O(3 N ) vertices such that every rectilinear representation of G has a component with spirality larger than N . Let L = N 2 + 1. For any k ∈ {0, . . . , L}, let G k be the SP-graph inductively defined as follows: (i) G 0 is a chain of N + 4 vertices; (ii) G 1 is a parallel of three copies of G 0 , with coincident poles (Fig. 7(a)); (iii) for k ≥ 2, G k is a parallel composition of three series, each starting and ending with an edge, and having G k−1 in the middle ( Fig. 7(b)). The graph G is obtained by composing in a cycle two chains p 1 and p 2 , of three edges each, with two copies of G L (Fig. 7(c)). The graph G L for N = 4 is in Fig. 7(d). About the number n of vertices of G, let n k be the number of vertices of G k . We have n 0 = N + 4 and n k = O(3 k N ) for k ≤ N . Hence, Consider first the rooted SPQ * -tree T ρ of G, where ρ represents p 1 . All the planar embeddings of G encoded by T ρ have p 1 (and p 2 ) on the external face of G, and by symmetry of the construction they are all equivalent. Any rectilinear representation H of G with an embedding encoded by T ρ requires that the restriction of H to each copy of G L has spirality zero and, at the same time, the restriction of H to one of the copies of G 0 in G L has spirality N + 2. Indeed, due to Lemma 2, for each rectilinear representation H k of G k , the leftmost (resp. rightmost) child component of H k has spirality that is two units larger (resp. smaller) than the spirality of H k . Hence, if there existed a rectilinear representation of G L with spirality greater (resp. smaller) than zero, it would contain a representation of a copy of G 0 with spirality greater than N + 2 (resp. less than −(N + 2)), which is impossible, as the absolute value of spirality of any copy of G 0 is at most N + 2. See Fig. 7(e), where N = 4.
On the other hand, if we consider the planar embeddings encoded by T when rooted at a Q * -node whose chain p belongs to a copy of G L , the same argument as above applies to the copy of G L that does not contain p; namely, any rectilinear representation of this copy must contain a component with spirality N + 2.
Proof. The proof is by induction on the depth of the subtree of T ρ rooted at ν. In the base case ν is a Q * -node and the three properties trivially hold for G ν,ρ . In the inductive case, ν is either an S-node or a P-node. We analyze the two cases separately.
ν is an S-node. We inductively prove the three properties.
Proof of Property (c). If σ ν = 4, we still consider perform a case analysis based on the value of σ µ l − σ µr . Suppose first that σ µ l − σ µr = 2. There are three subcases.
The next lemma states an interesting property that is used to prove Lemma 8.
Lemma 7. Let ν be a P-node with two children and suppose that G ν,ρ admits spirality σ ν ≥ 0. There exists a rectilinear representation of G ν,ρ with spirality σ ν such that the difference of spirality between the left child component and the right child component of G ν,ρ is either 2 or 3.
Proof. Assume that M is odd (if M is even, the proof is similar). By hypothesis M ≥ 3. We prove that, if Σ + ν contains a value σ ν whose parity is different from the one of M , then Σ + ν,ρ = [0, M ] 1 . The proof is by induction on the depth of the subtree of T ρ rooted at ν. If ν is a Q * -node, then Σ + ν,ρ = [0, M ] 1 and the statement trivially holds. In the inductive case, ν is either an S-node or a Pnode. By Corollary 1, G ν,ρ admits spirality σ ν for every σ ν ∈ [1, M ] 2 . Below, we analyze separately the case when ν is an S-node, a P-node with three children, or a P-node with two children.