vanilladocs
vanillapunch.com
API / base/rect

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

짝Counterpart: vanilla.js Rect소스source

사각형. (왼쪽 위 위치와 크기를 공개 필드로 둔 Copy 값, y 는 아래로 커진다)

Rectangle. (a Copy value with the top-left position and size as public fields, y grows downward)

예제Example점과 영역 검사, 겹친 영역 구하기Test points and areas, find the overlapping area
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));
정적staticpub const fn create(x: f64, y: f64, width: f64, height: f64) -> Rect#0.3.2 부터since 0.3.2소스source

생성.

Constructor.

xf64
왼쪽 x.Left x.
yf64
위 y.Top y.
widthf64
너비.Width.
heightf64
높이.Height.

반환ReturnsRect 만든 사각형.The created rectangle.

짝Counterpart: vanilla.js Rect.create

정적staticpub const fn zero() -> Rect#0.3.2 부터since 0.3.2소스source

빈 사각형.

Empty rectangle.

반환ReturnsRect 위치와 크기가 모두 0 인 사각형.A rectangle with position and size all 0.

짝Counterpart: vanilla.js Rect.zero

정적staticpub fn clamp(value: Rect, minimum: Rect, maximum: Rect) -> Rect#0.4.0 부터since 0.4.0소스source

위치와 크기를 성분별로 범위 제한.

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

예제Example위치는 0 ~ 100, 크기는 10 ~ 200 으로 자르기Clamp the position to 0 ~ 100 and the size to 10 ~ 200
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));
필드fieldpub position: Vector2#0.3.2 부터since 0.3.2소스source

왼쪽 위 위치.

Top-left position.

반환ReturnsVector2

짝Counterpart: vanilla.js Rect.position

필드fieldpub size: Vector2#0.3.2 부터since 0.3.2소스source

크기. (x 가 너비, y 가 높이)

Size. (x is the width, y the height)

반환ReturnsVector2

짝Counterpart: vanilla.js Rect.size

메서드methodpub fn is_zero(&self) -> bool#0.3.2 부터since 0.3.2소스source

모든 값이 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

메서드methodpub fn get_width(&self) -> f64#0.3.2 부터since 0.3.2소스source

너비.

Width.

반환Returnsf64 너비. (size.x)Width. (size.x)

짝Counterpart: vanilla.js Rect.width

메서드methodpub fn get_height(&self) -> f64#0.3.2 부터since 0.3.2소스source

높이.

Height.

반환Returnsf64 높이. (size.y)Height. (size.y)

짝Counterpart: vanilla.js Rect.height

메서드methodpub fn set_width(&mut self, width: f64)#0.4.0 부터since 0.4.0소스source

너비 설정.

Sets the width.

widthf64
새 너비. (왼쪽 위는 그대로)New width. (the top left stays)

짝Counterpart: vanilla.js Rect.width

메서드methodpub fn set_height(&mut self, height: f64)#0.4.0 부터since 0.4.0소스source

높이 설정.

Sets the height.

heightf64
새 높이. (왼쪽 위는 그대로)New height. (the top left stays)

짝Counterpart: vanilla.js Rect.height

메서드methodpub fn get_min(&self) -> Vector2#0.4.0 부터since 0.4.0소스source

왼쪽 위. (위치)

Top left. (the position)

반환ReturnsVector2 왼쪽 위 점.Top-left point.

짝Counterpart: vanilla.js Rect.min

메서드methodpub fn set_min(&mut self, minimum: Vector2)#0.4.0 부터since 0.4.0소스source

왼쪽 위 설정. (오른쪽 아래는 그대로 두고 크기를 바꾼다)

Sets the top left. (keeps the bottom right and changes the size)

minimumVector2
새 왼쪽 위 점.New top-left point.

짝Counterpart: vanilla.js Rect.min

예제Example오른쪽 아래를 둔 채 왼쪽 위만 옮기기Move only the top left while keeping the bottom right
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));
메서드methodpub fn get_max(&self) -> Vector2#0.4.0 부터since 0.4.0소스source

오른쪽 아래. (위치 + 크기)

Bottom right. (position + size)

반환ReturnsVector2 오른쪽 아래 점.Bottom-right point.

짝Counterpart: vanilla.js Rect.max

메서드methodpub fn set_max(&mut self, maximum: Vector2)#0.4.0 부터since 0.4.0소스source

오른쪽 아래 설정. (위치는 그대로 두고 크기를 바꾼다)

