vanilladocs
vanillapunch.com
API / base/rect

base/rect

사각 영역.

Rectangular area.

Rectextends Object

짝Counterpart: vanilla-engine Rect

사각 영역.

Rectangular area.

예제Example점과 영역 검사, 겹친 영역 구하기Test points and areas, find the overlapping area
import { Rect, Vector2 } from "./build/vanilla.js";

const panel = Rect.create(0, 0, 100, 50);
const button = Rect.create(80, 40, 40, 20);
const point = Vector2.create(10, 10);
console.log(panel.contains(point), panel.overlaps(button));
const overlap = panel.intersection(button);
console.log(overlap.left, overlap.top, overlap.width, overlap.height);
const bounds = panel.union(button);
console.log(bounds.right, bounds.bottom);
생성자constructorconstructor()#0.0.8 부터since 0.0.8소스source

생성.

Constructor.

정적staticstatic create(x, y, width, height)#0.0.8 부터since 0.0.8소스source

새로운 사각 영역 생성.

Creates a new rectangular area.

xnumber
좌상단 X 좌표.Top left X coordinate.
ynumber
좌상단 Y 좌표.Top left Y coordinate.
widthnumber
가로 크기.Width.
heightnumber
세로 크기.Height.

반환ReturnsRect 새 사각 영역.A new rectangle.

짝Counterpart: vanilla-engine Rect.create

정적staticstatic zero()#0.0.8 부터since 0.0.8소스source

크기가 없는 빈 사각 영역 생성.

Creates an empty rectangular area with no size.

반환ReturnsRect 위치와 크기가 모두 0 인 사각 영역.A rectangle whose position and size are all 0.

짝Counterpart: vanilla-engine Rect.zero

정적staticstatic clamp(value, min, max)#0.0.8 부터since 0.0.8소스source

범위 제한.

Clamps to a range.

valueRect
자를 사각 영역.Rectangle to clamp.
minRect
위치와 크기의 최솟값.Minimum for position and size.
maxRect
위치와 크기의 최댓값.Maximum for position and size.

반환ReturnsRect 위치와 크기를 성분마다 자른 새 사각 영역.A new rectangle with position and size clamped per component.

짝Counterpart: vanilla-engine Rect.clamp

속성propertyget/set position#0.0.8 부터since 0.0.8소스source

위치 반환 프로퍼티. 위치 설정 프로퍼티.

Position getter property. Position setter property.

반환ReturnsVector2 좌상단 위치. (내부 벡터를 그대로 돌려준다)Top left position. (returns the internal vector as is)

짝Counterpart: vanilla-engine Rect.position

속성propertyget/set size#0.0.8 부터since 0.0.8소스source

크기 반환 프로퍼티. 크기 설정 프로퍼티.

Size getter property. Size setter property.

반환ReturnsVector2 가로, 세로 크기. (내부 벡터를 그대로 돌려준다)Width and height. (returns the internal vector as is)

짝Counterpart: vanilla-engine Rect.size

속성propertyget/set width#0.0.8 부터since 0.0.8소스source

가로 크기 프로퍼티.

Width property.

반환Returnsnumber 가로 크기.Width.

짝Counterpart: vanilla-engine Rect.get_width

속성propertyget/set height#0.0.8 부터since 0.0.8소스source

세로 크기 프로퍼티.

Height property.

반환Returnsnumber 세로 크기.Height.

짝Counterpart: vanilla-engine Rect.get_height

속성propertyget/set min#0.0.8 부터since 0.0.8소스source

최소 좌표 프로퍼티 (좌상단).

Minimum coordinate property (top-left).

반환ReturnsVector2 좌상단 좌표의 새 벡터.A new vector of the top left coordinates.

짝Counterpart: vanilla-engine Rect.get_min

속성propertyget/set max#0.0.8 부터since 0.0.8소스source

최대 좌표 프로퍼티 (우하단).

Maximum coordinate property (bottom-right).

반환ReturnsVector2 우하단 좌표의 새 벡터.A new vector of the bottom right coordinates.

짝Counterpart: vanilla-engine Rect.get_max

속성propertyget/set center#0.0.8 부터since 0.0.8소스source

가운데 반환 프로퍼티. 가운데 설정 프로퍼티.

Center getter property. Center setter property.

반환ReturnsVector2 가운데 좌표의 새 벡터.A new vector of the center coordinates.

짝Counterpart: vanilla-engine Rect.get_center

속성propertyget/set left#0.0.8 부터since 0.0.8소스source

왼쪽 반환 프로퍼티. 왼쪽 설정 프로퍼티.

Left getter property. Left setter property.

반환Returnsnumber 왼쪽 X 좌표.Left X coordinate.

짝Counterpart: vanilla-engine Rect.get_left

