package com.gezi;


import java.util.List;

/**
 * 作者:是一个鸽子啊
 * 时间:2020/06/07
 */
public class BaseBoxChoose {
    /**
     * 当前飞机的初始大小
     */
    protected FlyBlock root;
    /**
     * 当前装箱的飞机
     */
    protected Fly fly;

    protected List<Box> boxList;

    public BaseBoxChoose(Fly fly, List<Box> boxList) {
        this.fly = fly;
        this.boxList = boxList;
    }

    /**
     * 给箱子安排位置
     */
    public void fit() {

    }

    /**
     * 分解车厢面积
     *
     * @param flyBlock
     * @param length
     * @param width
     */
    protected FlyBlock splitCarBlock(FlyBlock flyBlock, int length, int width) {
        //当前位置被放了箱子了
        flyBlock.setUsed(true);
        //箱子右边的大小
        FlyBlock rightFlyBlock = new FlyBlock(flyBlock.getX() + length, flyBlock.getY(), flyBlock.getLength() - length, width);
        //箱子下边的大小
        FlyBlock downFlyBlock = new FlyBlock(flyBlock.getX(), flyBlock.getY() + width, flyBlock.getLength(), flyBlock.getWidth() - width);
        //设置当前箱子的右边及下遍的大小
        flyBlock.setRight(rightFlyBlock);
        flyBlock.setDown(downFlyBlock);
        return flyBlock;
    }

    /**
     * 给箱子找个合适的位置
     * 没有地方可以放,则返回 null
     *
     * @param root   当前剩余的位置
     * @param length
     * @param width
     */
    protected FlyBlock findCarBlock(FlyBlock root, int length, int width, Box box) {
        /**
         * 判断是否被使用了
         */
        if (root.isUsed()) {
            //如果被使用了。就看看他的右边或者下边是否还有位置
            FlyBlock flyBlock = findCarBlock(root.getRight(), length, width, box);
            if (flyBlock != null) {
                return flyBlock;
            }
            return findCarBlock(root.getDown(), length, width, box);
        } else if ((length <= root.getLength() && (width <= root.getWidth()))) {
            //就返回当前位置可以放箱子,
            return root;
        } else if ((width <= root.getLength() && (length <= root.getWidth()))) {
            //旋转一下箱子
            box.setWidth(length);
            box.setLength(width);
            return root;
        } else {
            //没法放
            return null;
        }
    }
}
最近下载更多
lironggang  LV38 2023年3月26日
最代码官方  LV167 2020年6月9日
最近浏览更多
lironggang  LV38 2023年3月26日
libing1860 2022年5月30日
暂无贡献等级
murat7 2022年5月7日
暂无贡献等级
1057148049  LV11 2022年2月8日
woaini12788  LV7 2022年1月14日
my1999  LV2 2021年12月20日
xp95323  LV14 2021年11月9日
侯国强  LV4 2021年11月8日
playplaycode  LV3 2021年11月3日
lewis365  LV2 2021年8月27日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友