Sets the bottom right. (keeps the position and changes the size)

maximumVector2
새 오른쪽 아래 점.New bottom-right point.

짝Counterpart: vanilla.js Rect.max

메서드methodpub fn get_center(&self) -> Vector2#0.4.0 부터since 0.4.0소스source

가운데.

Center.

반환ReturnsVector2 가운데 점.Center point.

짝Counterpart: vanilla.js Rect.center

메서드methodpub fn set_center(&mut self, center: Vector2)#0.4.0 부터since 0.4.0소스source

가운데 설정. (크기는 그대로 두고 옮긴다)

Sets the center. (moves it, keeping the size)

centerVector2
새 가운데 점.New center point.

짝Counterpart: vanilla.js Rect.center

메서드methodpub fn get_left(&self) -> f64#0.4.0 부터since 0.4.0소스source

왼쪽 x.

Left x.

반환Returnsf64 왼쪽 x.Left x.

짝Counterpart: vanilla.js Rect.left

메서드methodpub fn set_left(&mut self, left: f64)#0.4.0 부터since 0.4.0소스source

왼쪽 x 설정. (크기는 그대로 두고 옮긴다)

Sets the left x. (moves it, keeping the size)

leftf64
새 왼쪽 x.New left x.

짝Counterpart: vanilla.js Rect.left

메서드methodpub fn get_top(&self) -> f64#0.4.0 부터since 0.4.0소스source

위 y.

Top y.

반환Returnsf64 위 y.Top y.

짝Counterpart: vanilla.js Rect.top

메서드methodpub fn set_top(&mut self, top: f64)#0.4.0 부터since 0.4.0소스source

위 y 설정. (크기는 그대로 두고 옮긴다)

Sets the top y. (moves it, keeping the size)

topf64
새 위 y.New top y.

짝Counterpart: vanilla.js Rect.top

메서드methodpub fn get_right(&self) -> f64#0.4.0 부터since 0.4.0소스source

오른쪽 x.

Right x.

반환Returnsf64 오른쪽 x. (왼쪽 x + 너비)Right x. (left x + width)

짝Counterpart: vanilla.js Rect.right

메서드methodpub fn set_right(&mut self, right: f64)#0.4.0 부터since 0.4.0소스source

오른쪽 x 설정. (크기는 그대로 두고 옮긴다)

Sets the right x. (moves it, keeping the size)

rightf64
새 오른쪽 x.New right x.

짝Counterpart: vanilla.js Rect.right

메서드methodpub fn get_bottom(&self) -> f64#0.4.0 부터since 0.4.0소스source

아래 y.

Bottom y.

반환Returnsf64 아래 y. (위 y + 높이)Bottom y. (top y + height)

짝Counterpart: vanilla.js Rect.bottom

메서드methodpub fn set_bottom(&mut self, bottom: f64)#0.4.0 부터since 0.4.0소스source

아래 y 설정. (크기는 그대로 두고 옮긴다)

Sets the bottom y. (moves it, keeping the size)

bottomf64
새 아래 y.New bottom y.

짝Counterpart: vanilla.js Rect.bottom

메서드methodpub fn contains(&self, point: Vector2) -> bool#0.3.2 부터since 0.3.2소스source

점이 안에 있는지.

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

메서드methodpub fn intersects(&self, other: &Rect) -> bool#0.3.2 부터since 0.3.2소스source

다른 사각형과 겹치는지.

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

예제Example맞닿은 사각형은 intersects 로는 겹치지 않고 overlaps 로는 겹친다Touching rectangles do not overlap with intersects but do with overlaps
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));
메서드methodpub fn overlaps(&self, other: &Rect) -> bool#0.4.0 부터since 0.4.0소스source

다른 사각형과 겹치는지. (원본 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

메서드methodpub fn intersection(&self, other: &Rect) -> Rect#0.4.0 부터since 0.4.0소스source

겹친 영역. (겹치지 않으면 빈 사각형, 변만 닿으면 너비나 높이가 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

예제Example겹침, 맞닿음, 떨어짐Overlapping, touching, apart
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());
메서드methodpub fn union(&self, other: &Rect) -> Rect#0.4.0 부터since 0.4.0소스source

둘을 다 덮는 가장 작은 사각형.

The smallest rectangle covering both.

other&Rect
같이 덮을 사각형.Rectangle to cover together.

반환ReturnsRect 둘을 다 덮는 가장 작은 사각형.The smallest rectangle covering both.

짝Counterpart: vanilla.js Rect.union