RectangleInteger
通用的介绍见: K维立方体
RectangleInteger表示整数构成的矩形,实现了IKCube<Vector2Int>
示例
https://github.com/VMware233/VMFramework/blob/3b3851401db5d97b9954887bd089af57e3290eb6/Assets/Examples/Core/KSet/RectangleIntegerDemo.cs
using UnityEngine;
using VMFramework.Core;
namespace VMFramework.Examples
{
public sealed class RectangleIntegerDemo : MonoBehaviour
{
private void Start()
{
// å建ä¸ä¸ª[0, 2]x[0, 3]çæ´æ°ç©å½¢ï¼ç¨å°ºå¯¸åå§å
// è¿éä¹å·æ¯ç¬å¡å°ç§¯ï¼ç¸å½äºä¸ä¸ªä»åæ (0, 0)å°(2, 3)çç©å½¢
// Create a rectangle with size [0, 2]x[0, 3] using dimensions
// The multiplication symbol is the Cartesian product,
// which means a rectangle from the coordinate (0, 0) to (2, 3)
var a = new RectangleInteger(new Vector2Int(3, 4));
// å建ä¸ä¸ª[2, 3]x[5, 6]çæ´æ°ç©å½¢ï¼ç¨æå°å¼åæå¤§å¼åå§å
// Create a rectangle with minimum value (2, 3) and maximum value (5, 6),
// which is equivalent to [2, 3]x[5, 6]
var b = new RectangleInteger(new Vector2Int(2, 3), new Vector2Int(5, 6));
// å¤å¶ä¸ä¸ªæ´æ°ç©å½¢
// Copy a rectangle
var c = new RectangleInteger(a);
// ç¨RectangleInteger.unitå¿«éå建ä¸ä¸ª[0, 1]x[0, 1]çæ´æ°ç©å½¢
// Create a rectangle with size [0, 1]x[0, 1] using RectangleInteger.unit
var d = RectangleInteger.unit;
// [0, 2]x[0, 3]ä¸(3, 4)ç¸å ï¼å¾å°ä¸ä¸ª[3, 6]x[3, 7]çæ´æ°ç©å½¢
// Add a vector to a rectangle to get a new rectangle with shifted coordinates
var e = a + new Vector2Int(3, 4);
// [3, 6]x[3, 7]å è´å·ï¼å¾å°ä¸ä¸ª[-6, -3]x[-7, -3]çæ´æ°ç©å½¢
// ä¸ç¸å¯¹äºåæ åç¹ä½éå䏿 ·
// Negate a rectangle to get a new rectangle with negated coordinates,
// which is equivalent to mirroring it around the coordinate origin
var f = -e;
// å建ä¸ä¸ª[0, 2]x[0, 3]çæ´æ°ç©å½¢ï¼å³ä»åæ (0, 0)å°(2, 3)çç©å½¢
// Create a [0, 2]x[0, 3] rectangle with minimum value (0, 0) and maximum value (2, 3)
var rangeX = RangeInteger.unit * 2;
var rangeY = RangeInteger.unit * 3;
var rectangle = rangeX * rangeY;
// è·å[0, 2]x[0, 3]è¿ä¸ªç©å½¢ä¸ææè¾¹çä¸çæ´æ°ç¹
// Get all integer points on the boundaries of the [0, 2]x[0, 3] rectangle
foreach (var point in rectangle.GetAllBoundaryPoints())
{
Debug.Log(point);
}
// è·å[0, 2]x[0, 3]è¿ä¸ªç©å½¢å
çæææ´æ°ç¹ï¼å
æ¬è¾¹çï¼
// Get all integer points inside the [0, 2]x[0, 3] rectangle, including the boundaries
foreach (var point in rectangle.GetAllPoints())
{
Debug.Log(point);
}
// ä»[0, 2]x[0, 3]è¿ä¸ªç©å½¢å
éæºå5个ä¸åçéæºç¹ï¼å
æ¬è¾¹çï¼
// Get 5 unique random points inside the [0, 2]x[0, 3] rectangle, including the boundaries
foreach (var point in rectangle.GetRandomUniquePoints(5))
{
Debug.Log(point);
}
}
}
}
最后更新于
这有帮助吗?