【国产开源可视化引擎】Meta2d.js API-Rect

区域位置。

属性

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 });

----------------------------------------------------------------------

乐吾乐潜心研发,自主可控,持续迭代优化

Github:GitHub - le5le-com/meta2d.js: The meta2d.js is real-time data exchange and interactive web 2D engine. Developers are able to build Web SCADA, IoT, Digital twins and so on. Meta2d.js是一个实时数据响应和交互的2d引擎,可用于Web组态,物联网,数字孪生等场景。

Gitee: meta2d.js: The meta2d.js is real-time data exchange and interactive web 2D engine. Developers are able to build Web SCADA, IoT, Digital twins and so on. Meta2d.js是一个实时数据响应和交互的2d引擎,可用于Web组态,物联网,数字孪生等场景。

欢迎Star、Fork、博文支持

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值