src/main/java/org/fit/layout/cssbox/BoxNode.java
public boolean visuallyEncloses(BoxNode childNode)
    {
        int cx1 = childNode.getVisualBounds().getX1();
        int cy1 = childNode.getVisualBounds().getY1();
        int cx2 = childNode.getVisualBounds().getX2();
        int cy2 = childNode.getVisualBounds().getY2();
        int px1 = getVisualBounds().getX1();
        int py1 = getVisualBounds().getY1();
        int px2 = getVisualBounds().getX2();
        int py2 = getVisualBounds().getY2();
        
        /*if (this.toString().contains("pBody") && childNode.toString().contains("mediawiki"))
            System.out.println(childNode + " inside of " + this);
        if (childNode.toString().contains("www-lupa-cz") && this.toString().contains("[page]"))
            System.out.println(childNode + " inside of " + this);*/
        /*if (this.getOrder() == 70 && childNode.getOrder() == 74)
            System.out.println("jo!");*/
        
        
        //check how many corners of the child are inside enough (with some overlap)
        int ccnt = 0;
        if (cx1 >= px1 + OVERLAP && cx1 <= px2 - OVERLAP &&
            cy1 >= py1 + OVERLAP && cy1 <= py2 - OVERLAP) ccnt++; //top left
        if (cx2 >= px1 + OVERLAP && cx2 <= px2 - OVERLAP &&
            cy1 >= py1 + OVERLAP && cy1 <= py2 - OVERLAP) ccnt++; //top right
        if (cx1 >= px1 + OVERLAP && cx1 <= px2 - OVERLAP &&
            cy2 >= py1 + OVERLAP && cy2 <= py2 - OVERLAP) ccnt++; //bottom left
        if (cx2 >= px1 + OVERLAP && cx2 <= px2 - OVERLAP &&
            cy2 >= py1 + OVERLAP && cy2 <= py2 - OVERLAP) ccnt++; //bottom right
        //check how many corners of the child are inside the parent exactly
        int xcnt = 0;
        if (cx1 >= px1 && cx1 <= px2 &&
            cy1 >= py1 && cy1 <= py2) xcnt++; //top left
        if (cx2 >= px1 && cx2 <= px2 &&
            cy1 >= py1 && cy1 <= py2) xcnt++; //top right
        if (cx1 >= px1 && cx1 <= px2 &&
            cy2 >= py1 && cy2 <= py2) xcnt++; //bottom left
        if (cx2 >= px1 && cx2 <= px2 &&
            cy2 >= py1 && cy2 <= py2) xcnt++; //bottom right
        //and reverse direction - how many corners of the parent are inside of the child
        int rxcnt = 0;
        if (px1 >= cx1 && px1 <= cx2 &&
            py1 >= cy1 && py1 <= cy2) rxcnt++; //top left
        if (px2 >= cx1 && px2 <= cx2 &&
            py1 >= cy1 && py1 <= cy2) rxcnt++; //top right
        if (px1 >= cx1 && px1 <= cx2 &&
            py2 >= cy1 && py2 <= cy2) rxcnt++; //bottom left
        if (px2 >= cx1 && px2 <= cx2 &&
            py2 >= cy1 && py2 <= cy2) rxcnt++; //bottom right
        //shared areas
        int shared = getVisualBounds().intersection(childNode.getVisualBounds()).getArea();
        double sharedperc = (double) shared / childNode.getBounds().getArea();
        
        //no overlap
        if (xcnt == 0)
        	return false;
        //fully overlapping or over a corner - the order decides
        else if ((cx1 == px1 && cy1 == py1 && cx2 == px2 && cy2 == py2) //full overlap
        	     || (ccnt == 1 && xcnt <= 1)) //over a corner
        	return this.getOrder() < childNode.getOrder() && sharedperc >= AREAP;
        //fully inside
        else if (xcnt == 4)
            return true;
        //partly inside (at least two corners)
        else if (xcnt >= 2)
        {
            if (rxcnt == 4) //reverse relation - the child contains the parent
                return false;
            else //child partly inside the parent
                return this.getOrder() < childNode.getOrder() && sharedperc >= AREAP;
        }
        //not inside
        else
            return false;
    }
