区域位置。
属性
interface Rect {
x?: number;
y?: number;
ex?: number; // x + width
ey?: number; // y + height
width?: number;
height?: number;
rotate?: number;
center?: Point; // {x, y}
}
Copy
函数
这里的函数为相关函数
pointInRect
点是否在 Rect 上。会计算旋转因素
参数:
- pt: Point
- rect: Rect
返回:
boolean
示例:
import { pointInRect } from '@meta2d/core';
// 点(世界坐标)是否在pen上
pointInRect(point, pen.calculative.worldRect);
Copy
pointInSimpleRect
点是否在 Rect 上,不计算旋转因素。
参数:
- pt: Point
- rect: Rect
- r: number
偏移半径。默认 0
返回:
boolean
示例:
import { pointInSimpleRect } from '@meta2d/core';
// 点(世界坐标)是否在pen上
pointInSimpleRect(point, pen.calculative.worldRect);
Copy
calcCenter
计算中心点。
参数:
- rect: Rect
返回:
void
示例:
import { calcCenter } from '@meta2d/core';
calcCenter({ x, y, width, height });
Copy
rectInRect
判断一个 rect 是否在另外一个 rect 内。
参数:
- source: Rect
- target: Rect
- allIn: boolean
是否需要 source 完全在 target 内。默认部分
返回:
boolean
示例:
import { rectInRect } from '@meta2d/core';
rectInRect({ x, y, width, height }, { x, y, width, height });
Copy
translateRect
平移 Rect。
参数:
- rect: Rect
- x: number
- y: number
返回:
void
示例:
import { translateRect } from '@meta2d/core';
translateRect({ x, y, width, height }, 10, 10);
Copy
scaleRect
缩放 Rect。
参数:
- rect: Rect
- scale: number
- center: Point
返回:
void
示例:
import { scaleRect } from '@meta2d/core';
scaleRect({ x, y, width, height }, 1.2, { x: 0, y: 0 });
Copy
calcRelativeRect
计算一个 rect 相对另外一个 worldRect 的相对坐标。通常用于计算子元素位置
参数:
- rect: Rect
- worldRect: Rect
返回:
Rect: 相对坐标
示例:
import { calcRelativeRect } from '@meta2d/core';
const relRect = calcRelativeRect({ x, y, width, height }, { x, y, width, height });
Copy
calcRelativePoint
计算点 相对 worldRect 的相对坐标。通常用于计算锚点位置
参数:
- pt: Point
- worldRect: Rect
返回:
Point: 相对坐标
示例:
import { calcRelativePoint } from '@meta2d/core';
const relPoint = calcRelativePoint({ x, y }, { x, y, width, height });
----------------------------------------------------------------------
乐吾乐潜心研发,自主可控,持续迭代优化
欢迎Star、Fork、博文支持