//routelength.bcpl

// Computes the length of a net, for use in ordering them

// last modified by E. McCreight, June 25, 1981 2:28 PM

get "route.defs"

let ComputeLengths(net) be
[ // Compute the total net length and shortest arc length, or area for Multiwire
let shortestarc = infinity
let netlength = 0
let minx,miny = infinity,infinity
let maxx, maxy = 0,0
let pin = net>>net.pinList
if @pin ne mark then
[
let x1,y1 = nil,nil
GetPinCoord(0, pin, lv x1, lv y1)
if x1 ls minx then minx = x1
if x1 gr maxx then maxx = x1
if y1 ls miny then miny = y1
if y1 gr maxy then maxy = y1

pin = @pin
while @pin ne mark do
[
let x2,y2 = nil,nil
GetPinCoord(0, pin, lv x2, lv y2)
if x2 ls minx then minx = x2
if x2 gr maxx then maxx = x2
if y2 ls miny then miny = y2
if y2 gr maxy then maxy = y2

let arclength = StandardMetric(x1, y1, x2, y2)
netlength = netlength+arclength
if arclength ls shortestarc then shortestarc = arclength
pin = @pin
x1 = x2; y1 = y2
]
]
net>>net.shortestarc = shortestarc eq infinity? 0, // single-node net
(doMultiWire?
(((maxx-minx)/4)*((maxy-miny)/4)), // compute area of enclosing rectangle
shortestarc // shortest arc for Rosemary
)
net>>net.netlength = netlength
]