public boolean visuallyEncloses(BoxNode childNode)
    {
        int cx1 = childNode.getVisualBounds().getX1();
        int cy1 = childNode.getVisualBounds().getY1();
        int cx2 = childNode.getVisualBounds().getX2();
        int cy2 = childNode.getVisualBounds().getY2();
        int px1 = getVisualBounds().getX1();
        int py1 = getVisualBounds().getY1();
        int px2 = getVisualBounds().getX2();
        int py2 = getVisualBounds().getY2();
        
        /*if (this.toString().contains("pBody") && childNode.toString().contains("mediawiki"))
            System.out.println(childNode + " inside of " + this);
        if (childNode.toString().contains("www-lupa-cz") && this.toString().contains("[page]"))
            System.out.println(childNode + " inside of " + this);*/
        /*if (this.getOrder() == 70 && childNode.getOrder() == 74)
            System.out.println("jo!");*/
        
        
        //check how many corners of the child are inside enough (with some overlap)
        int ccnt = 0;
        if (cx1 >= px1 + OVERLAP && cx1 <= px2 - OVERLAP &&
            cy1 >= py1 + OVERLAP && cy1 <= py2 - OVERLAP) ccnt++; //top left
        if (cx2 >= px1 + OVERLAP && cx2 <= px2 - OVERLAP &&
            cy1 >= py1 + OVERLAP && cy1 <= py2 - OVERLAP) ccnt++; //top right
        if (cx1 >= px1 + OVERLAP && cx1 <= px2 - OVERLAP &&
            cy2 >= py1 + OVERLAP && cy2 <= py2 - OVERLAP) ccnt++; //bottom left
        if (cx2 >= px1 + OVERLAP && cx2 <= px2 - OVERLAP &&
            cy2 >= py1 + OVERLAP && cy2 <= py2 - OVERLAP) ccnt++; //bottom right
        //check how many corners of the child are inside the parent exactly
        int xcnt = 0;
        if (cx1 >= px1 && cx1 <= px2 &&
            cy1 >= py1 && cy1 <= py2) xcnt++; //top left
        if (cx2 >= px1 && cx2 <= px2 &&
            cy1 >= py1 && cy1 <= py2) xcnt++; //top right
        if (cx1 >= px1 && cx1 <= px2 &&
            cy2 >= py1 && cy2 <= py2) xcnt++; //bottom left
        if (cx2 >= px1 && cx2 <= px2 &&
            cy2 >= py1 && cy2 <= py2) xcnt++; //bottom right
        //and reverse direction - how many corners of the parent are inside of the child
        int rxcnt = 0;
        if (px1 >= cx1 && px1 <= cx2 &&
            py1 >= cy1 && py1 <= cy2) rxcnt++; //top left
        if (px2 >= cx1 && px2 <= cx2 &&
            py1 >= cy1 && py1 <= cy2) rxcnt++; //top right
        if (px1 >= cx1 && px1 <= cx2 &&
            py2 >= cy1 && py2 <= cy2) rxcnt++; //bottom left
        if (px2 >= cx1 && px2 <= cx2 &&
            py2 >= cy1 && py2 <= cy2) rxcnt++; //bottom right
        //shared areas
        int shared = getVisualBounds().intersection(childNode.getVisualBounds()).getArea();
        double sharedperc = (double) shared / childNode.getBounds().getArea();
        
        //no overlap
        if (xcnt == 0)
        	return false;
        //fully overlapping or over a corner - the order decides
        else if ((cx1 == px1 && cy1 == py1 && cx2 == px2 && cy2 == py2) //full overlap
        	     || (ccnt == 1 && xcnt <= 1)) //over a corner
        	return this.getOrder() < childNode.getOrder() && sharedperc >= AREAP;
        //fully inside
        else if (xcnt == 4)
            return true;
        //partly inside (at least two corners)
        else if (xcnt >= 2)
        {
            if (rxcnt == 4) //reverse relation - the child contains the parent
                return false;
            else //child partly inside the parent
                return this.getOrder() < childNode.getOrder() && sharedperc >= AREAP;
        }
        //not inside
        else
            return false;
    }
Checks if another node is located inside the visual bounds of this box.
@param childNode the node to check
@return <code>true</code> if the child node is completely inside this node, <code>false</code> otherwise