base/rect
사각형. (좌상 위치 + 크기, 원본 base/rect.js)
- 원본의 width, min, center, left 같은 프로퍼티는 get_..., set_... 함수로 옮겼다.
- intersects 는 러스트 판에서 먼저 만든 것으로 변이 닿기만 하면 겹치지 않는 것으로 본다. 원본 overlaps 는 변이 닿아도 겹친 것으로 보고, intersection 이 이것을 쓴다.
Rectangle. (top-left position + size, the original base/rect.js)
- The original's properties like width, min, center and left became get_... and set_... functions.
- intersects was made first in the Rust version and counts edges that merely touch as not overlapping. The original overlaps counts touching edges as overlapping, and intersection uses it.
Rectstruct traits Clone, Copy, Debug, Default, PartialEq, GeometryKeyValue, ToReflectValue
사각형. (왼쪽 위 위치와 크기를 공개 필드로 둔 Copy 값, y 는 아래로 커진다)
Rectangle. (a Copy value with the top-left position and size as public fields, y grows downward)
use vanilla::{Rect, Vector2};
let panel = Rect::create(0.0, 0.0, 100.0, 50.0);
let button = Rect::create(80.0, 40.0, 40.0, 20.0);
assert!(panel.contains(Vector2::create(10.0, 10.0)));
assert!(panel.overlaps(&button));
let overlap = panel.intersection(&button);
assert_eq!(overlap, Rect::create(80.0, 40.0, 20.0, 10.0));
let bounds = panel.union(&button);
assert_eq!((bounds.get_right(), bounds.get_bottom()), (120.0, 60.0));생성.
Constructor.
- xf64
- 왼쪽 x.Left x.
- yf64
- 위 y.Top y.
- widthf64
- 너비.Width.
- heightf64
- 높이.Height.
반환ReturnsRect 만든 사각형.The created rectangle.
짝Counterpart: vanilla.js Rect.create
빈 사각형.
Empty rectangle.
반환ReturnsRect 위치와 크기가 모두 0 인 사각형.A rectangle with position and size all 0.
짝Counterpart: vanilla.js Rect.zero
위치와 크기를 성분별로 범위 제한.
Clamps position and size per component.
- valueRect
- 제한할 사각형.Rectangle to clamp.
- minimumRect
- 위치와 크기의 최소값. (position, size 를 따로 본다)Minimum of position and size. (position and size are checked separately)
- maximumRect
- 위치와 크기의 최대값. (position, size 를 따로 본다)Maximum of position and size. (position and size are checked separately)
반환ReturnsRect 위치와 크기를 성분별로 자른 새 사각형.A new rectangle with position and size clamped per component.
짝Counterpart: vanilla.js Rect.clamp
use vanilla::Rect;
let minimum = Rect::create(0.0, 0.0, 10.0, 10.0);
let maximum = Rect::create(100.0, 100.0, 200.0, 200.0);
let clamped = Rect::clamp(Rect::create(-5.0, 50.0, 500.0, 1.0), minimum, maximum);
assert_eq!(clamped, Rect::create(0.0, 50.0, 200.0, 10.0));크기. (x 가 너비, y 가 높이)
Size. (x is the width, y the height)
반환ReturnsVector2
짝Counterpart: vanilla.js Rect.size
모든 값이 0 인지.
Whether every value is 0.
반환Returnsbool 위치와 크기의 네 값이 모두 0 이면 true.true if all four values of position and size are 0.
짝Counterpart: vanilla.js Rect.isZero
너비 설정.
Sets the width.
- widthf64
- 새 너비. (왼쪽 위는 그대로)New width. (the top left stays)
짝Counterpart: vanilla.js Rect.width
높이 설정.
Sets the height.
- heightf64
- 새 높이. (왼쪽 위는 그대로)New height. (the top left stays)
짝Counterpart: vanilla.js Rect.height
왼쪽 위. (위치)
Top left. (the position)
반환ReturnsVector2 왼쪽 위 점.Top-left point.
짝Counterpart: vanilla.js Rect.min
왼쪽 위 설정. (오른쪽 아래는 그대로 두고 크기를 바꾼다)
Sets the top left. (keeps the bottom right and changes the size)
- minimumVector2
- 새 왼쪽 위 점.New top-left point.
짝Counterpart: vanilla.js Rect.min
use vanilla::{Rect, Vector2};
let mut rect = Rect::create(10.0, 20.0, 100.0, 50.0);
rect.set_min(Vector2::zero());
assert_eq!(rect, Rect::create(0.0, 0.0, 110.0, 70.0));오른쪽 아래. (위치 + 크기)
Bottom right. (position + size)
반환ReturnsVector2 오른쪽 아래 점.Bottom-right point.
짝Counterpart: vanilla.js Rect.max
오른쪽 아래 설정. (위치는 그대로 두고 크기를 바꾼다)
Sets the bottom right. (keeps the position and changes the size)
- maximumVector2
- 새 오른쪽 아래 점.New bottom-right point.
짝Counterpart: vanilla.js Rect.max
가운데 설정. (크기는 그대로 두고 옮긴다)
Sets the center. (moves it, keeping the size)
- centerVector2
- 새 가운데 점.New center point.
짝Counterpart: vanilla.js Rect.center
왼쪽 x 설정. (크기는 그대로 두고 옮긴다)
Sets the left x. (moves it, keeping the size)
- leftf64
- 새 왼쪽 x.New left x.
짝Counterpart: vanilla.js Rect.left
위 y 설정. (크기는 그대로 두고 옮긴다)
Sets the top y. (moves it, keeping the size)
- topf64
- 새 위 y.New top y.
짝Counterpart: vanilla.js Rect.top
오른쪽 x.
Right x.
반환Returnsf64 오른쪽 x. (왼쪽 x + 너비)Right x. (left x + width)
짝Counterpart: vanilla.js Rect.right
오른쪽 x 설정. (크기는 그대로 두고 옮긴다)
Sets the right x. (moves it, keeping the size)
- rightf64
- 새 오른쪽 x.New right x.
짝Counterpart: vanilla.js Rect.right
아래 y.
Bottom y.
반환Returnsf64 아래 y. (위 y + 높이)Bottom y. (top y + height)
짝Counterpart: vanilla.js Rect.bottom
아래 y 설정. (크기는 그대로 두고 옮긴다)
Sets the bottom y. (moves it, keeping the size)
- bottomf64
- 새 아래 y.New bottom y.
짝Counterpart: vanilla.js Rect.bottom
점이 안에 있는지.
Whether a point is inside.
- pointVector2
- 판정할 점.Point to test.
반환Returnsbool 점이 안이나 변 위에 있으면 true.true if the point is inside or on an edge.
짝Counterpart: vanilla.js Rect.contains
다른 사각형과 겹치는지.
Whether it overlaps another rectangle.
- other&Rect
- 겹침을 볼 사각형.Rectangle to check overlap with.
반환Returnsbool 안쪽이 겹치면 true. 변이 닿기만 하면 false.true if the insides overlap. false if the edges merely touch.
짝Counterpart: vanilla.js Rect.intersects
use vanilla::Rect;
let left = Rect::create(0.0, 0.0, 10.0, 10.0);
let touching = Rect::create(10.0, 0.0, 5.0, 5.0);
assert!(!left.intersects(&touching));
assert!(left.overlaps(&touching));다른 사각형과 겹치는지. (원본 overlaps, 변이 닿기만 해도 겹친 것으로 본다)
Whether it overlaps another rectangle. (the original overlaps, counts merely touching edges as overlapping)
- other&Rect
- 겹침을 볼 사각형.Rectangle to check overlap with.
반환Returnsbool 겹치거나 변이 닿으면 true.true if overlapping or the edges touch.
짝Counterpart: vanilla.js Rect.overlaps
겹친 영역. (겹치지 않으면 빈 사각형, 변만 닿으면 너비나 높이가 0)
Overlapping area. (an empty rectangle if not overlapping, width or height 0 if only the edges touch)
- other&Rect
- 겹친 영역을 구할 사각형.Rectangle to compute the overlapping area with.
반환ReturnsRect 겹친 사각형. 겹치지 않으면 Rect::zero(), 변만 닿으면 너비나 높이가 0 인 사각형.The overlapping rectangle. Rect::zero() if not overlapping, a rectangle with width or height 0 if only the edges touch.
짝Counterpart: vanilla.js Rect.intersection
use vanilla::Rect;
let first = Rect::create(0.0, 0.0, 10.0, 10.0);
assert_eq!(first.intersection(&Rect::create(5.0, 5.0, 10.0, 10.0)), Rect::create(5.0, 5.0, 5.0, 5.0));
assert_eq!(first.intersection(&Rect::create(10.0, 0.0, 5.0, 5.0)), Rect::create(10.0, 0.0, 0.0, 5.0));
assert!(first.intersection(&Rect::create(20.0, 20.0, 5.0, 5.0)).is_zero());둘을 다 덮는 가장 작은 사각형.
The smallest rectangle covering both.
- other&Rect
- 같이 덮을 사각형.Rectangle to cover together.
반환ReturnsRect 둘을 다 덮는 가장 작은 사각형.The smallest rectangle covering both.
짝Counterpart: vanilla.js Rect.union