diff --git a/demo/js/contours-8.js b/demo/js/contours-8.js new file mode 100644 index 0000000..05bd70d --- /dev/null +++ b/demo/js/contours-8.js @@ -0,0 +1,6 @@ + +define( + function(require) { + return {"xMin":0,"yMin":0,"xMax":286,"yMax":266,"unicode":[58932],"advanceWidth":1024,"leftSideBearing":0,"name":"uniE634","contours":[[{"x":0,"y":81,"onCurve":true},{"x":0,"y":220,"onCurve":true},{"x":0,"y":230},{"x":8,"y":247},{"x":22,"y":260},{"x":41,"y":266},{"x":51,"y":266,"onCurve":true},{"x":237,"y":266,"onCurve":true},{"x":249,"y":266},{"x":266,"y":259},{"x":279,"y":247},{"x":286,"y":232},{"x":286,"y":224,"onCurve":true},{"x":286,"y":81,"onCurve":true}],[{"x":286,"y":185,"onCurve":true,"index0":13,"index1":13},{"x":286,"y":43,"onCurve":true,"index0":0,"index1":0},{"x":286,"y":34},{"x":279,"y":19},{"x":266,"y":7},{"x":249,"y":0},{"x":237,"y":0,"onCurve":true,"index0":6,"index1":6},{"x":51,"y":0,"onCurve":true,"index0":6,"index1":6},{"x":41,"y":0},{"x":22,"y":7},{"x":8,"y":19},{"x":0,"y":36},{"x":0,"y":47,"onCurve":true,"index0":12,"index1":12},{"x":0,"y":185,"onCurve":true,"index0":13,"index1":13}]]} + } +); diff --git a/demo/js/contoursCombine.js b/demo/js/contoursCombine.js index cef040e..fe20e69 100644 --- a/demo/js/contoursCombine.js +++ b/demo/js/contoursCombine.js @@ -11,7 +11,7 @@ define( var lang = require('common/lang'); var editor = require('editor/main'); - var shape_baidu = require('./contours-7'); + var shape_baidu = require('./contours-8'); var isPathCross = require('graphics/isPathCross'); var pathJoin = require('graphics/pathJoin'); var util = require('graphics/util'); diff --git a/src/graphics/join/join2Path.js b/src/graphics/join/join2Path.js index 7d5834d..c7fcf35 100644 --- a/src/graphics/join/join2Path.js +++ b/src/graphics/join/join2Path.js @@ -19,6 +19,22 @@ define( var pathSplit = require('./pathSplit'); var pathCombine = require('./pathCombine'); + /** + * 获取另一个路径和分割路径的交点情况 + * + * @param {Array} path 要比较的路径 + * @param {Array} splitedPath 分割后的路径 + * @return {boolean} 是否相交 + */ + function getPathCross(path, splitedPath) { + var inPath = isInsidePath( + path, + splitedPath[1].onCurve + ? splitedPath[1] + : getBezierQ2Point(splitedPath[0], splitedPath[1], splitedPath[2], 0.5) + ); + return !!inPath; + } /** * 求路径并集 @@ -39,17 +55,6 @@ define( var splitedPaths0; var splitedPaths1; - // 获取另一个路径和分割路径的交点情况 - var getPathCross = function (path, splitedPath) { - var inPath = isInsidePath( - path, - splitedPath[1].onCurve - ? splitedPath[1] - : getBezierQ2Point(splitedPath[0], splitedPath[1], splitedPath[2], 0.5) - ); - return inPath; - }; - // 获取组合后的路径 var getJoinedPath = function(joint) { @@ -67,17 +72,23 @@ define( splitedPath.cross = getPathCross(path1, splitedPath); - // 这里需要判断整个曲线有相交区域,但是部分曲线只有交点没有相交轮廓的情况 - if (inPathBefore == splitedPath.cross) { - partInPath = true; - } - if (splitedPath.cross) { inPath = true; } - inPathBefore = splitedPath.cross; + // 这里需要判断整个曲线有相交区域,但是部分曲线只有交点没有相交轮廓的情况 + if (inPathBefore === splitedPath.cross) { + if (false === inPathBefore) { + partInPath = true; + } + else { + // 这里需要修正相交边缘重叠的情况,不然组合路径的时候会出问题 + // TODO + } + } + + inPathBefore = splitedPath.cross; return splitedPath; });