我有一个10x10的数组,我知道矩形的起点和终点在哪里。矩形可以是 1x3、2x2、3x2 等。
给定开始和结束坐标,我需要标记矩形在 10x10 数组中的位置。
示例一(正确):
左上角节点:[0, 1]
右下节点:[1,2]
|--0--| |--x--| |--x--| |--0--|
|--0--| |--x--| |--x--| |--0--|
|--0--| |--0--| |--0--| |--0--|
|--0--| |--0--| |--0--| |--0--|
示例二(不正确):
左上角节点:[1,3]
右下节点:[3,3]
电流输出:
|--0--| |--0--| |--0--| |--0--|
|--0--| |--0--| |--0--| |--x--|
|--0--| |--0--| |--0--| |--0--|
|--0--| |--0--| |--0--| |--0--|
所需输出:
|--0--| |--0--| |--0--| |--0--|
|--0--| |--0--| |--0--| |--x--|
|--0--| |--0--| |--0--| |--x--|
|--0--| |--0--| |--0--| |--x--|
这是我尝试过的:
$width = $lowerRightNode[1] - $upperLeftNode[1] + 1;
echo 'width: ' . $width .'<br/>';
for($i=$upperLeftNode[0]; $i < $upperLeftNode[0] + $width; $i++) {
for($z=$upperLeftNode[1]; $z <= $lowerRightNode[1]; $z++) {
$this->_grid[$i][$z] = 'x';
echo $i . ' ' . $z .'<br/>';
}
}
长风秋雁
桃花长相依