속성propertyget/set top#0.0.8 부터since 0.0.8소스source

위쪽 반환 프로퍼티. 위쪽 설정 프로퍼티.

Top getter property. Top setter property.

반환Returnsnumber 위쪽 Y 좌표.Top Y coordinate.

짝Counterpart: vanilla-engine Rect.get_top

속성propertyget/set right#0.0.8 부터since 0.0.8소스source

오른쪽 반환 프로퍼티. 오른쪽 설정 프로퍼티.

Right getter property. Right setter property.

반환Returnsnumber 오른쪽 X 좌표.Right X coordinate.

짝Counterpart: vanilla-engine Rect.get_right

속성propertyget/set bottom#0.0.8 부터since 0.0.8소스source

아래쪽 반환 프로퍼티. 아래쪽 설정 프로퍼티.

Bottom getter property. Bottom setter property.

반환Returnsnumber 아래쪽 Y 좌표.Bottom Y coordinate.

짝Counterpart: vanilla-engine Rect.get_bottom

메서드methodequals(other)#0.0.8 부터since 0.0.8소스source

동등성 비교.

Equality comparison.

otherany
비교할 값.Value to compare.

반환Returnsboolean 같은 객체이거나 위치와 크기가 모두 같은 Rect 면 참.True if it is the same object or a Rect with the same position and size.

메서드methodclone()#0.0.9 부터since 0.0.9소스source

복제.

Clone.

반환Returnsthis 위치와 크기가 같은 새 사각 영역.A new rectangle with the same position and size.

메서드methodcontains(value)#0.0.8 부터since 0.0.8소스source

겹치는지 여부.

Whether it overlaps.

valueVector2
검사할 점.Point to test.

반환Returnsboolean 점이 영역 안이나 변 위에 있으면 참. (Vector2 가 아니면 거짓)True if the point is inside the area or on its edge. (false if not a Vector2)

짝Counterpart: vanilla-engine Rect.contains

메서드methodoverlaps(value)#0.0.8 부터since 0.0.8소스source

겹치는지 여부.

Whether it overlaps.

valueRect
검사할 사각 영역.Rectangle to test.

반환Returnsboolean 겹치거나 변이 닿으면 참. (Rect 가 아니면 거짓)True if they overlap or their edges touch. (false if not a Rect)

짝Counterpart: vanilla-engine Rect.overlaps

메서드methodintersects(other)#0.4.0 부터since 0.4.0소스source

다른 사각형과 겹치는지. (변이 닿기만 한 것은 겹친 것이 아니다, overlaps 는 닿기만 해도 겹친 것으로 본다)

Whether it overlaps another rectangle. (Edges merely touching do not count as overlapping, overlaps counts mere touching as overlapping)

otherRect
검사할 사각 영역.Rectangle to test.

반환Returnsboolean 넓이가 있는 겹침이 있으면 참.True if they overlap with a nonzero area.

짝Counterpart: vanilla-engine Rect.intersects

예제Example변이 닿은 두 사각 영역 비교하기Compare two rectangles whose edges touch
import { Rect } from "./build/vanilla.js";

const leftRect = Rect.create(0, 0, 10, 10);
const rightRect = Rect.create(10, 0, 10, 10);
console.log(leftRect.overlaps(rightRect), leftRect.intersects(rightRect));
메서드methodintersection(other)#0.0.8 부터since 0.0.8소스source

교집합 (두 사각형이 겹치는 영역 반환).

Intersection (returns the area where the two rectangles overlap).

otherRect
겹침을 구할 사각 영역.Rectangle to intersect with.

반환ReturnsRect 겹친 부분의 새 사각 영역. (겹치지 않으면 Rect.zero())A new rectangle of the overlapping part. (Rect.zero() if they do not overlap)

짝Counterpart: vanilla-engine Rect.intersection

메서드methodunion(other)#0.0.8 부터since 0.0.8소스source

합집합 (두 사각형을 모두 포함하는 최소 사각형 반환).

Union (returns the smallest rectangle containing both rectangles).

otherRect
합칠 사각 영역.Rectangle to merge.

반환ReturnsRect 두 영역을 모두 담는 가장 작은 새 사각 영역.The smallest new rectangle that contains both areas.

짝Counterpart: vanilla-engine Rect.union

메서드methodisZero()#0.3.2 부터since 0.3.2소스source

위치와 크기가 모두 0 인지. (Rect.zero() 와 같은지를 새 객체를 만들지 않고 본다)

Whether position and size are both 0. (Checks equality with Rect.zero() without creating a new object)

반환Returnsboolean 위치와 크기가 모두 0 이면 참.True if both position and size are 0.

짝Counterpart: vanilla-engine Rect.is_zero