public void Handmaid2() { int x1 = -2; int x2 = 2; int y1 = 2; int y2 = 2; int s = 10; long __expected = 198L; long __result = new RectangularObstacle().countReachable(x1, x2, y1, y2, s); Assert.AreEqual(__expected, __result); }
public void Example0() { int x1 = -5; int x2 = 5; int y1 = 3; int y2 = 3; int s = 2; long __expected = 13L; long __result = new RectangularObstacle().countReachable(x1, x2, y1, y2, s); Assert.AreEqual(__expected, __result); }
public void Example4() { int x1 = -100; int x2 = 100; int y1 = 42; int y2 = 47; int s = 0; long __expected = 1L; long __result = new RectangularObstacle().countReachable(x1, x2, y1, y2, s); Assert.AreEqual(__expected, __result); }
public void Example3() { int x1 = 0; int x2 = 0; int y1 = 1; int y2 = 1; int s = 4; long __expected = 38L; long __result = new RectangularObstacle().countReachable(x1, x2, y1, y2, s); Assert.AreEqual(__expected, __result); }
public void Handmaid3() { int x1 = 1; int x2 = 1; int y1 = 3; int y2 = 3; int s = 4; long __expected = 40L; long __result = new RectangularObstacle().countReachable(x1, x2, y1, y2, s); Assert.AreEqual(__expected, __result); }
/// <summary> /// 检查仿真方形障碍物的尺寸和位置参数合法性 若超出场地则调整到场地内 /// </summary> /// <param name="obj">待检查尺寸和位置参数合法性的方形障碍物对象</param> public static void ParametersCheckingObstacle(ref RectangularObstacle obj) { Field f = Field.Instance(); // 确保障碍物长度不超过场地X方向长度 obj.LengthMm = (obj.LengthMm > f.FieldLengthXMm) ? f.FieldLengthXMm : obj.LengthMm; // 确保障碍物宽度不超过场地Z方向长度 obj.WidthMm = (obj.WidthMm > f.FieldLengthZMm) ? f.FieldLengthZMm : obj.WidthMm; // 根据新的位置坐标和尺寸参数更新碰撞检测参数即4个顶点构成的列表 obj.CalculateCollisionDetectionParas(); int tmp = 0; int minX = (int)UrwpgSimHelper.Min(obj.PolygonVertices[0].X, obj.PolygonVertices[1].X, obj.PolygonVertices[2].X, obj.PolygonVertices[3].X, ref tmp); if (minX < Field.Instance().LeftMm) { // 出了左边界 obj.PositionMm.X += Field.Instance().LeftMm - minX; // 右移超出的距离 } else {// 没出左边界 int maxX = (int)UrwpgSimHelper.Max(obj.PolygonVertices[0].X, obj.PolygonVertices[1].X, obj.PolygonVertices[2].X, obj.PolygonVertices[3].X, ref tmp); if (maxX > Field.Instance().RightMm) { // 出了右边界 obj.PositionMm.X -= maxX - Field.Instance().RightMm; // 左移超出的距离 } } int minZ = (int)UrwpgSimHelper.Min(obj.PolygonVertices[0].Z, obj.PolygonVertices[1].Z, obj.PolygonVertices[2].Z, obj.PolygonVertices[3].Z, ref tmp); if (minZ < Field.Instance().TopMm) { // 出了上边界 obj.PositionMm.Z += Field.Instance().TopMm - minZ; // 下移超出的距离 } else {// 没出上边界 int maxZ = (int)UrwpgSimHelper.Max(obj.PolygonVertices[0].Z, obj.PolygonVertices[1].Z, obj.PolygonVertices[2].Z, obj.PolygonVertices[3].Z, ref tmp); if (maxZ > Field.Instance().BottomMm) { // 出了下边界 obj.PositionMm.Z -= maxZ - Field.Instance().BottomMm; // 上移超出的距离 } } }