public void match()

in kit/src/main/java/com/oracle/javafx/scenebuilder/kit/editor/panel/content/guides/MovingGuideController.java [102:191]


    public void match(Bounds targetBounds) {
        List<HorizontalSegment> horizontalMatchingLines;
        List<VerticalSegment> verticalMatchingLines;
        boolean matchedHorizontally = false;
        boolean matchedVertically = false;
        
        // Match horizontal center line of targetBounds
        horizontalMatchingLines 
                = horizontalLineIndex.matchCenter(targetBounds, MATCH_DISTANCE);
        if (horizontalMatchingLines.isEmpty() == false) {
            matchedHorizontally = true;
            final HorizontalSegment line = horizontalMatchingLines.get(0);
            assert MathUtils.equals(line.getY1(), line.getY2());
            final double targetMinY = targetBounds.getMinY();
            final double targetMaxY = targetBounds.getMaxY();
            final double targetMidY = (targetMinY + targetMaxY) / 2.0;
            suggestedDY = line.getY1() - targetMidY;
        }
        
        // Match north boundary of targetBounds
        if (matchedHorizontally == false) {
            horizontalMatchingLines 
                    = horizontalLineIndex.matchNorth(targetBounds, MATCH_DISTANCE);
            if (horizontalMatchingLines.isEmpty() == false) {
                matchedHorizontally = true;
                final HorizontalSegment line = horizontalMatchingLines.get(0);
                assert MathUtils.equals(line.getY1(), line.getY2());
                suggestedDY = line.getY1() - targetBounds.getMinY();
            }
        }
        
        // Match south boundary of targetBounds
        if (matchedHorizontally == false) {
            horizontalMatchingLines 
                    = horizontalLineIndex.matchSouth(targetBounds, MATCH_DISTANCE);
            if (horizontalMatchingLines.isEmpty() == false) {
                matchedHorizontally = true;
                final HorizontalSegment line = horizontalMatchingLines.get(0);
                assert MathUtils.equals(line.getY1(), line.getY2());
                suggestedDY = line.getY1() - targetBounds.getMaxY();
            }
        }
        
        if (matchedHorizontally == false) {
            suggestedDY = 0.0;
        }
        
        // Match vertical center line of targetBounds
        verticalMatchingLines 
                = verticalLineIndex.matchCenter(targetBounds, MATCH_DISTANCE);
        if (verticalMatchingLines.isEmpty() == false) {
            matchedVertically = true;
            final VerticalSegment line = verticalMatchingLines.get(0);
            assert MathUtils.equals(line.getX1(), line.getX2());
            final double targetMinX = targetBounds.getMinX();
            final double targetMaxX = targetBounds.getMaxX();
            final double targetMidX = (targetMinX + targetMaxX) / 2.0;
            suggestedDX = line.getX1() - targetMidX;
        }
        
        // Match west boundary of targetBounds
        if (matchedVertically == false) {
            verticalMatchingLines 
                    = verticalLineIndex.matchWest(targetBounds, MATCH_DISTANCE);
            if (verticalMatchingLines.isEmpty() == false) {
                matchedVertically = true;
                final VerticalSegment line = verticalMatchingLines.get(0);
                assert MathUtils.equals(line.getX1(), line.getX2());
                suggestedDX = line.getX1() - targetBounds.getMinX();
            }
        }
        
        // Match east boundary of targetBounds
        if (matchedVertically == false) {
            verticalMatchingLines 
                    = verticalLineIndex.matchEast(targetBounds, MATCH_DISTANCE);
            if (verticalMatchingLines.isEmpty() == false) {
                matchedVertically = true;
                final VerticalSegment line = verticalMatchingLines.get(0);
                assert MathUtils.equals(line.getX1(), line.getX2());
                suggestedDX = line.getX1() - targetBounds.getMaxX();
            }
        }
        
        if (matchedVertically == false) {
            suggestedDX = 0.0;
        }
        
        renderer.setLines(horizontalMatchingLines, verticalMatchingLines);
    }