public class RoundRect {
float width;
float height;
float r;
float fullWidth => width + r * 2;
float fullHeight => height + r * 2;
float radWidth => width + r;
float radHeight => height + r;
public float perimeter => (radWidth * 2 + radHeight * 2);
static Exception pointOut = new Exception("Point out of the rectangle");
public RoundRect(float width, float height, float radius) {
if (width < radius || height < radius) { throw new Exception("Radius should be less than dimensions"); }
this.width = width - 2*radius;
this.height = height - 2*radius;
r = radius;
}
public float CornerByAxisPoint(float p, bool positive) {
if (Mathf.Abs(p) > r) {
Debug.Log("Invalid input p: " + p + $". Must be within [-{r}, {r}]");
p = Mathf.Clamp(p, -r, r);
}
return Mathf.Sqrt(r * r - p * p) * (positive ? 1 : -1);
}
public Vector2 GetPointOnBase(float x, bool topSide) {
if (x width) { return new Vector2(x+(topSide ? 0 : -width*2-r), CornerByAxisPoint(x-width+(topSide ? 0 : -r), topSide)); }
else throw pointOut;
}
public Vector2 GetPointOnLegs(float y, bool rightSide) {
if (y height) { return new Vector2(CornerByAxisPoint(y-height, rightSide)+(rightSide ? -r : r), (rightSide ? -y : y)); }
else throw pointOut;
}
public Vector2 GetPoint(float p) {
Debug.Log(p);
if (p radWidth && p radWidth + radHeight && p radWidth*2 + radHeight && p GetPoint(Mathf.Lerp(0f, perimeter, t));
public static Vector3 OnGround(Vector2 point) {
return new Vector3(point.x, 0, point.y);
}
}
Я использую GetPointOnLegs для получения позиций слева и справа, GetPointOnBase — для получения позиций сверху вниз. Это дает мне странные результаты по углам и время от времени неверный ввод p (сравнение плавающих точек).
< /p>
Я использовал эпсилон, и неверный квадратный корень, казалось бы, больше не был проблемой, но основная проблема осталась: интерполяция по углам не очень хорошая, поэтому я вернул его обратно. Все точки должны быть расположены ровно, без странных пробелов.
[code] public class RoundRect { float width; float height; float r; float fullWidth => width + r * 2; float fullHeight => height + r * 2; float radWidth => width + r; float radHeight => height + r; public float perimeter => (radWidth * 2 + radHeight * 2); static Exception pointOut = new Exception("Point out of the rectangle");
public RoundRect(float width, float height, float radius) { if (width < radius || height < radius) { throw new Exception("Radius should be less than dimensions"); } this.width = width - 2*radius; this.height = height - 2*radius; r = radius; } public float CornerByAxisPoint(float p, bool positive) { if (Mathf.Abs(p) > r) { Debug.Log("Invalid input p: " + p + $". Must be within [-{r}, {r}]"); p = Mathf.Clamp(p, -r, r); } return Mathf.Sqrt(r * r - p * p) * (positive ? 1 : -1); } public Vector2 GetPointOnBase(float x, bool topSide) { if (x width) { return new Vector2(x+(topSide ? 0 : -width*2-r), CornerByAxisPoint(x-width+(topSide ? 0 : -r), topSide)); } else throw pointOut; } public Vector2 GetPointOnLegs(float y, bool rightSide) { if (y height) { return new Vector2(CornerByAxisPoint(y-height, rightSide)+(rightSide ? -r : r), (rightSide ? -y : y)); } else throw pointOut; } public Vector2 GetPoint(float p) { Debug.Log(p); if (p radWidth && p radWidth + radHeight && p radWidth*2 + radHeight && p GetPoint(Mathf.Lerp(0f, perimeter, t));
public static Vector3 OnGround(Vector2 point) { return new Vector3(point.x, 0, point.y); } } [/code] Я использую GetPointOnLegs для получения позиций слева и справа, GetPointOnBase — для получения позиций сверху вниз. Это дает мне странные результаты по углам и время от времени неверный ввод p (сравнение плавающих точек). [img]https://i.sstatic.net/9ZbA1XKN.png[/img] < /p> Я использовал эпсилон, и неверный квадратный корень, казалось бы, больше не был проблемой, но основная проблема осталась: интерполяция по углам не очень хорошая, поэтому я вернул его обратно. Все точки должны быть расположены ровно, без странных пробелов.
Стандарт C++ гласит, что возврат ссылки на локальную переменную (в стеке) является неопределенным поведением, так почему же многие (если не все) текущие компиляторы только выдают предупреждение об этом ?
Я хочу отобразить изображение из массива в ноутбуке Jupyter (встроенный) в коде Visual Studio.
Я запускаю Windows 11 на высоком мониторе DPI с масштабированием на 150%.
Pixels не оказывается резким в записной книжке. Я хочу масштабировать целое...
Обзор. Я создаю шахматную игру с использованием Swing (Java), и при создании шаблона шахматной доски я столкнулся с проблемой, когда прямоугольники, которые я создал с помощью drawRect исчезнет вскоре после запуска окна.