@@ -14,34 +14,61 @@ function RouteChannel(pa::Path{T}, capacity=0) where {T}
1414end
1515
1616# Return a node corresponding to the section of the channel that the segment actually runs through
17- function segment_channel_section (ch:: RouteChannel{T} , wireseg_start, wireseg_stop, prev_width, next_width; margin= zero (T)) where {T}
17+ function segment_channel_section (
18+ ch:: RouteChannel{T} ,
19+ wireseg_start,
20+ wireseg_stop,
21+ prev_width,
22+ next_width;
23+ margin= zero (T)
24+ ) where {T}
1825 d = wireseg_stop - wireseg_start
1926 # Adjust for margins and track vs channel direction to get the channel node section used by actual segment
20- if abs (d) <= 2 * margin + prev_width + next_width
27+ if abs (d) <= 2 * margin + prev_width + next_width
2128 # handle case where margin consumes entire segment
2229 # Just have a zero length Straight at the midpoint
23- track_mid = (wireseg_start + wireseg_stop)/ 2
30+ track_mid = (wireseg_start + wireseg_stop) / 2
2431 midpoint = ch. node. seg (track_mid)
2532 middir = direction (ch. node. seg, track_mid)
26- channel_section = Node (Straight (zero (T), midpoint, middir), SimpleTrace (width (ch. node. sty, track_mid)))
33+ channel_section = Node (
34+ Straight (zero (T), midpoint, middir),
35+ SimpleTrace (width (ch. node. sty, track_mid))
36+ )
2737 elseif d > zero (d) # segment is along channel direction
28- channel_section = split (ch. node,
29- [wireseg_start + margin + prev_width/ 2 ,
30- wireseg_stop - margin - next_width/ 2 ])[2 ]
38+ channel_section = split (
39+ ch. node,
40+ [
41+ wireseg_start + margin + prev_width / 2 ,
42+ wireseg_stop - margin - next_width / 2
43+ ]
44+ )[2 ]
3145 elseif d < zero (d) # segment is counter to channel direction
32- channel_section = reverse (split (ch. node,
33- [wireseg_stop + margin + next_width/ 2 ,
34- wireseg_start - margin - prev_width/ 2 ])[2 ])
46+ channel_section = reverse (
47+ split (
48+ ch. node,
49+ [
50+ wireseg_stop + margin + next_width / 2 ,
51+ wireseg_start - margin - prev_width / 2
52+ ]
53+ )[2 ]
54+ )
3555 end
3656 return channel_section
3757end
3858
3959function track_path_segment (n_tracks, channel_section, track_idx; reversed= false )
40- return offset (channel_section. seg,
41- track_section_offset (n_tracks, width (channel_section. sty), track_idx; reversed))
60+ return offset (
61+ channel_section. seg,
62+ track_section_offset (n_tracks, width (channel_section. sty), track_idx; reversed)
63+ )
4264end
4365
44- function track_section_offset (n_tracks, section_width:: Coordinate , track_idx; reversed= false )
66+ function track_section_offset (
67+ n_tracks,
68+ section_width:: Coordinate ,
69+ track_idx;
70+ reversed= false
71+ )
4572 # (spacing) * number of tracks away from middle track
4673 sgn = reversed ? - 1 : 1
4774 spacing = section_width / (n_tracks + 1 )
5077
5178function track_section_offset (n_tracks, section_width:: Function , track_idx; reversed= false )
5279 # (spacing) * number of tracks away from middle track
53- return t -> (reversed ? - 1 : 1 ) * (section_width (t) / (n_tracks + 1 )) * (track_idx - (1 + n_tracks) / 2 )
80+ return t ->
81+ (reversed ? - 1 : 1 ) *
82+ (section_width (t) / (n_tracks + 1 )) *
83+ (track_idx - (1 + n_tracks) / 2 )
5484end
5585
5686reverse (n:: Node ) = Paths. Node (reverse (n. seg), reverse (n. sty, pathlength (n. seg)))
@@ -67,7 +97,7 @@ function reverse(b::BSpline{T}) where {T}
6797 p1 = b. p0
6898 r = Interpolations. scale (
6999 interpolate (p, Interpolations. BSpline (Cubic (NeumannBC (t0, t1)))),
70- range (1 - tmax, stop= 1 - tmin, length= length (p))
100+ range (1 - tmax, stop= 1 - tmin, length= length (p))
71101 )
72102 α0 = rotated_direction (b. α1, RotationPi ())
73103 α1 = rotated_direction (b. α0, RotationPi ())
@@ -80,23 +110,35 @@ reverse(s::TaperTrace{T}, l) where {T} = TaperTrace{T}(s.width_end, s.width_star
80110reverse (s:: SimpleTrace , l) = s
81111reverse (s:: GeneralTrace , l) = GeneralTrace (t -> width (s, l - t))
82112# Define methods for CPW even though they're not allowed for channels
83- reverse (s:: TaperCPW{T} , l) where {T} = TaperCPW {T} (s. trace_end, s. gap_end, s. trace_start, s. gap_start, s. length)
113+ reverse (s:: TaperCPW{T} , l) where {T} =
114+ TaperCPW {T} (s. trace_end, s. gap_end, s. trace_start, s. gap_start, s. length)
84115reverse (s:: SimpleCPW , l) = s
85116reverse (s:: GeneralCPW , l) = GeneralCPW (t -> trace (s, l - t), t -> gap (s, l - t))
86117# For compound segments, reverse the individual sections and reverse their order
87118# Keep the same tag so if a compound segment/style pair matched before they will still match
88119reverse (s:: CompoundSegment ) = CompoundSegment (reverse (reverse .(s. segments)), s. tag)
89120function reverse (s:: CompoundStyle{T} , l) where {T}
90121 lengths = reverse (diff (s. tgrid))
91- CompoundStyle {T} (reverse (reverse .(s. styles, lengths)), cumsum (reverse (lengths)), s. tag)
122+ return CompoundStyle {T} (
123+ reverse (reverse .(s. styles, lengths)),
124+ cumsum (reverse (lengths)),
125+ s. tag
126+ )
92127end
93128
94129abstract type AbstractMultiRouting <: RouteRule end
95130
96131abstract type AbstractChannelRouting <: AbstractMultiRouting end
97132
98- function _route! (p:: Path{T} , p1:: Point , α1, rule:: AbstractChannelRouting ,
99- sty, waypoints, waydirs) where {T}
133+ function _route! (
134+ p:: Path{T} ,
135+ p1:: Point ,
136+ α1,
137+ rule:: AbstractChannelRouting ,
138+ sty,
139+ waypoints,
140+ waydirs
141+ ) where {T}
100142 # Track segments for each channel
101143 track_path_segs = track_path_segments (rule, p, p1)
102144 waypoints = Point{T}[] # Segments too short for margins will just become waypoints for transitions
@@ -105,14 +147,21 @@ function _route!(p::Path{T}, p1::Point, α1, rule::AbstractChannelRouting,
105147 if iszero (pathlength (track_path_seg)) # Was too short for margins
106148 push! (waypoints, p0 (track_path_seg))
107149 else
108- route! (p, p0 (track_path_seg), α0 (track_path_seg), next_entry_rule, sty; waypoints)
150+ route! (
151+ p,
152+ p0 (track_path_seg),
153+ α0 (track_path_seg),
154+ next_entry_rule,
155+ sty;
156+ waypoints
157+ )
109158 push! (p, Node (track_path_seg, sty), reconcile= false ) # p0, α0 reconciled by construction
110- p[end - 1 ]. next = p[end ]
111- p[end ]. prev = p[end - 1 ]
159+ p[end - 1 ]. next = p[end ]
160+ p[end ]. prev = p[end - 1 ]
112161 # Note `auto_curvature` BSpline uses curvature from end of previous segment
113162 # and is not reconciled with the new node
114163 # But we can do this ourselves
115- _reconcile_curvature! (p[end - 1 ], next_entry_rule)
164+ _reconcile_curvature! (p[end - 1 ], next_entry_rule)
116165 empty! (waypoints)
117166 end
118167 end
@@ -132,7 +181,7 @@ function _reconcile_curvature!(n::Node{T}, rule::BSplineRouting) where {T}
132181 end
133182 κ1 = if n. next === n
134183 0.0 / oneunit (T)
135- else
184+ else
136185 signed_curvature (segment (n. next), zero (coordinatetype (n)))
137186 end
138187 _set_endpoints_curvature! (segment (n), κ0, κ1)
145194
146195struct SingleChannelRouting{T} <: AbstractChannelRouting
147196 channel:: RouteChannel{T}
148- transition_rules:: Tuple{<:RouteRule,<:RouteRule}
149- transition_margins:: Tuple{T,T}
197+ transition_rules:: Tuple{<:RouteRule, <:RouteRule}
198+ transition_margins:: Tuple{T, T}
150199 segment_tracks:: Dict{Path{T}, Int}
151200end
152201function SingleChannelRouting (ch:: RouteChannel{T} , rule:: RouteRule , margin:: T ) where {T}
@@ -159,18 +208,34 @@ exit_margin(scr::SingleChannelRouting) = last(scr.transition_margins)
159208num_tracks (scr:: SingleChannelRouting ) = maximum (values (scr. segment_tracks))
160209track_idx (scr, pa) = scr. segment_tracks[pa]
161210function set_track! (scr, pa, track_idx)
162- scr. segment_tracks[pa] = track_idx
211+ return scr. segment_tracks[pa] = track_idx
163212end
164213
165214function track_path_segments (rule:: SingleChannelRouting , pa:: Path , endpt)
166215 wireseg_start = pathlength_nearest (rule. channel. node. seg, p1 (pa))
167216 wireseg_stop = pathlength_nearest (rule. channel. node. seg, endpt)
168- return [track_path_segment (num_tracks (rule),
169- segment_channel_section (rule. channel, wireseg_start, wireseg_stop, 2 * entry_margin (rule), 2 * exit_margin (rule)),
217+ return [
218+ track_path_segment (
219+ num_tracks (rule),
220+ segment_channel_section (
221+ rule. channel,
222+ wireseg_start,
223+ wireseg_stop,
224+ 2 * entry_margin (rule),
225+ 2 * exit_margin (rule)
226+ ),
170227 track_idx (rule, pa),
171- reversed= wireseg_start > wireseg_stop)]
228+ reversed= wireseg_start > wireseg_stop
229+ )
230+ ]
172231end
173232
174- function _update_with_graph! (rule:: SingleChannelRouting , route_node, graph; track= num_tracks (rule)+ 1 , kwargs... )
175- set_track! (rule, route_node. component. _path, track)
176- end
233+ function _update_with_graph! (
234+ rule:: SingleChannelRouting ,
235+ route_node,
236+ graph;
237+ track= num_tracks (rule) + 1 ,
238+ kwargs...
239+ )
240+ return set_track! (rule, route_node. component. _path, track)
241+ end
0 commit comments