Skip to content

Commit

Permalink
fix squiggly wires (#343)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomcl authored Aug 5, 2023
1 parent 7e6dc98 commit 1fbc4fc
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
17 changes: 13 additions & 4 deletions src/Renderer/DrawBlock/BusWire.fs
Original file line number Diff line number Diff line change
Expand Up @@ -201,19 +201,27 @@ let logSegmentsInModel (model: Model) (wireSegmentIdPairs: (int*ConnectionId) li

/// Given the coordinates of two port locations that correspond
/// to the endpoints of a wire, as well as the final port orientation
/// this function returns a list of wire vertices
/// this function returns a list of wire vertices.
/// The starting segment will always be from a Right Edge (and so in increasing X direction)
let makeInitialWireVerticesList (wireStartPos : XYPos) (wireEndPos : XYPos) (portOrientation : Edge) =
let xStart, yStart, xEnd, yEnd = wireStartPos.X, wireStartPos.Y, wireEndPos.X, wireEndPos.Y

let nubLength = Constants.nubLength
let nubLength =
let xDelta = xEnd - xStart
let yDelta = abs (yEnd - yStart)
match portOrientation with
| CommonTypes.Edge.Left when xDelta > 0 -> min nubLength (xDelta / 2.)
| CommonTypes.Edge.Top
| CommonTypes.Edge.Bottom when xDelta > 0 -> min nubLength xDelta
| _ -> nubLength
/// This is a fixed-length horizontal stick with a zero-length vertical after it.
/// It starts nearly all the wires
let rightNub = [
{X = xStart; Y = yStart};
{X = xStart+nubLength; Y = yStart}; //Stick horizontal
{X = xStart+nubLength; Y = yStart}; //Length 0 vertical
]
let rightwards = xStart - xEnd + 20. < 0
let rightwards = xStart - xEnd < 0
let downwards = yStart - yEnd < 0
match rightwards, downwards with //add 20 to prevent issues in the case that the ports are directly on in line with one another
| true, true ->
Expand Down Expand Up @@ -346,7 +354,8 @@ let xyVerticesToSegments connId (xyVerticesList: XYPos list) =

/// Given the coordinates of two port locations that correspond
/// to the endpoints of a wire, as well as the orientation of the final port
/// this function returns a list of Segment(s).
/// this function returns a list of Segment(s).
/// The starting segment will always be from a Right Edge (and so in increasing X direction)
let makeInitialSegmentsList
(hostId : ConnectionId)
(startPos : XYPos)
Expand Down
3 changes: 2 additions & 1 deletion src/Renderer/DrawBlock/BusWireRoute.fs
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ let snapToNet (model: Model) (wireToRoute: Wire) : Wire =
let smartAutoroute (model: Model) (wire: Wire) : Wire =

let initialWire = (autoroute model wire)

// Snapping to Net only if model.SnapToNet toggled to be true
let snappedToNetWire =
match model.SnapToNet with
Expand All @@ -533,6 +533,7 @@ let smartAutoroute (model: Model) (wire: Wire) : Wire =
tryShiftHorizontalSeg maxCallsToShiftHorizontalSeg model intersectedBoxes snappedToNetWire
)
|> Option.defaultValue snappedToNetWire



//-----------------------------------------------------------------------------------------------------------//
Expand Down
1 change: 1 addition & 0 deletions src/Renderer/DrawBlock/BusWireRoutingHelpers.fs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ module Constants =
let overlapTolerance = 2.
/// corners with max length edge larger than this are not removed
let separateCaptureOverlap = 6. // Larger than as overlapTolerance, smaller than minSegmentSeparation
let minWireLengthToSeparate = 10. // prevents short wires being squiggly
let maxCornerSize = 100.
/// How close are segment extensions caused by corner removal allowed to
/// get to other elements? Maybe needs to be smaller than some otehr things for
Expand Down
5 changes: 2 additions & 3 deletions src/Renderer/DrawBlock/BusWireSeparate.fs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@ let makeLines (wiresToRoute: ConnectionId list) (ori: Orientation) (model: Model
/// Which segments in wires are included as Lines?
let selectSegments (wire: Wire) (orient: Orientation) (seg: Segment) =
let numSegs = wire.Segments.Length
ori = orient && seg.Index <> 0 && seg.Index <> numSegs - 1 && not (seg.IsZero()) //|| (segN -1).IsZero() || (segN 1).IsZero())
let wireLength = euclideanDistance wire.StartPos wire.EndPos
ori = orient && seg.Index <> 0 && seg.Index <> numSegs - 1 && not (seg.IsZero()) && wireLength > minWireLengthToSeparate

/// Lines coming from wire segments
/// Manually routed segments are considered fixed
Expand All @@ -169,7 +170,6 @@ let makeLines (wiresToRoute: ConnectionId list) (ori: Orientation) (model: Model
match wireIsRoutable, seg.Mode, seg.Index=2, seg.Index=segs.Length-3 with
| _, Manual , _ , _
| false, _, _, _ ->
//printf $"\n**Wire {pWire wire} is manual**\n"
FIXEDMANUALSEG
| _, _ , true , _ when segs[ 1 ].IsZero() ->
FIXEDSEG
Expand Down Expand Up @@ -881,7 +881,6 @@ let separateModelSegmentsOneOrientation (wires: ConnectionId list) (ori: Orienta
/// Perform complete wire segment separation and ordering for all orientations.
/// wiresToRoute: set of wires to have segments separated and ordered
let separateAndOrderModelSegments (wiresToRoute: ConnectionId list) (model: Model) : Model =

// Currently: separate all wires - not just those (in wiresToRoute) that
// have changed. This prevents unrouted segments from pinning new segments.
// TODO: see whetehr something better can be worked out,a nd whetehr routing segments
Expand Down

0 comments on commit 1fbc4fc

Please sign in to comment.