Compare commits

...

3 Commits

Author SHA1 Message Date
ChenX
bfa2feca5b 允许返回空 2024-03-29 17:47:00 +08:00
ChenX
bdb033f410 支持返回空 2024-03-29 16:30:00 +08:00
ChenX
13b169882b 优化代码 使用textBox 2024-03-28 14:44:17 +08:00
6 changed files with 60 additions and 21 deletions

View File

@@ -23207,16 +23207,25 @@ NestCache.NoPutCache = {};
NestCache.CacheRect = new Map();
const TEXT_BOX = NestCache.CreatePath(570, 110);
//分析文字放置位置
function ParseRegionTextPos(contour, holes, textBox = TEXT_BOX) {
/**
* 分析文字放置位置
* @param contour 轮廓点表
* @param holes 网洞点表
* @param [textBox=TEXT_BOX] 标签盒子
* @param [allowReturnNullPos=false] 允许返回null 当没有找到合适的位置返回null
* @returns Vector3
*/
function ParseRegionTextPos(contour, holes, textBox = TEXT_BOX, allowReturnNullPos = false) {
let hasTextBox = true;
let path = new Path(contour);
let nfps = path.GetInsideNFP(textBox)?.map(nfp => Path2Polyline(PathTranslate_Self(PathScale(nfp, 1e-4), path.OrigionMinPoint.x, path.OrigionMinPoint.y))); //可能无法获得
if (!nfps || nfps.length === 0) {
if (allowReturnNullPos)
return;
nfps = [Path2Polyline(contour)];
hasTextBox = false;
}
let holenfps = [];
let holeNFPs = [];
for (let hole of holes) {
let hpath = new Path(hole);
let nfps = hpath.GetOutsideNFP(textBox);
@@ -23226,11 +23235,11 @@ function ParseRegionTextPos(contour, holes, textBox = TEXT_BOX) {
let boxpl = new exports.Polyline().RectangleFrom2Pt(new three.Vector3(box.min.x - 1e5, box.min.y - 1), new three.Vector3(box.max.x + 1e5, box.min.y + 1));
let con1 = Contour.CreateContour(pl, false);
let con2 = Contour.CreateContour(boxpl, false);
holenfps.push(...con1.UnionBoolOperation(con2).contours);
holeNFPs.push(...con1.UnionBoolOperation(con2).contours);
}
let shapes = nfps.map(pl => new Shape(Contour.CreateContour(pl, false)));
let subShapes = new ShapeManager;
holenfps.forEach(pl => {
holeNFPs.forEach(pl => {
subShapes.UnionBoolOperation(new ShapeManager([new Shape(pl)]));
});
let resShapes = [];
@@ -23238,8 +23247,12 @@ function ParseRegionTextPos(contour, holes, textBox = TEXT_BOX) {
// TestDraw(shape.Outline.Curve, 6);
resShapes.push(...shape.SubstactBoolOperation(subShapes.ShapeList)); //可能减完丢了
}
if (resShapes.length === 0)
if (resShapes.length === 0) {
//允许返回空的点 因为无法放置
if (allowReturnNullPos)
return;
resShapes = shapes;
}
let maxDist = -Infinity;
let minp;
for (let shape of resShapes) {
@@ -23279,8 +23292,8 @@ function ParseRegionTextPos(contour, holes, textBox = TEXT_BOX) {
// p = midPoint(pts[index - 1], pts[index + 1]);
// TestDraw(new Point(p));
if (hasTextBox) {
p.x += 280;
p.y += 60;
p.x += textBox.Size.x * 0.5;
p.y += textBox.Size.y * 0.5;
}
return p;
}

File diff suppressed because one or more lines are too long

View File

@@ -22875,7 +22875,12 @@ function InitClipperCpp() {
return new Promise((res, rej) => {
clipperLib.loadNativeClipperLibInstanceAsync(
// let it autodetect which one to use, but also available WasmOnly and AsmJsOnly
clipperLib.NativeClipperLibRequestedFormat.WasmOnly).then(c => {
//del_ue_exp_start
clipperLib.NativeClipperLibRequestedFormat.WasmOnly
//del_ue_exp_end
//del_ue_exp_start
//del_ue_exp_end clipperLib.NativeClipperLibRequestedFormat.AsmJsOnly
).then(c => {
clipperCpp.lib = c;
res();
// console.log("载入成功!");//不再需要
@@ -23175,16 +23180,25 @@ NestCache.NoPutCache = {};
NestCache.CacheRect = new Map();
const TEXT_BOX = NestCache.CreatePath(570, 110);
//分析文字放置位置
function ParseRegionTextPos(contour, holes, textBox = TEXT_BOX) {
/**
* 分析文字放置位置
* @param contour 轮廓点表
* @param holes 网洞点表
* @param [textBox=TEXT_BOX] 标签盒子
* @param [allowReturnNullPos=false] 允许返回null 当没有找到合适的位置返回null
* @returns Vector3
*/
function ParseRegionTextPos(contour, holes, textBox = TEXT_BOX, allowReturnNullPos = false) {
let hasTextBox = true;
let path = new Path(contour);
let nfps = path.GetInsideNFP(textBox)?.map(nfp => Path2Polyline(PathTranslate_Self(PathScale(nfp, 1e-4), path.OrigionMinPoint.x, path.OrigionMinPoint.y))); //可能无法获得
if (!nfps || nfps.length === 0) {
if (allowReturnNullPos)
return;
nfps = [Path2Polyline(contour)];
hasTextBox = false;
}
let holenfps = [];
let holeNFPs = [];
for (let hole of holes) {
let hpath = new Path(hole);
let nfps = hpath.GetOutsideNFP(textBox);
@@ -23194,11 +23208,11 @@ function ParseRegionTextPos(contour, holes, textBox = TEXT_BOX) {
let boxpl = new Polyline().RectangleFrom2Pt(new Vector3(box.min.x - 1e5, box.min.y - 1), new Vector3(box.max.x + 1e5, box.min.y + 1));
let con1 = Contour.CreateContour(pl, false);
let con2 = Contour.CreateContour(boxpl, false);
holenfps.push(...con1.UnionBoolOperation(con2).contours);
holeNFPs.push(...con1.UnionBoolOperation(con2).contours);
}
let shapes = nfps.map(pl => new Shape(Contour.CreateContour(pl, false)));
let subShapes = new ShapeManager;
holenfps.forEach(pl => {
holeNFPs.forEach(pl => {
subShapes.UnionBoolOperation(new ShapeManager([new Shape(pl)]));
});
let resShapes = [];
@@ -23206,8 +23220,12 @@ function ParseRegionTextPos(contour, holes, textBox = TEXT_BOX) {
// TestDraw(shape.Outline.Curve, 6);
resShapes.push(...shape.SubstactBoolOperation(subShapes.ShapeList)); //可能减完丢了
}
if (resShapes.length === 0)
if (resShapes.length === 0) {
//允许返回空的点 因为无法放置
if (allowReturnNullPos)
return;
resShapes = shapes;
}
let maxDist = -Infinity;
let minp;
for (let shape of resShapes) {
@@ -23247,8 +23265,8 @@ function ParseRegionTextPos(contour, holes, textBox = TEXT_BOX) {
// p = midPoint(pts[index - 1], pts[index + 1]);
// TestDraw(new Point(p));
if (hasTextBox) {
p.x += 280;
p.y += 60;
p.x += textBox.Size.x * 0.5;
p.y += textBox.Size.y * 0.5;
}
return p;
}

File diff suppressed because one or more lines are too long

View File

@@ -1,5 +1,13 @@
import { Vector3 } from "three";
import { Point } from "../../../Nest/Common/Point";
import { Path } from "../../../Nest/Core/Path";
export declare function ParseRegionTextPos(contour: Point[], holes: (Point[])[], textBox?: Path): Vector3;
/**
* 分析文字放置位置
* @param contour 轮廓点表
* @param holes 网洞点表
* @param [textBox=TEXT_BOX] 标签盒子
* @param [allowReturnNullPos=false] 允许返回null 当没有找到合适的位置返回null
* @returns Vector3
*/
export declare function ParseRegionTextPos(contour: Point[], holes: (Point[])[], textBox?: Path, allowReturnNullPos?: boolean): Vector3 | undefined;
//# sourceMappingURL=ParseRegionTextPos.d.ts.map

View File

@@ -1 +1 @@
{"version":3,"file":"ParseRegionTextPos.d.ts","sourceRoot":"","sources":["../../../../../src/DatabaseServices/Room/ParseService/ParseRegionTextPos.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAEhC,OAAO,EAAE,KAAK,EAAE,MAAM,4BAA4B,CAAC;AAInD,OAAO,EAAE,IAAI,EAAiC,MAAM,yBAAyB,CAAC;AAS9E,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,KAAK,EAAE,EAAE,KAAK,EAAE,CAAC,KAAK,EAAE,CAAC,EAAE,EAAE,OAAO,OAAW,WAuG1F"}
{"version":3,"file":"ParseRegionTextPos.d.ts","sourceRoot":"","sources":["../../../../../src/DatabaseServices/Room/ParseService/ParseRegionTextPos.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAEhC,OAAO,EAAE,KAAK,EAAE,MAAM,4BAA4B,CAAC;AAInD,OAAO,EAAE,IAAI,EAAiC,MAAM,yBAAyB,CAAC;AAQ9E;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,KAAK,EAAE,EAAE,KAAK,EAAE,CAAC,KAAK,EAAE,CAAC,EAAE,EAAE,OAAO,OAAW,EAAE,kBAAkB,UAAQ,GAAG,OAAO,GAAG,SAAS,CA6G5I"}