Two-Point L1 Shortest Path Queries in the Plane

Let P be a set of h pairwise-disjoint polygonal obstacles with a total of n vertices in the plane. In this paper, we consider the problem of building a data structure that can quickly compute an L1 shortest obstacle-avoiding path between any two query points s and t. We build a data structure of size O(n + h2 · log h · 4√log h) in O(n + h2 · log2 h · 4√log h) time that answers each query in O(log n + k) time, where k is the number of edges of the output path. Note that n + h2 · log2 h · 4√log h = O(n+h2+ϵ) for any constant ϵ > 0. We also extend our techniques to the weighted rectilinear version in which the "obstacles" of P are rectilinear regions with "weights" and allow L1 paths to travel through them with weighted costs. Our algorithm answers each query in O(log n + k) time with a data structure of size O(n2 · log n · 4√log n) that is built in O(n2 · log2 n · 4√log n) time.


INTRODUCTION
Let P be a set of h pairwise-disjoint polygonal obstacles in the plane with a total of n vertices. We consider two-point shortest obstacle-avoiding path queries for which the path lengths are measured in the L1 metric. The plane minus the interior of the obstacles is called the free space. Our goal is to build a data structure to quickly report an L1 shortest path in the free space between any two query points s and t. Previously, Chen et al. [4] constructed a data structure of size O(n 2 log n) in O(n 2 log 2 n) time that reports the length of the L1 shortest s-t path in O(log 2 n) time and an actual path in additional O(k) time, where k is the number of edges of the output path. Unless otherwise stated, when we say that the query time of a data structure is O(f (n, h)) (which may be a function of both n and h), we mean that the shortest path length can be reported in O(f (n, h)) time and an actual path can be found in additional time linear in the number of edges of the output path.
In this paper, we build a new data structure of size O(n + Our techniques also solve the weighted rectilinear version in which each "obstacle" P ∈ P is a region with a weight w(P ) ≥ 0 and each obstacle edge of P is axis-parallel; a path intersecting the interior of P is charged a cost depending on w(P ). Chen et al. [4] constructed a data structure of size O(n 2 log 2 n) in O(n 2 log 2 n) time that answers each twopoint shortest path query in O(log 2 n) time. We build a new data structure of size O(n 2 · log n · 4 √ log n ) in O(n 2 · log 2 n · 4 √ log n ) time that answers each query in O(log n) time. Note that n 2 · log 2 n · 4 √ log n = O(n 2+ϵ ) for any ϵ > 0.
The polygonal domain case (or "a polygon with holes"), in which P has h obstacles as defined above, is more difficult. For the Euclidean metric, Hershberger and Suri [20] built a single source shortest path map of size O(n log n) in O(n log n) time that answers each query in O(log n) time. For the L1 metric, Mitchell [28,30] built an O(n)-size single source shortest path map in O(n log n) time that answers each query in O(log n) time. Later, Chen and Wang [5,6,9] built an L1 single source shortest path map of size O(n) in O(n + h log h) time, with an O(log n) query time, for a triangulated free space. For two-point L1 shortest path queries, Chen et al. [4] gave the previously best solution, as mentioned above; for a special case where the obstacles are rectangles, ElGindy and Mitra [14] gave an O(n 2 ) size data structure that supports O(log n) time queries. For two-point queries in the Euclidean metric, Chiang and Mitchell [11] built a data structure of size O(n 11 ) that answers each query in O(log n) time, and alternatively, a data structure of size O(n 10 log n) with an O(log 2 n) query time; other data structures with trade-off between preprocessing and query time were also given in [11]. If the query points s and t are both restricted to the boundaries of the obstacles of P, Bae and Okamato [1] built a data structure of size O(n 5 poly(log n)) that answers each query in O(log n) time.
For the weighted region case, in which the "obstacles" allow paths to pass through their interior with weighted costs, Mitchell and Papadimitriou [33] gave an algorithm that finds a weighted Euclidean shortest path in a time of O(n 8 ) times a factor related to the precision of the problem instance. For the weighted rectilinear case, Lee et al. [27] presented two algorithms for finding a weighted L1 shortest path, and Chen et al. [4] gave an improved algorithm with O(n log 3/2 n) time and O(n log n) space. Chen et al. [4] also presented a data structure for two-point weighted L1 shortest path queries among weighted rectilinear obstacles, as mentioned above.

Our Approaches
Our first main idea is to propose an enhanced graph GE of size O(n √ log n2 √ log n ) by introducing more "Steiner points" than the graph in [4,12,13], to reduce the query time from O(log 2 n) to O(log n). Our preprocessing time and space are O(n 2 · log 2 n · 4 √ log n ) and O(n 2 · log n · 4 √ log n ), respectively. (This idea is then extended to solving the weighted rectilinear version.) To improve the data structure construction so that its time and space bounds depend linearly on n, we utilize the extended corridor structure [5,6,9]. Although this structure itself is not new, it was not used to process twopoint shortest path queries before. Our contribution is to present new techniques for two-point L1 path queries based on a set of interesting new observations. In the following, Section 2 introduces notations and sketches previous work. In Section 3, we propose our enhanced graph GE. In Section 4, we reduce the preprocessing time and space by using the extended corridor structure. In Section 5, we extend our techniques in Section 3 to the weighted rectilinear case. Due to the space limit, many details are omitted and can be found in the full version of this paper.
Henceforth, unless otherwise stated, "shortest paths" always refer to L1 shortest paths and "distances" and "lengths" refer to L1 distances and lengths. To distinguish from graphs, the vertices/edges of P are called "obstacle vertices/edges", and graph vertices are referred to as "nodes".

PRELIMINARIES
A path in the plane is x-monotone (resp., y-monotone) if its intersection with any vertical (resp., horizontal) line is either empty or connected. A path is xy-monotone if it is both x-monotone and y-monotone. It is well-known that any xy-monotone path is an L1 shortest path.
A point p is visible to a point q if the line segment pq is in the free space. A point p is horizontally visible to a line l if there is a point q on l such that pq is horizontal and is in the free space. For a line l and a point p, the point q ∈ l is the horizontal projection of p on l if pq is horizontal, and we denote it as p h (l) = q. Let ∂P denote the boundaries of all obstacles in P. For a point p in the free space, if we shoot a horizontal ray from p to the left, the first point on ∂P hit by the ray is called the leftward projection of p on ∂P, denoted by p l ; similarly, we define the rightward, upward, and downward projections of p on ∂P, denoted by p r , p u , and p d , respectively.
We sketch the graph in [4], denoted by G old , for answering two-point queries, which was originally proposed in [12,13] for computing a single shortest path. To define G old , two types of Steiner points are specified, as follows. For each obstacle vertex p, its four projections on ∂P, i.e., p l , p r , p u , and p d , are type-1 Steiner points. Clearly, there are totally O(n) type-1 Steiner points.
The type-2 Steiner points are on cut-lines, which are organized in a binary tree T (P) called the cut-line tree, defined as follows. For each node u of T (P), a set V (u) of obstacle vertices and a cut-line l(u) are associated with u, where l(u) is a vertical line through the median of the x-coordinates of the vertices in V (u). For the root r of T (P), V (r) is the set of all obstacle vertices of P. For the left (resp., right) child v of u, V (v) consists of the vertices of V (u) on the left (resp., right) of l(u). Since P has n vertices, the height of T (P) is O(log n). For every node u of T (P), for each vertex p ∈ V (u), if p is horizontally visible to l(u), then the point p h (l(u)), i.e., the horizontal projection of p on l(u), is a type-2 Steiner point. Since each obstacle vertex defines a type-2 Steiner point on at most one cut-line at each level of T (P), there are O(n log n) type-2 Steiner points.
The node set of G old consists of all obstacle vertices of P and all Steiner points thus defined. The edges of G old are defined as follows. First, for every obstacle vertex p, there is an edge pq in G old for each q ∈ {p l , p r , p u , p d }. Second, for every obstacle edge e of P, e may contain multiple type-1 Steiner points, and these Steiner points and the two endpoints of e are the nodes of G old on e; the segment connecting each pair of consecutive graph nodes on e defines an edge in G old . Third, for each cut-line l, any two consecutive type-2 Steiner points on l define an edge in G old if these two points are visible to each other. Finally, for each obstacle vertex p, if p defines a type-2 Steiner point p ′ on a cut-line, then pp ′ defines an edge in G old . Clearly, G old has O(n log n) nodes and O(n log n) edges.
It was shown in [12,13] that G old contains a shortest path between any two obstacle vertices. Chen et al. [4] used G old to answer two-point queries by "inserting" the query points s and t into G old so that shortest s-t paths are "controlled" by O(log n) nodes of G old , called "gateways". Let Vg(s, G old ) be the set of gateways of s, which we further partition into two subsets V 1 g (s, G old ) and V 2 g (s, G old ). We first define V 1 g (s, G old ) (of size O(1)). For each q ∈ {s l , s r , s u , s d }, let v1 and v2 be the two graph nodes adjacent to q on the obstacle edge containing q; then v1 and v2 are in V 1 g (s, G old ), and the paths sq ∪ qv1 and sq ∪ qv2 are the gateway edges from s to v1 and v2, respectively. Next, we define V 2 g (s, G old ), recursively, on the cut-line tree T (P). Let v be the root of T (P). Suppose s is horizontally visible to the cut-line l(v). Let q be the Steiner point on l(v) immediately above (resp., below) the projection point s h (l(v)); if q is visible to s h (l(v)), then q is in V 2 g (s, G old ) and the path ss h (l(v)) ∪ s h (l(v))q is the gateway edge from s to q. We call l(v) a projection cut-line of s if s is horizontally visible to l(v). We proceed to the left (resp., right) child of v in T (P) if s is to the left (resp., right) of l(v). We continue in this way until reaching a leaf of T (P). Thus, V 2 g (s, G old ) contains O(log n) type-2 Steiner points on O(log n) projection cut-lines.
The above defines the gateways and gateway edges. Henceforth, when we say "a path from s contains a gateway q", we implicitly mean that the path also contains the corresponding gateway edge. The above also defines O(log n) projection cut-lines for s, which will be used later in Section 3. It was shown in [4] that for any obstacle vertex v, there is a shortest s-v path in G old that contains a gateway of s.
Similarly, we define the gateway set Vg(t, G old ) for t. Assume that there is a shortest s-t path containing an obstacle vertex. Then, it was shown in [4] that there must be a shortest s-t path that contains a gateway vs ∈ Vg(s, G old ), a gateway vt ∈ Vg(t, G old ), and a shortest path from vs to vt in the graph G old . Based on this result, a gateway graph Gg(s, t) is built for the query on s and t, as follows. The node set of Gg(s, t) is {s, t} ∪ Vg(s, G old ) ∪ Vg(t, G old ). Its edge set consists of all gateway edges and the edges (vs, vt) for each vs ∈ Vg(s, G old ) and each vt ∈ Vg(t, G old ), where the weight of (vs, vt) is the length of a shortest path from vs to vt in G old . Hence, Gg(s, t) has O(log n) nodes and O(log 2 n) edges, and if we know the weights of all edges (vs, vt), then a shortest s-t path in Gg(s, t) can be found in O(log 2 n) time.
In the preprocessing, we compute a single source shortest path tree in G old from each node of G old . Then, the weight of each such edge (vs, vt) is obtained in O(1) time, and an actual shortest s-t path can also be reported in linear time by using the shortest path trees.
It is possible that no shortest s-t path contains any obstacle vertex. For example, consider a projection point s r of s and a projection point t d of t. If ss r intersects tt d , say at a point q, then sq ∪ qt is a shortest s-t path; otherwise, if s r and t d are both on the same obstacle edge, then ss r ∪ s r t d ∪ t d t is a shortest s-t path. We call such shortest s-t paths trivial shortest paths. Similarly, trivial shortest s-t paths can also be defined by other projection points of s and t. It was shown in [4] that if there is no trivial shortest s-t path, then there must exist a shortest s-t path that contains an obstacle vertex. As in [4], we can determine whether a trivial shortest s-t path exists in O(log n) time by using the horizontal and vertical visibility decompositions of P [4].

REDUCING THE QUERY TIME BASED ON AN ENHANCED GRAPH
In this section, we propose an "enhanced graph" GE that allows us to reduce the query time to O(log n). We first define GE, and then answer two-point queries by using GE.

The Enhanced Graph G E
On the nodes of GE, first, every node of G old is also a node in GE. In addition, GE contains the following type-3 Steiner points as nodes. To define these Steiner points, we introduce the concepts of "levels" and "super-levels" on the cut-line tree T (P) defined in Section 2. T (P) has O(log n) levels. We define the level numbers recursively: The root v is at the first level, and its level number is denoted by ln(v) = 1; for any Consider the i-th super-level. Let u be any node at the highest level (i.e., the level with the smallest level number) of this super-level. Let Tu(P) denote the subtree of T (P) rooted at u without including any node outside the i-th super-level (e.g., see Fig. 1 and its corresponding cut-lines and level numbers in Fig. 2 Recall that u is associated with a subset V (u) of obstacle vertices and a vertical cut-line l(u), and for any vertex p in V (u), if p is horizontally visible to l(u), then its projection point p h (l(u)) is a type-2 Steiner point. Each point p ∈ V (u) defines the following type-3 Steiner points. For each node v in Tu(P), if p is horizontally visible to l(v), then its projection point p h (l(v)) is a type-3 Steiner point (e.g., see Fig. 2; note that if p ∈ V (v), then the Steiner point is also a type-2 Steiner point). Hence, p defines O(2 √ log n ) type-3 Steiner points in the i-th superlevel of T (P). Let S(p) be the set of all type-2 and type-3 Steiner points on the cut-lines of the subtree Tu(P) induced by p, and let S(p) also contain p. In the order of the points in S(p) from left to right, we put an edge in GE connecting every two consecutive points in S(p) (e.g., see Fig. 2). Since the total number of obstacle vertices in V (u) for all nodes u at the same level of T (P) is n, the number of type-3 Steiner points thus defined in each super-level is O(n2 Hence, the total number of nodes in GE is O(n √ log n2 √ log n ). We have also defined above some edges in GE. The rest of edges in GE are defined similarly as in G old . Specifically, first, as in G old , for every obstacle vertex p, there is an edge pq in GE for each q ∈ {p l , p r , p u , p d }. Second, as in G old , for each obstacle edge e, e may contain multiple type-1 Steiner points; the segment connecting each pair of a a + 1 a + 2 a + 2 a + 2 a + 2 a + 1 level numbers:

Reducing the Query Time
Consider two query points s and t. Our key idea is: We define a new set of gateways for s, denoted by Vg(s, GE), containing O( √ log n) nodes of GE, such that for any obstacle vertex p of P, there exists a shortest path from s to p through a gateway of Vg(s, GE). The set Vg(s, GE) can be divided into two subsets V 1 g (s, GE) and . We discussed in Section 2 that s is horizontally visible to its O(log n) projection cut-lines. Since GE has more Steiner points than G odd , the intuition is that we do not have to include gateways in each projection cut-line of s. More specifically, we only need to include gateways in two projection cut-lines in each super-level. See the details below.
We define the relevant projection cut-lines of s, as follows. Let S be the set of projection cut-lines of s to the right of s. Consider a cut-line l ∈ S and suppose l is associated with a node u in the i-th super-level of the cut-line tree T (P) for some i. Then l is a relevant projection cut-line of s if ln(u) > ln(v) (i.e., their level numbers) for every For each relevant projection cut-line l of s, the Steiner point p (if any) immediately above (resp., below) the projection We also define the gateway edges in the same way as in Section 2. Again, when we say a shortest path from s containing a gateway, the path contains the corresponding gateway edge as well. Similarly, we define the gateway set Vg(t, GE) for t. We have the following lemma.
Lemma 1. For any obstacle vertex p of P, there exists a shortest path from s to p using GE that contains a gateway of s in Vg(s, GE); similar results hold for t and Vg(t, GE).
Proof. In the following, we only prove the case for s and Vg(s, GE), and the case for t can be proved similarly.
Recall Vg(s, G old ) is the gateway set of s defined on G old in Section 2, and there exists a shortest path π(s, p) from s to p using G old that contains a point a ∈ Vg(s, G old ) [4].
By the definition of GE, if any edge e of G old connecting two nodes u and v is not an edge of GE, then e can be viewed as being "divided" into many edges in GE such that the concatenation of these edges is a path from u to v in GE with the same length as e. Hence, π(s, p) is still a shortest path along GE. For any point a ∈ Vg(s, G old ) that is on a shortest s-p path, we call it a via point. If any via point a , then we are done as well. It remains to prove for the case that for every via point a, a ∈ V 2 g (s, G old ) and a ̸ ∈ V 2 g (s, GE) hold. Recall that every node of G old , including each via point a, is also a node of GE. Below, we find an xy-monotone path from s to such a via point a along GE that contains a gateway b ∈ V 2 g (s, GE). Since any xymonotone path is a shortest path, this gives a shortest s-p path (through a) containing a gateway b of s in Vg(s, GE), thus proving the lemma. W.l.o.g., we assume that a is to the right of s and above s (i.e., a is to the northeast of s, see Fig. 3 , and thus we are done. Otherwise, l(v) is not a relevant cut-line of s, and there exists a relevant cut-line l(v ′ ) of s to the right of s such that v ′ is in the i-th super-level of T (P) and ln(v ′ ) > ln(v). Next, we show that the sought gateway b lies on l(v ′ ).
It was shown in [4] (Lemma 3.4) that the level numbers of the projection cut-lines of s to the right of s, in the leftto-right order, are decreasing. This can be easily seen by considering the projection cut-lines of T (P) in a top-down manner. Hence, l(v ′ ) is to the left of l(v) (see Fig. 3). Let q be the obstacle vertex that defines the Steiner point a on l(v). By our definition of Steiner points, q must be in V (u) for the node u that is the highest ancestor of v (and v ′ ) in the i-th super-level. Therefore, if q is horizontally visible to l(v ′ ), then q also defines a Steiner point on l(v ′ ). We now show that q is horizontally visible to l(v ′ ), and for this, it suffices to prove that a is horizontally visible to l(v ′ ) since q is horizontally visible to a. Because a ∈ V 2 g (s, G old ) and no via point is in V 1 g (s, G old ), it was shown in [4] that a must be horizontally visible to the vertical line through s. Since l(v ′ ) is between s and a ∈ l(v), a is also horizontally visible to l(v ′ ).
Thus, q defines a Steiner point on l(v ′ ), i.e., the point q h (l(v ′ )) (see Fig. 3). By the definition of V 2 g (s, GE), the lowest Steiner point b on l(v ′ ) above s must be a gateway in V 2 g (s, GE). Note that b may or may not be q h (l(v ′ )), but b cannot be higher than q h (l(v ′ )). Thus, the concatenation of the gateway edge from s to b, bq h (l(v ′ )), and q h (l(v ′ ))a, which is an xy-monotone path from s to a using GE, contains the gateway b of V 2 g (s, GE). The lemma thus follows.
By Lemma 1, if there exists a shortest s-t path through an obstacle vertex of P, then there exists a shortest s-t path through a gateway of s in Vg(s, GE) and a gateway of t in Vg(t, GE). The next lemma computes the gateways. We summarize our algorithm in Theorem 1.
Theorem 1. We can build a data structure of size O(n 2 · log n · 4 √ log n ) in O(n 2 · log 2 n · 4 √ log n ) time that can answer each two-point L1 shortest path query in O(log n) time.
Proof. In the preprocessing, we build GE. For each node v of GE, we compute a shortest path tree in GE from v. We maintain a shortest path length table such that for any two nodes u and v, the shortest u-v path length in GE can be ob- log n ), computing and maintaining all these shortest path trees in GE take O(n 2 log n4 √ log n ) space and O(n 2 log 2 n4 √ log n ) time. We also do the preprocessing for Lemma 2.
Given any two query points s and t, we first check whether there is a trivial shortest s-t path, as discussed in Section 2, in O(log n) time by using the algorithm in [4] (with an O(n log n) time preprocessing). If there is a trivial shortest s-t path, then we are done. Otherwise, there must be a shortest s-t path that contains an obstacle vertex of P. Then, we first compute the gateway sets Vg(s, GE) and Vg(t, GE) in O(log n) time by Lemma 2. Finally, we determine the shortest s-t path length by using the gateway graph as discussed in Section 2, in O(log n) time, since there are O( √ log n) gateways and thus the gateway graph has O( √ log n) nodes and O(log n) edges. We can also report an actual shortest s-t path in additional time linear to the number of edges of the output path by using the shortest path trees of GE.

REDUCING THE TIME AND SPACE OF THE PREPROCESSING
In this section, we reduce the preprocessing in Theorem For this, we shall use the extended corridor data structure [5,6,9]. The corridor structure was used to solve shortest path problems (e.g., [22,24,25]), and new concepts like "ocean", "bays", and "canals" have been introduced [5,6,7,8,9,10], which we refer to as the "extended corridor structure". This structure is a subdivision of the free space on which algorithms for specific problems rely. While the structure itself is relatively simple, the main difficulty is to design efficient algorithms to exploit it. In some sense, the role played by the extended corridor structure is similar to that of the triangulation for many algorithms. To make the paper self-contained, we sketch it in Section 4.1.

The Extended Corridor Structure
For simplicity of discussion, we assume the obstacles of P are all contained in a rectangle R. Let F denote the free space in R, and Tri(F ) denote a triangulation of F . Let G(F ) denote the dual graph of Tri(F ). Based on G(F ), we compute a planar 3-regular graph, denoted by G 3 , possibly with loops and multi-edges, by repeatedly removing all degree-one nodes and then contracting all degree-two nodes. G 3 has O(h) faces, nodes, and edges [25]. Every node of G 3 corresponds to a triangle in Tri(F ), called a junction triangle. Removing all junction triangles from G 3 results in O(h) corridors, each of which corresponds to an edge of G 3 .
The boundary of each corridor C consists of four parts (see Fig. 4): (1) A boundary portion of an obstacle Pi ∈ P, from a point a to a point b; (2) a triangulation diagonal of a junction triangle from b to a point e on an obstacle Pj ∈ P (Pi = Pj is possible); (3) a boundary portion of Pj from e to a point f ; (4) a diagonal f a of a junction triangle. C is a simple polygon. Let π(a, b) (resp., π(e, f )) be the Euclidean shortest path from a to b (resp., e to f ) in C. The region HC bounded by π(a, b), π(e, f ), be, and f a is called an hourglass, which is open if π(a, b) ∩ π(e, f ) = ∅ and closed otherwise (see Fig. 4). If HC is open, then both π(a, b) and π(e, f ) are convex and are called the sides of HC ; otherwise, HC consists of two "funnels" and a path πC = π(a, b) ∩ π(e, f ) joining the two apices of the two funnels (e.g., x and y in Fig. 4), and πC is called the corridor path of C. The two funnel apices are called corridor path terminals. Each side of a funnel is also a convex chain.
Let If HC is open, let c and d be any two consecutive vertices on one side of HC such that cd is not an obstacle edge (e.g.,  Fig. 4). Note that c and d are on the same obstacle, say P . The free region enclosed by cd and the boundary portion of P between c and d is called a bay. We call cd the gate of the bay, which is an edge shared by the bay and M. If HC is closed, let x and y be the two apices of its two funnels. Consider two consecutive vertices c and d on a side of any funnel such that cd is not an obstacle edge. cd also defines a bay, unless c or d is a funnel apex (say, c = x) and c and d lie on different obstacles, in which case we call xd the canal gate at x = c (see Fig. 4  Let M ′ be the union of M and all corridor paths. For any two points s and t in M, it was proved that there exists an L1 shortest s-t path in M ′ [5,6,9,25].

Queries in the Ocean
Let Q = R \ M. Note that ∂Q is ∂M. Hence, ∂Q consists of O(h) convex chains with totally O(n) vertices, and ∂Q also contains O(h) reflex vertices that are corridor path terminals. Since P has h obstacles, Q contains at most h connected components and each obstacle of P is contained in a component of Q. For any point q in M, in this subsection, let q l , q r , q u , and q d denote the leftward, rightward, upward, and downward projection points of q on ∂Q, respectively.
An obstacle vertex p on ∂Q is said to be extreme if both its incident edges on ∂Q are on the same side of the vertical or horizontal line through p. Let Ve(Q) denote the set of all extreme vertices and corridor path terminals of Q. Since ∂Q consists of O(h) convex chains and O(h) reflex vertices that are corridor path terminals, |Ve(Q)| = O(h). We could build a graph on Ve(Q) with respect to Q in a similar way as we built GE with respect to P in Section 3, and then use this graph to answer queries when both query points are in M. However, in order to handle the general queries (in Section 4.3), we need to consider more points for building the graph. Specifically, let V(Q) = {p l , p r , p u , p d | p ∈ Ve(Q)} ∪ Ve(Q), i.e., in addition to Ve(Q), V(Q) also contains the four projections of all points in Ve(Q) on ∂Q. Since |Ve(Q)| =

O(h), |V(Q)| = O(h).
For each connected component Q of Q, let V(Q) denote the set of points of V(Q) on Q. Consider any two points a and b of V(Q) that are consecutive on the boundary ∂Q of Q. By the definitions, the portion of ∂Q between a and b that contains no other points of V(Q) is an xy-monotone path, and we call it an elementary curve of ∂Q. Hence, for any two points on an elementary curve, the portion of the curve between the two points is a shortest path.
Below, we define the graph GE(M) on V(Q) with respect to Q, similar to GE built in Section 3.
For the node set, each point of V(Q) defines a node in GE(M). In addition, GE(M) has type-1, type-2, and type-3 Steiner points as nodes. Such Steiner points are defined using V(Q) in a similar way as before, but with respect to ∂Q. The edges of GE(M) are similar to those in GE. We only point out the differences. One big difference is that for each corridor path, since its two terminals define two nodes in GE(M), GE(M) has an edge connecting these two nodes whose weight is the length of the corridor path. Another subtle difference is as follows. For each obstacle edge e of P, recall that GE has an edge connecting each pair of consecutive graph nodes on e. In contrast, here we consider each individual elementary curve of Q because not every vertex of Q defines a node in GE(M). Specifically, consider any elementary curve β of Q. Note that the two endpoints of β must be in V(Q) and thus define two nodes in GE(M). For each pair of consecutive graph nodes along β, we put an edge in GE(M) whose weight is the length of the portion of β between these two points.
We can prove that for any two points u and v in V(Q), a shortest path from u to v in GE(M) corresponds to a shortest path from u to v in the plane. The

The General Queries
We turn to the general queries in which at least one query point is not in M. We focus on the case when s ∈ B and B is a bay. The case when B is a canal can be handled by similar techniques although it is a little more complicated since each canal has two gates. The point t can be in B, M, or another bay or canal, and we discuss these three cases below. Let g denote the gate of B.
As an overview of our approach, we characterize the different possible ways that a shortest s-t path may cross the gate g, show how to find such a possible path for each way, and finally compute all possible "candidate" paths and select the one with the smallest path length as our solution.
If t ∈ B, since s ∈ B, there must exist a shortest s-t path in B. Let nB denote the number of vertices of B. In the preprocessing, we build a data structure for two-point Euclidean shortest path queries in B, denoted by D(B), in O(nB) time [15]. Using D(B), for any t ∈ B, the L1 shortest s-t path query can be answered in O(log n) time.

The Point t is in M
If t ∈ M, then since s ∈ B, a shortest s-t path must cross the gate g of B. A main difficulty for answering the general queries is to deal with this case. More specifically, we already have a graph GE(M) on M, and our goal is to design a mechanism to connect the bay B with GE(M) through the gate g, so that it can capture the shortest path information in the union of B and M ′ (recall that M ′ is the union of M and all corridor paths).
We define three crucial points z1, z2, and z (see Fig. 5). Suppose we move along π(z ′ , a1) from z ′ ; let z ′ 1 be the first point on π(z ′ , a1) we encounter that is horizontally visible to g = a1a2. Similarly, as moving along π(z ′ , a2) from z ′ , let z ′ 2 be the first point on π(z ′ , a2) encountered that is vertically visible to g. Note that in some cases z ′ 1 (resp., z ′ 2 ) can be z ′ , a1, or a2. Let z1 be the horizontal projection of z ′ 1 on g and z2 be the vertical projection of z ′ 2 on g (see Fig. 5). Let z be the intersection of the horizontal line containing z1z ′ 1 and the vertical line containing z2z ′ 2 . With a preprocessing of O(nB) time and space, the three points z1, z2, and z can be found in O(log n) time for any query point s in B. We omit the details. We can prove that the point z1 is above z2, i.e., the y-coordinate of z1 is no smaller than that of z2. The proofs for the following two lemmas are also omitted.
Lemma 5. For any point p ∈ a1z1, there is a shortest path from s to p that contains z1; likewise, for any p ∈ a2z2, there is a shortest path from s to p that contains z2. Lemma 6. The point z is in F , and for any point p ∈ z1z2, there is a shortest path from s to p that contains z.
By Lemma 5, suppose a shortest s-t path crosses g at a point on a1z1 (similar results hold for a2z2). Then, there must be a shortest s-t path that is a concatenation of a shortest path π(s, z1) in B and a shortest path π(z1, t) from z1 to t in M ′ . The path π(s, z1) can be found using the data structure D(B) and π(z1, t) can be found by Lemma 4 since both z1 and t are in M. Hence, such a shortest s-t path query is answered in O(log n) time.
In the following, we assume every shortest s-t path crosses the interior of z1z2. By Lemma 6, there is a shortest s-t path that is a concatenation of a shortest path π(s, z) from s to z in B and a shortest path π(z, t) from z to t (which crosses z1z2). π(s, z) can be found by D(B) in O(log n) time. To compute π(z, t), there are two cases depending on whether π(z, t) contains a point in V(g) ∩ z1z2, where V(g) is the set of points of V(Q) lying on g. If no shortest path π(z, t) contains a point in V(g) ∩ z1z2, Lemma 7 (proof omitted) implies that there is a trivial shortest path π(z, t), which can be easily found in O(log n) time.
Lemma 7. If no shortest path π(z, t) contains a point in V(g) ∩ z1z2 (this includes the case of V(g) = ∅), then t must be horizontally visible to zz2.
It remains to handle the case when a shortest path π(z, t) contains a point in V(g) ∩ z1z2. For this, we shall build a graph GE(g) inside B and merge it with the graph GE(M) on M so that the merged graph can help find π(z, t) in O(log n) time. Next, we introduce the graph GE(g).
Assume V(g) ̸ = ∅. Let hg = |V(g)|. The graph GE(g) is defined on the points of V(g) in a similar way as GE in Section 3. One big difference is that GE(g) is built inside B and uses vertical cut-segments in B instead of cut-lines. Also, no type-1 Steiner point is needed for GE(g). Specifically, we define a cut-segment tree T (g) as follows. The root u of T (g) is associated with a point set V (u) = V(g). Each node u of T (g) is also associated with a vertical cut-segment l(u), defined as follows. Let p be the point of V (u) that has the median x-coordinate among all points in V (u). Note that p is on g. We extend a vertical line segment from p upwards into the interior of B until it hits ∂B; this segment is the cut-segment l(u). The left (resp., right) child of u is defined recursively on the points of V (u) to the left (resp., right) of l(u). The height of T (g) is O(log hg).
We define the type-2 and type-3 Steiner points on the cutsegments of T (g) in the same way as in Section 3. The node set of GE(g) consists of all points of V(g) and all Steiner points on the cut-segments of T (g). The edges of GE(g) are defined similarly as those in GE and we omit the details. √ log hg ) time (the algorithm is omitted). We define a gateway set Vg(z, GE(g)) for z on GE(g) similarly as V 2 g (s, GE) in Section 3, but only on the Steiner points in the triangle △zz1z2 (because △zz1z2 contains a shortest path from z to any point in V(g) ∩ z1z2). Specifically, for each relevant projection cut-segment l of z (defined similarly as the relevant projection cut-lines) to the right of z, the node of GE(g) on l immediately below the horizontal projection point of z on l is in Vg(z, GE(g)). Thus, |Vg(z, GE(g))| = O( √ log hg). We can prove that for any point p ∈ V(g) ∩ z1z2, there is a shortest path from z to p in B using GE(g) that contains a gateway of z in Vg(z, GE(g)).
Since V(g) ⊆ V(Q), each point of V(g) is also a node of GE(M). We merge the two graphs GE(M) and GE(g) into one graph, GE(M, g), by treating the two nodes in these two graphs defined by the same point in V(g) as a single node. We can obtain that if a shortest s-t path contains a point in V(g) ∩ z1z2, then there is a shortest s-t path along GE(M, g) containing a gateway of z in Vg(z, GE(g)) and a gateway of t in Vg(t, GE(M)). By Lemma 8 (proof omitted), for the case when a shortest path π(z, t) contains a point in V(g) ∩ z1z2, we can find such a shortest path π(z, t) in O(log n) time .
We have discussed all possible cases of finding a shortest s-t path when s is in a bay B and t is in the ocean M, and in each case, we can obtain a shortest path in O(log n) time.

The Point t is in Another Bay
Let Bs be the bay containing s with gate gs, and Bt be the bay containing t with gate gt. Any shortest s-t path must cross gs and gt. We need to consider the cases how a shortest s-t path may cross different portions of gs and gt.
We define the crucial points z1, z2, and z in Bs for s in the same way as before, but denote them by z1(s), z2(s), and z(s) instead. Similarly, we define the corresponding three points z1(t), z2(t), and z(t) in Bt for t. Based on our observations above, there must be a shortest s-t path π(s, t) with the following cases: (1) π(s, t) contains a point in {z1(s), z2(s)} and a point in {z1(t), z2(t)}; (2) π(s, t) contains z(s) and a point in {z1(t), z2(t)}; (3) π(s, t) contains z(t) and a point in {z1(s), z2(s)}; (4) π(s, t) contains z(s) and z(t). Shortest paths for the first three cases can be found by the techniques we discussed above. Below, we present our algorithm for finding a shortest s-t path for Case (4), assuming that there is no shortest path for the first three cases. We focus on finding a shortest path π(z(s), z(t)) from z(s) to z(t) since a shortest path from s to z(s) in Bs and a shortest path from t to z(t) in Bt can be found easily. Also, since the first three cases do not occur, any shortest path π(z(s), z(t)) must cross the interior of z1(s)z2(s) on gs and the interior of z1(t)z2(t) on gt.
Recall that we have defined a graph GE(gs) in Bs on the points of V(gs), which consists of all points of V(Q) lying on gs. We also find a gateway set Vg(z(s), GE(gs)) for z(s) on GE(gs). Similarly, for Bt and its gate gt, we define V(gt), GE(gt), and Vg(z(t), GE(gt)). Let GE(M, gs, gt) be the graph formed by merging GE(M), GE(gs), and GE(gt).
We can prove the following (proof omitted): If there is a shortest path from z(s) to z(t) containing a point in V(gs) ∩ z1(s)z2(s) and a point in V(gt) ∩ z1(t)z2(t), then there is a shortest path from z(s) to z(t) along GE(M, gs, gt) that contains a gateway of z(s) in Vg(z(s), GE(gs)) and a gateway of z(t) in Vg(z(t), GE(gt)). Otherwise, there must exist a trivial shortest path from z(s) to z(t), as implied by the following lemma, which generalizes Lemma 7. Based on the above discussion, we can find a shortest z(s)z(t) path by either using the gateways of z(s) and z(t) in the merged graph GE(M, gs, gt) or shooting horizontal and vertical rays from z(s) and z(t). In either case, we can find a shortest path in O(log n) time.
It remains to solve the canal case when the query points are in canals. The algorithm is similar and the only difference is that we have to consider two gates for each canal. Specifically, suppose s is in a canal Cs and t is in a canal Ct. If Cs ̸ = Ct, then there must be a shortest s-t path π that intersects a gate of Cs at a point ps and intersects a gate of Ct at a point pt such that the subpath π(s, ps) is in Cs, the subpath π(pt, t) is in Ct, and the subpath π(ps, pt) is in M ′ . Hence, we can use a similar approach as for the bay case to find a shortest s-t path by considering all four gate pairs of Cs and Ct. If Cs = Ct, while we can treat this case in the same way as for the case of Cs ̸ = Ct, we need to consider one more possible situation when a shortest s-t path may be contained entirely in Cs, which is easy since Cs is a simple polygon. If one of Cs or Ct is a bay, the case can be handled in a similar fashion. If we replace all enhanced graphs, e.g., GE(M) and GE(g) for every gate g, by the corresponding graphs similar to G old in [4] as discussed in Section 2 or the shortest path maps, then we obtain two data structures with the following bounds: (1) O(n + h 2 log 2 h) time and space preprocessing, and O(log n+log 2 h) time queries; (2) O(nh log h+h 2 log 2 h) time and O(nh log h) space preprocessing, and O(log n log h) time queries. The details are omitted.

THE WEIGHTED RECTILINEAR CASE
In this section, we extend our techniques in Section 3 to the weighted rectilinear case. In this case, every polygonal obstacle P ∈ P is rectilinear and weighted, i.e., each edge of P is either horizontal or vertical and P has a weight w(P ) ≥ 0. If a line segment e is in P , the weighted length of e is x·(1+ w(P )), where x is the L1 length of e. Any polygonal path π can be divided into a sequence of maximal line segments such that each segment is contained in the same obstacle or in the free space F ; the weighted length of π is the sum of the weighted lengths of all maximal line segments of π.
Consider a vertex v of any rectilinear obstacle P such that the interior angle of P at v is 3π/2. We define the internal projections of v on the boundary ∂P of P as follows. Suppose u1v and u2v are the two edges of P incident to v. We extend u1v into the interior of P along the direction from u1 to v until we hit ∂P at the first point, which is an internal projection of v; similarly, we define another interval projection of v by extending u2v. Internal projections are used to control shortest paths that pass through the interior of obstacles.
The "visibility" in the weighted case is defined in a slightly different way: Two points p and q are visible to each other if pq is entirely in either F or an obstacle.
Let V be the set of all obstacle vertices of P, their internal projections, and all type-1 Steiner points. Then |V| = O(n). We build a graph GE(V) on V similar to the one presented in Section 3, with the following differences. (1) The visibility here is based on the new definition above. (2) Since a path can travel through the interior of any obstacle, for each cut-line l, an edge in GE(V) connects every two consecutive Steiner points on l, whose weight is the weighted length of the line segment connecting the two points. (3) In addition to the vertical cut-lines, there are also horizontal cut-lines, which are defined similarly and have type-2 and type-3 Steiner points defined on them similarly to those on the vertical cut-lines. Thus, GE(V) has O(n √ log n2 √ log n ) nodes and edges. The graph of GE(V) can be built in O(n log 3/2 n2 √ log n ) time, and we omit the algorithm. Consider any two query points s and t. For simplicity of discussion, we assume that both s and t are in F (the general case can also be handled similarly). With a preprocessing of O(n 2 ) time and space, a shortest s-t path that does not contain any vertex of V can be found in O(log n) time [4]. Thus in the following, we focus on finding a shortest s-t path containing at lease one vertex of V.
Let Y (s) be the set of s and the four projections of s on ∂P, i.e., Y (s) = {s, s l , s r , s u , s d }; similarly, let Y (t) = {t, t l , t r , t u , t d }. It was shown in [4] that it suffices to find a shortest path from p to q containing a vertex of V for every p ∈ Y (s) and every q ∈ Y (t). With a little abuse of notation, we let s be any point in Y (s) and t be any point in Y (t). Our goal is to find a shortest s-t path that contains at lease one vertex of V. Unless otherwise indicated, any shortest s-t path mentioned below refers to a shortest s-t path that contains a vertex of V.
In [4], similar to the discussions in Section 2, O(log n) gateways for s and O(log n) gateways for t were defined, such that any shortest s-t path must contain a gateway of s and a gateway of t. Hence by using the gateway graph, a shortest s-t path can be found in O(log 2 n) time.
Based on our enhanced graph GE(V), as in Section 3, we define a new gateway set Vg(s, GE(V)) of size O( √ log n) for s. The gateway set Vg(s, GE(V)) contains O( √ log n) Steiner points on the vertical cut-lines defined in the same way as those in V 2 g (s, GE) in Section 3; similarly, Vg(s, GE(V)) also contains O( √ log n) Steiner points on the horizontal cutlines. The gateway set Vg(t, GE(V)) is defined similarly. We can prove (proof omitted) that there exists a shortest s-t path containing a gateway of s in Vg(s, GE(V)) and a gateway of t in Vg(t, GE(V)). Next, we show how to compute the two gateway sets and (the weights of) their gateway edges. Below, we discuss only the case for s.
The approach for Lemma 2 can still be used to compute the gateway set Vg(s, GE(V)) in O(log n) time, but it cannot compute the weights of the gateway edges for the following reasons. Consider a gateway v ∈ Vg(s, GE(V)), say on a vertical cut-line l. Then there is a gateway edge (s, v) that consists of two line segments ss h (l) and s h (l)v (recall that s h (l) is the horizontal projection of s on l). Hence, the weighted length of the edge (s, v) is the sum of the weighted lengths of these two line segments. It was shown in [4] that ss h (l) must be in the free space (since s is in F ); thus, the weighted length of ss h (l) is easy to compute. However, the vertical segment s h (l)v may intersect multiple obstacles [4]. We use a slightly different algorithm to compute in O(log n) time the gateways and the weights of the gateway edges for s in the next lemma and the proof is omitted. Consider any two query points s and t. First, we use the approach in [4] to find a shortest s-t path that does not contain any obstacle vertex of P (if any), after a preprocessing of O(n 2 ) time and space. Below, we focus on finding a shortest s-t path containing an obstacle vertex of P, which must contain a gateway of s in Vg(s, GE(V)) and a gateway of t in Vg(t, GE(V)). By Lemma 10, we can compute both Vg(s, GE(V)) and Vg(t, GE(V)) in O(log n) time. Then, a shortest s-t path can be found by building a gateway graph in O(log n) time since the sizes of both Vg(s, GE(V)) and Vg(t, GE(V)) are O( √ log n). As in [4], after the shortest s-t path length is computed, an actual shortest s-t path can be