|
@@ -4,7 +4,12 @@ import { Container } from "../packages";
|
|
|
import { EntityType, Entity } from "../packages/entity";
|
|
|
import { Attrib, ShapeType } from "../type";
|
|
|
import { getTouchOffset } from "./act";
|
|
|
-import { createLineByDire, getDireDist } from "./math";
|
|
|
+import {
|
|
|
+ createLineByDire,
|
|
|
+ getDireDist,
|
|
|
+ getLineIntersection,
|
|
|
+ getLineProjection,
|
|
|
+} from "./math";
|
|
|
import { inRevise } from "./public";
|
|
|
import { disableMouse, enableMouse } from "./shape-mose";
|
|
|
import { generateId, getChangePart } from "./util";
|
|
@@ -126,16 +131,21 @@ export const copyEntityAttrib = <T extends Entity = Entity>(
|
|
|
) => {
|
|
|
const count = props.count || 1;
|
|
|
const dire = props.dire || [1, 0];
|
|
|
- const halfSize = props.size;
|
|
|
+ const size = props.size;
|
|
|
const entity = props.entity;
|
|
|
const start = entity.shape.getPosition();
|
|
|
- const unit = getDireDist(halfSize);
|
|
|
+ const line = createLineByDire(dire, [start.x, start.y], 10);
|
|
|
const items = entity.container.getSameLevelData(entity) as Attrib[];
|
|
|
|
|
|
for (let i = 0; i < count; i++) {
|
|
|
- const line = createLineByDire(dire, [start.x, start.y], unit * (i + 1));
|
|
|
+ const offset = size.map((p) => (p *= i + 1));
|
|
|
+ const point = getLineProjection(line, [
|
|
|
+ start.x + offset[0],
|
|
|
+ start.y + offset[1],
|
|
|
+ ]).point;
|
|
|
+
|
|
|
const newAttrib = {
|
|
|
- ...props.factoryAttrib([line[2], line[3]]),
|
|
|
+ ...props.factoryAttrib(point),
|
|
|
id: generateId(items),
|
|
|
};
|
|
|
items.push(newAttrib as any);
|