MCPcopy Index your code
hub / github.com/SuperMap/iClient-JavaScript / isInsidePath

Method isInsidePath

src/common/overlay/levelRenderer/Area.js:854–1003  ·  view source on GitHub ↗

* @function LevelRenderer.Tool.Areal.prototype.isInsidePath * @description 与 canvas 一样采用 non-zero winding rule

(pathArray, lineWidth, brushType, x, y)

Source from the content-addressed store, hash-verified

852 * @description 与 canvas 一样采用 non-zero winding rule
853 */
854 isInsidePath(pathArray, lineWidth, brushType, x, y) {
855 var w = 0;
856 var xi = 0;
857 var yi = 0;
858 var x0 = 0;
859 var y0 = 0;
860 var beginSubpath = true;
861 var firstCmd = true;
862
863 brushType = brushType || 'fill';
864
865 var hasStroke = brushType === 'stroke' || brushType === 'both';
866 var hasFill = brushType === 'fill' || brushType === 'both';
867
868 // var roots = [-1, -1, -1];
869 for (var i = 0; i < pathArray.length; i++) {
870 var seg = pathArray[i];
871 var p = seg.points;
872 // Begin a new subpath
873 if (beginSubpath || seg.command === 'M') {
874 if (i > 0) {
875 // Close previous subpath
876 if (hasFill) {
877 w += this.windingLine(xi, yi, x0, y0, x, y);
878 }
879 if (w !== 0) {
880 return true;
881 }
882 }
883 x0 = p[p.length - 2];
884 y0 = p[p.length - 1];
885 beginSubpath = false;
886 if (firstCmd && seg.command !== 'A') {
887 // 如果第一个命令不是M, 是lineTo, bezierCurveTo
888 // 等绘制命令的话,是会从该绘制的起点开始算的
889 // Arc 会在之后做单独处理所以这里忽略
890 firstCmd = false;
891 xi = x0;
892 yi = y0;
893 }
894 }
895 switch (seg.command) {
896 case 'M':
897 xi = p[0];
898 yi = p[1];
899 break;
900 case 'L':
901 if (hasStroke) {
902 if (this.isInsideLine(
903 xi, yi, p[0], p[1], lineWidth, x, y
904 )) {
905 return true;
906 }
907 }
908 if (hasFill) {
909 w += this.windingLine(xi, yi, p[0], p[1], x, y);
910 }
911 xi = p[0];

Callers 1

_mathMethodMethod · 0.95

Calls 10

windingLineMethod · 0.95
isInsideLineMethod · 0.95
isInsideCubicStrokeMethod · 0.95
windingCubicMethod · 0.95
windingQuadraticMethod · 0.95
isInsideArcStrokeMethod · 0.95
windingArcMethod · 0.95
cosMethod · 0.80
sinMethod · 0.80

Tested by

no test coverage detected