add path INTERSECT JOIN
This commit is contained in:
parent
9574572200
commit
8a3feb2acc
6
demo/js/contours-3.js
Normal file
6
demo/js/contours-3.js
Normal file
@ -0,0 +1,6 @@
|
||||
|
||||
define(
|
||||
function(require) {
|
||||
return {"xMin":0,"yMin":-32,"xMax":512,"yMax":480,"unicode":[57358],"advanceWidth":512,"leftSideBearing":0,"name":"uniE00E","contours":[[{"x":362,"y":480},{"x":150,"y":480},{"x":0,"y":330},{"x":0,"y":118},{"x":150,"y":-32},{"x":362,"y":-32},{"x":512,"y":118},{"x":512,"y":330}],[{"x":360,"y":148,"onCurve":true},{"x":365,"y":143},{"x":365,"y":127},{"x":360,"y":122,"onCurve":true},{"x":351,"y":113,"onCurve":true},{"x":345,"y":108},{"x":330,"y":108},{"x":325,"y":113,"onCurve":true},{"x":254,"y":184,"onCurve":true},{"x":183,"y":114,"onCurve":true},{"x":178,"y":108},{"x":163,"y":108},{"x":157,"y":114,"onCurve":true},{"x":148,"y":122,"onCurve":true},{"x":143,"y":128},{"x":143,"y":143},{"x":148,"y":148,"onCurve":true},{"x":219,"y":219,"onCurve":true},{"x":148,"y":290,"onCurve":true},{"x":143,"y":295},{"x":143,"y":311},{"x":148,"y":316,"onCurve":true},{"x":157,"y":325,"onCurve":true},{"x":162,"y":330},{"x":177,"y":330},{"x":183,"y":325,"onCurve":true},{"x":254,"y":254,"onCurve":true},{"x":325,"y":325,"onCurve":true},{"x":330,"y":330},{"x":346,"y":330},{"x":351,"y":325,"onCurve":true},{"x":360,"y":316,"onCurve":true},{"x":365,"y":311},{"x":365,"y":295},{"x":360,"y":290,"onCurve":true},{"x":289,"y":219,"onCurve":true}]]};
|
||||
}
|
||||
);
|
@ -11,7 +11,7 @@ define(
|
||||
|
||||
var lang = require('common/lang');
|
||||
var editor = require('editor/main');
|
||||
var shape_baidu = require('./contours');
|
||||
var shape_baidu = require('./contours-3');
|
||||
var isPathCross = require('graphics/isPathCross');
|
||||
var pathJoin = require('graphics/pathJoin');
|
||||
var util = require('graphics/util');
|
||||
@ -54,24 +54,26 @@ define(
|
||||
}
|
||||
});
|
||||
});
|
||||
jointLayer.refresh();
|
||||
|
||||
var paths = pathJoin(path0, path1, 1);
|
||||
|
||||
paths.forEach(function(p, index) {
|
||||
jointLayer.addShape('path', {
|
||||
points: lang.clone(p),
|
||||
style: {
|
||||
lineWidth: 2,
|
||||
fill:true,
|
||||
fillColor: index % 2 ? 'red' : 'blue'
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
jointLayer.refresh();
|
||||
}
|
||||
|
||||
|
||||
var paths = pathJoin(path0, path1, 4);
|
||||
|
||||
paths.forEach(function(p, index) {
|
||||
jointLayer.addShape('path', {
|
||||
points: lang.clone(p),
|
||||
style: {
|
||||
lineWidth: 2,
|
||||
fill:true,
|
||||
fillColor: index % 2 ? 'red' : 'blue'
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
jointLayer.refresh();
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -108,11 +108,11 @@ define(
|
||||
var result = getPathJoint(path0, path1);
|
||||
if (!result) {
|
||||
// 0 包含 1
|
||||
if (isInsidePath(path1, path0[0])) {
|
||||
if (isInsidePath(path0, path1[0])) {
|
||||
return 2;
|
||||
}
|
||||
// 1 包含 0
|
||||
else if(isInsidePath(path0, path1[0])) {
|
||||
else if(isInsidePath(path1, path0[0])) {
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
|
@ -178,74 +178,73 @@ define(
|
||||
var newPaths = [];
|
||||
var splice = Array.prototype.splice;
|
||||
|
||||
// 交集
|
||||
if (relation == pathJoin.INTERSECT) {
|
||||
// 过滤路径
|
||||
var filterPath = function(path){
|
||||
if (relation == pathJoin.INTERSECT) {
|
||||
return path.cross;
|
||||
}
|
||||
else if (relation == pathJoin.JOIN) {
|
||||
return !path.cross;
|
||||
}
|
||||
else {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
else {
|
||||
splitPaths0 = splitPaths0.filter(filterPath);
|
||||
splitPaths1 = splitPaths1.filter(filterPath);
|
||||
|
||||
// 相切,分割图形
|
||||
if (relation == pathJoin.TANGENCY) {
|
||||
|
||||
// 计算哈希,用来辅助组合点
|
||||
var splitHash0 = getSplitPathHash(splitPaths0);
|
||||
var splitHash1 = getSplitPathHash(splitPaths1);
|
||||
// 计算哈希,用来辅助组合点
|
||||
var splitHash0 = getSplitPathHash(splitPaths0);
|
||||
var splitHash1 = getSplitPathHash(splitPaths1);
|
||||
|
||||
for (var i = 0; i < splitPaths0.length; i++) {
|
||||
var length = splitPaths0[i].length;
|
||||
var newPath = splitPaths0[i].slice(0, length - 1);
|
||||
for (var i = 0; i < splitPaths0.length; i++) {
|
||||
var length = splitPaths0[i].length;
|
||||
var newPath = splitPaths0[i].slice(0, length - 1);
|
||||
|
||||
var start = splitPaths0[i][0];
|
||||
var end = splitPaths0[i][length - 1];
|
||||
|
||||
var nextHash = splitHash1;
|
||||
var cross = splitPaths0[i].cross; // 起始cross
|
||||
var loops = 0; // 防止死循环,最多组合100个路径段
|
||||
var start = splitPaths0[i][0];
|
||||
var end = splitPaths0[i][length - 1];
|
||||
|
||||
var nextHash = splitHash1;
|
||||
var cross = splitPaths0[i].cross; // 起始cross
|
||||
var loops = 0; // 防止死循环,最多组合100个路径段
|
||||
|
||||
while (loops++ < 100 && (Math.abs(start.x - end.x) > 0.0001 || Math.abs(start.y - end.y) > 0.0001)) {
|
||||
while (loops++ < 100 && (Math.abs(start.x - end.x) > 0.0001 || Math.abs(start.y - end.y) > 0.0001)) {
|
||||
|
||||
var paths = nextHash[hashcode(end)];
|
||||
|
||||
// 选取异向
|
||||
var p = paths[0];
|
||||
if (cross == p.cross) {
|
||||
p = paths[1];
|
||||
}
|
||||
|
||||
if (end.x == p[0].x && end.y == p[0].y) {
|
||||
}
|
||||
else {
|
||||
p = p.reverse();
|
||||
}
|
||||
|
||||
splice.apply(newPath, [newPath.length, 0].concat(p.slice(0, p.length - 1)));
|
||||
|
||||
cross = !cross;
|
||||
end = p[p.length - 1];
|
||||
|
||||
if (nextHash === splitHash1) {
|
||||
nextHash = splitHash0;
|
||||
}
|
||||
else {
|
||||
nextHash = splitHash1;
|
||||
// 这里需要去掉已经使用的splitPaths0上的点
|
||||
splitPaths0.splice(splitPaths0.indexOf(p), 1);
|
||||
}
|
||||
}
|
||||
|
||||
newPaths.push(newPath);
|
||||
var paths = nextHash[hashcode(end)];
|
||||
|
||||
// 选取异向
|
||||
var p = paths[0];
|
||||
if (relation == pathJoin.TANGENCY && cross == p.cross) {
|
||||
p = paths[1];
|
||||
}
|
||||
|
||||
if (end.x == p[0].x && end.y == p[0].y) {
|
||||
}
|
||||
else {
|
||||
p = p.reverse();
|
||||
}
|
||||
|
||||
splice.apply(newPath, [newPath.length, 0].concat(p.slice(0, p.length - 1)));
|
||||
|
||||
cross = !cross;
|
||||
end = p[p.length - 1];
|
||||
|
||||
if (nextHash === splitHash1) {
|
||||
nextHash = splitHash0;
|
||||
}
|
||||
else {
|
||||
nextHash = splitHash1;
|
||||
// 这里需要去掉已经使用的splitPaths0上的点
|
||||
splitPaths0.splice(splitPaths0.indexOf(p), 1);
|
||||
}
|
||||
}
|
||||
|
||||
// 合并两图形
|
||||
else {
|
||||
|
||||
}
|
||||
newPaths.push(newPath);
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (newPaths.length) {
|
||||
return newPaths.map(function(path){
|
||||
return util.deInterpolate(path);
|
||||
@ -309,6 +308,10 @@ define(
|
||||
if (relation == pathJoin.JOIN && direction0 !== direction1) {
|
||||
relation = pathJoin.TANGENCY;
|
||||
}
|
||||
// 异向的相交等于空
|
||||
if (relation == pathJoin.INTERSECT && direction0 !== direction1) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return combinePath(splitPaths0, splitPaths1, relation);
|
||||
|
||||
|
@ -48,10 +48,10 @@ define(
|
||||
});
|
||||
|
||||
if(2 === result) {
|
||||
return start;
|
||||
return end;
|
||||
}
|
||||
else if(3 === result) {
|
||||
return end;
|
||||
return start;
|
||||
}
|
||||
else {
|
||||
return start;
|
||||
|
Loading…
x
Reference in New Issue
Block a user