用于计算2箱侧的函数或公式

时间:2016-07-30 15:36:56

标签: math

我刚刚来到这里,我想问一个公式来计算如果内联与否则获取方框。

enter image description here enter image description here

我需要一个公式来知道box2或box1是否在同一侧

1 个答案:

答案 0 :(得分:0)

如果我理解你的问题,你需要一种方法,检查两个盒子(矩形)是否对齐(左或右)?这是一个非常快速的解决方案:

public enum Side {
    Left,
    Right
}

public bool CheckIfAligned(Rect box1, Rect box2, Side side) {
    if(side == Side.Left)
        return box1.Location.X == box2.Location.X;
    else // side == Side.Right
        return box1.Location.X + box1.Width == box2.Location.X + box2.Width;
}