@tisoap/react-flow-smart-edge
Advanced tools
Comparing version 0.2.0 to 0.2.1
@@ -288,7 +288,8 @@ 'use strict'; | ||
}); | ||
var path = []; | ||
var fullPath = []; | ||
var smoothedPath = []; | ||
try { | ||
path = finder.findPath(start.x, start.y, end.x, end.y, grid); | ||
path = pathfinding.Util.smoothenPath(grid, path); | ||
fullPath = finder.findPath(start.x, start.y, end.x, end.y, grid); | ||
smoothedPath = pathfinding.Util.smoothenPath(grid, fullPath); | ||
} catch (_unused) {// No path was found. This can happen if the end point is "surrounded" | ||
@@ -299,3 +300,6 @@ // by other nodes, or if the starting and ending nodes are on top of | ||
return path; | ||
return { | ||
fullPath: fullPath, | ||
smoothedPath: smoothedPath | ||
}; | ||
}; | ||
@@ -466,3 +470,9 @@ | ||
style = props.style, | ||
storeNodes = props.storeNodes; // We use the node's information to generate bounding boxes for them | ||
storeNodes = props.storeNodes, | ||
label = props.label, | ||
labelStyle = props.labelStyle, | ||
labelShowBg = props.labelShowBg, | ||
labelBgStyle = props.labelBgStyle, | ||
labelBgPadding = props.labelBgPadding, | ||
labelBgBorderRadius = props.labelBgBorderRadius; // We use the node's information to generate bounding boxes for them | ||
// and the graph | ||
@@ -492,11 +502,14 @@ | ||
var gridPath = generatePath(grid, start, end); | ||
var _generatePath = generatePath(grid, start, end), | ||
fullPath = _generatePath.fullPath, | ||
smoothedPath = _generatePath.smoothedPath; | ||
/* | ||
Fallback to BezierEdge if no path was found. | ||
length = 0: no path was found | ||
length = 1: starting and ending points are the same | ||
length = 2: a single straight line from point A to point B | ||
*/ | ||
Fallback to BezierEdge if no path was found. | ||
length = 0: no path was found | ||
length = 1: starting and ending points are the same | ||
length = 2: a single straight line from point A to point B | ||
*/ | ||
if (gridPath.length <= 2) { | ||
if (smoothedPath.length <= 2) { | ||
return React__default.createElement(reactFlowRenderer.BezierEdge, Object.assign({}, props)); | ||
@@ -506,3 +519,3 @@ } // Here we convert the grid path to a sequence of graph coordinates. | ||
var graphPath = gridPath.map(function (gridPoint) { | ||
var graphPath = smoothedPath.map(function (gridPoint) { | ||
var x = gridPoint[0], | ||
@@ -517,5 +530,27 @@ y = gridPoint[1]; | ||
var svgPathString = drawSmoothLinePath(source, target, graphPath); | ||
var svgPathString = drawSmoothLinePath(source, target, graphPath); // The Label, if any, should be placed in the middle of the path | ||
var _fullPath$Math$floor = fullPath[Math.floor(fullPath.length / 2)], | ||
middleX = _fullPath$Math$floor[0], | ||
middleY = _fullPath$Math$floor[1]; | ||
var _gridToGraphPoint = gridToGraphPoint({ | ||
x: middleX, | ||
y: middleY | ||
}, graph.xMin, graph.yMin), | ||
labelX = _gridToGraphPoint.x, | ||
labelY = _gridToGraphPoint.y; | ||
var text = label ? React__default.createElement(reactFlowRenderer.EdgeText, { | ||
x: labelX, | ||
y: labelY, | ||
label: label, | ||
labelStyle: labelStyle, | ||
labelShowBg: labelShowBg, | ||
labelBgStyle: labelBgStyle, | ||
labelBgPadding: labelBgPadding, | ||
labelBgBorderRadius: labelBgBorderRadius | ||
}) : null; | ||
var markerEnd = reactFlowRenderer.getMarkerEnd(arrowHeadType, markerEndId); | ||
return React__default.createElement("path", { | ||
return React__default.createElement(React__default.Fragment, null, React__default.createElement("path", { | ||
style: style, | ||
@@ -525,3 +560,3 @@ className: "react-flow__edge-path", | ||
markerEnd: markerEnd | ||
}); | ||
}), text); | ||
}); | ||
@@ -528,0 +563,0 @@ var DebouncedPathFindingEdge = /*#__PURE__*/React.memo(function (props) { |
@@ -1,2 +0,2 @@ | ||
"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var t=require("react"),r=e(t),n=e(require("react-use/lib/useDebounce")),o=require("react-flow-renderer"),i=require("pathfinding");function a(){return(a=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,arguments)}require("tiny-warning");var u=function(e,t){switch(t){case"top":return{x:e.x,y:e.y-1};case"bottom":return{x:e.x,y:e.y+1};case"left":return{x:e.x-1,y:e.y};case"right":return{x:e.x+1,y:e.y}}},s=function(e,t,r){for(var n=e.getNodeAt(t.x,t.y);!n.walkable;){e.setWalkableAt(n.x,n.y,!0);var o=u(n,r);n=e.getNodeAt(o.x,o.y)}},x=function(e,t,r){var n=e.x/10,o=e.y/10,i=t/10,a=r/10;if(i<1)for(;1!==i;)i++,n++;else if(i>1)for(;1!==i;)i--,n--;if(a<1)for(;1!==a;)a++,o++;else if(a>1)for(;1!==a;)a--,o--;return{x:n,y:o}},c=function(e,t){return void 0===t&&(t=10),Math.round(e/t)*t},d=function(e,t){return void 0===t&&(t=10),Math.floor(e/t)*t},f=function(e,t){return void 0===t&&(t=10),Math.ceil(e/t)*t},y={debounceTime:200},l=t.createContext(y),h=function(e){var t=e.value;return r.createElement(l.Provider,{value:void 0===t?y:t},e.children)},m=t.memo((function(e){var t=e.sourceX,n=e.sourceY,a=e.sourcePosition,y=e.targetX,l=e.targetY,h=e.targetPosition,m=e.arrowHeadType,v=e.markerEndId,g=e.style,b=function(e,t,r,n){void 0===t&&(t=0),void 0===r&&(r=0),void 0===n&&(n=0),t=Math.max(Math.round(t),0),r=Math.max(Math.round(r),0),n=Math.max(Math.round(n),0),t=Number.isInteger(t)?t:0,r=Number.isInteger(r)?r:0,n=Number.isInteger(n)?n:0;var o=Number.MIN_SAFE_INTEGER,i=Number.MIN_SAFE_INTEGER,a=Number.MAX_SAFE_INTEGER,u=Number.MAX_SAFE_INTEGER,s=e.map((function(e){var r,s,x=null==e?void 0:e.__rf,c=Math.max((null==x?void 0:x.width)||0,1),y=Math.max((null==x?void 0:x.height)||0,1),l=(null==x||null==(r=x.position)?void 0:r.x)||0,h=(null==x||null==(s=x.position)?void 0:s.y)||0,m={x:l-t,y:h-t},v={x:l-t,y:h+y+t},g={x:l+c+t,y:h-t},b={x:l+c+t,y:h+y+t};return n>0&&(m.x=d(m.x,n),m.y=d(m.y,n),v.x=d(v.x,n),v.y=f(v.y,n),g.x=f(g.x,n),g.y=d(g.y,n),b.x=f(b.x,n),b.y=f(b.y,n)),m.y<u&&(u=m.y),m.x<a&&(a=m.x),b.y>i&&(i=b.y),b.x>o&&(o=b.x),{id:e.id,width:c,height:y,topLeft:m,bottomLeft:v,topRight:g,bottomRight:b}})),x={x:a-=r,y:u-=r},c={x:a,y:i+=r},y={x:o+=r,y:u};return{nodes:s,graph:{topLeft:x,bottomLeft:c,topRight:y,bottomRight:{x:o,y:i},width:Math.abs(x.x-y.x),height:Math.abs(x.y-c.y),xMax:o,yMax:i,xMin:a,yMin:u}}}(e.storeNodes,10,20,10),p=b.graph,M={x:t,y:n,position:a},E={x:y,y:l,position:h},N=function(e,t,r,n){var o=e.xMin,a=e.yMin,d=new i.Grid(e.width/10,e.height/10);t.forEach((function(e){for(var t=x(e.topLeft,o,a),r=x(e.bottomRight,o,a),n=t.x;n<r.x;n++)for(var i=t.y;i<r.y;i++)d.setWalkableAt(n,i,!1)}));var f=x({x:c(r.x,10),y:c(r.y,10)},o,a),y=x({x:c(n.x,10),y:c(n.y,10)},o,a),l=d.getNodeAt(f.x,f.y);s(d,l,r.position);var h=d.getNodeAt(y.x,y.y);s(d,h,n.position);var m=u(l,r.position),v=u(h,n.position);return{grid:d,start:m,end:v}}(p,b.nodes,M,E),w=function(e,t,r){var n=new i.AStarFinder({diagonalMovement:i.DiagonalMovement.Always,allowDiagonal:!0,dontCrossCorners:!0}),o=[];try{o=n.findPath(t.x,t.y,r.x,r.y,e),o=i.Util.smoothenPath(e,o)}catch(e){}return o}(N.grid,N.start,N.end);if(w.length<=2)return r.createElement(o.BezierEdge,Object.assign({},e));var A=function(e,t,r){return function(e){for(var t=e[0],r=e[0],n="M"+r[0]+","+r[1]+"M",o=0;o<e.length;o++){var i=e[o],a=[(t[0]-(u=i[0]))/2+u,(t[1]-(s=i[1]))/2+s];n+=" "+a[0]+","+a[1],n+="Q"+i[0]+","+i[1],t=i}var u,s,x=e[e.length-1];return n+" "+x[0]+","+x[1]}([[e.x,e.y]].concat(r,[[t.x,t.y]]))}(M,E,w.map((function(e){var t=function(e,t,r){var n=10*e.x,o=10*e.y,i=t,a=r;if(i<10)for(;10!==i;)i+=10,n-=10;else if(i>10)for(;10!==i;)i-=10,n+=10;if(a<10)for(;10!==a;)a+=10,o-=10;else if(a>10)for(;10!==a;)a-=10,o+=10;return{x:n,y:o}}({x:e[0],y:e[1]},p.xMin,p.yMin);return[t.x,t.y]}))),S=o.getMarkerEnd(m,v);return r.createElement("path",{style:g,className:"react-flow__edge-path",d:A,markerEnd:S})})),v=t.memo((function(e){var i=o.useStoreState((function(e){return e.nodes})),u=function(){var e=t.useContext(l);if(void 0===e)throw new Error("useSmartEdge must be used within a SmartEdgeProvider");return e}().debounceTime,s=t.useState(a({storeNodes:i},e)),x=s[0],c=s[1];return n((function(){c(a({storeNodes:i},e))}),u,[e,i]),r.createElement(m,Object.assign({},x))})),g=t.memo((function(e){var t=o.useStoreState((function(e){return e.nodes}));return r.createElement(m,Object.assign({storeNodes:t},e))})),b=t.memo((function(e){var n=t.useContext(l);return n?r.createElement(0===n.debounceTime?g:v,Object.assign({},e)):r.createElement(h,null,r.createElement(v,Object.assign({},e)),";")}));exports.SmartEdge=b,exports.SmartEdgeProvider=h,exports.default=b; | ||
"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var t=require("react"),r=e(t),n=e(require("react-use/lib/useDebounce")),o=require("react-flow-renderer"),a=require("pathfinding");function i(){return(i=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,arguments)}require("tiny-warning");var u=function(e,t){switch(t){case"top":return{x:e.x,y:e.y-1};case"bottom":return{x:e.x,y:e.y+1};case"left":return{x:e.x-1,y:e.y};case"right":return{x:e.x+1,y:e.y}}},l=function(e,t,r){for(var n=e.getNodeAt(t.x,t.y);!n.walkable;){e.setWalkableAt(n.x,n.y,!0);var o=u(n,r);n=e.getNodeAt(o.x,o.y)}},s=function(e,t,r){var n=e.x/10,o=e.y/10,a=t/10,i=r/10;if(a<1)for(;1!==a;)a++,n++;else if(a>1)for(;1!==a;)a--,n--;if(i<1)for(;1!==i;)i++,o++;else if(i>1)for(;1!==i;)i--,o--;return{x:n,y:o}},d=function(e,t,r){var n=10*e.x,o=10*e.y,a=t,i=r;if(a<10)for(;10!==a;)a+=10,n-=10;else if(a>10)for(;10!==a;)a-=10,n+=10;if(i<10)for(;10!==i;)i+=10,o-=10;else if(i>10)for(;10!==i;)i-=10,o+=10;return{x:n,y:o}},x=function(e,t){return void 0===t&&(t=10),Math.round(e/t)*t},y=function(e,t){return void 0===t&&(t=10),Math.floor(e/t)*t},c=function(e,t){return void 0===t&&(t=10),Math.ceil(e/t)*t},f={debounceTime:200},h=t.createContext(f),g=function(e){var t=e.value;return r.createElement(h.Provider,{value:void 0===t?f:t},e.children)},m=t.memo((function(e){var t=e.sourceX,n=e.sourceY,i=e.sourcePosition,f=e.targetX,h=e.targetY,g=e.targetPosition,m=e.arrowHeadType,v=e.markerEndId,b=e.style,M=e.label,p=e.labelStyle,E=e.labelShowBg,N=e.labelBgStyle,w=e.labelBgPadding,S=e.labelBgBorderRadius,P=function(e,t,r,n){void 0===t&&(t=0),void 0===r&&(r=0),void 0===n&&(n=0),t=Math.max(Math.round(t),0),r=Math.max(Math.round(r),0),n=Math.max(Math.round(n),0),t=Number.isInteger(t)?t:0,r=Number.isInteger(r)?r:0,n=Number.isInteger(n)?n:0;var o=Number.MIN_SAFE_INTEGER,a=Number.MIN_SAFE_INTEGER,i=Number.MAX_SAFE_INTEGER,u=Number.MAX_SAFE_INTEGER,l=e.map((function(e){var r,l,s=null==e?void 0:e.__rf,d=Math.max((null==s?void 0:s.width)||0,1),x=Math.max((null==s?void 0:s.height)||0,1),f=(null==s||null==(r=s.position)?void 0:r.x)||0,h=(null==s||null==(l=s.position)?void 0:l.y)||0,g={x:f-t,y:h-t},m={x:f-t,y:h+x+t},v={x:f+d+t,y:h-t},b={x:f+d+t,y:h+x+t};return n>0&&(g.x=y(g.x,n),g.y=y(g.y,n),m.x=y(m.x,n),m.y=c(m.y,n),v.x=c(v.x,n),v.y=y(v.y,n),b.x=c(b.x,n),b.y=c(b.y,n)),g.y<u&&(u=g.y),g.x<i&&(i=g.x),b.y>a&&(a=b.y),b.x>o&&(o=b.x),{id:e.id,width:d,height:x,topLeft:g,bottomLeft:m,topRight:v,bottomRight:b}})),s={x:i-=r,y:u-=r},d={x:i,y:a+=r},x={x:o+=r,y:u};return{nodes:l,graph:{topLeft:s,bottomLeft:d,topRight:x,bottomRight:{x:o,y:a},width:Math.abs(s.x-x.x),height:Math.abs(s.y-d.y),xMax:o,yMax:a,xMin:i,yMin:u}}}(e.storeNodes,10,20,10),A=P.graph,_={x:t,y:n,position:i},B={x:f,y:h,position:g},R=function(e,t,r,n){var o=e.xMin,i=e.yMin,d=new a.Grid(e.width/10,e.height/10);t.forEach((function(e){for(var t=s(e.topLeft,o,i),r=s(e.bottomRight,o,i),n=t.x;n<r.x;n++)for(var a=t.y;a<r.y;a++)d.setWalkableAt(n,a,!1)}));var y=s({x:x(r.x,10),y:x(r.y,10)},o,i),c=s({x:x(n.x,10),y:x(n.y,10)},o,i),f=d.getNodeAt(y.x,y.y);l(d,f,r.position);var h=d.getNodeAt(c.x,c.y);l(d,h,n.position);var g=u(f,r.position),m=u(h,n.position);return{grid:d,start:g,end:m}}(A,P.nodes,_,B),I=function(e,t,r){var n=new a.AStarFinder({diagonalMovement:a.DiagonalMovement.Always,allowDiagonal:!0,dontCrossCorners:!0}),o=[],i=[];try{o=n.findPath(t.x,t.y,r.x,r.y,e),i=a.Util.smoothenPath(e,o)}catch(e){}return{fullPath:o,smoothedPath:i}}(R.grid,R.start,R.end),j=I.fullPath,O=I.smoothedPath;if(O.length<=2)return r.createElement(o.BezierEdge,Object.assign({},e));var T=function(e,t,r){return function(e){for(var t=e[0],r=e[0],n="M"+r[0]+","+r[1]+"M",o=0;o<e.length;o++){var a=e[o],i=[(t[0]-(u=a[0]))/2+u,(t[1]-(l=a[1]))/2+l];n+=" "+i[0]+","+i[1],n+="Q"+a[0]+","+a[1],t=a}var u,l,s=e[e.length-1];return n+" "+s[0]+","+s[1]}([[e.x,e.y]].concat(r,[[t.x,t.y]]))}(_,B,O.map((function(e){var t=d({x:e[0],y:e[1]},A.xMin,A.yMin);return[t.x,t.y]}))),k=j[Math.floor(j.length/2)],F=d({x:k[0],y:k[1]},A.xMin,A.yMin),q=M?r.createElement(o.EdgeText,{x:F.x,y:F.y,label:M,labelStyle:p,labelShowBg:E,labelBgStyle:N,labelBgPadding:w,labelBgBorderRadius:S}):null,C=o.getMarkerEnd(m,v);return r.createElement(r.Fragment,null,r.createElement("path",{style:b,className:"react-flow__edge-path",d:T,markerEnd:C}),q)})),v=t.memo((function(e){var a=o.useStoreState((function(e){return e.nodes})),u=function(){var e=t.useContext(h);if(void 0===e)throw new Error("useSmartEdge must be used within a SmartEdgeProvider");return e}().debounceTime,l=t.useState(i({storeNodes:a},e)),s=l[0],d=l[1];return n((function(){d(i({storeNodes:a},e))}),u,[e,a]),r.createElement(m,Object.assign({},s))})),b=t.memo((function(e){var t=o.useStoreState((function(e){return e.nodes}));return r.createElement(m,Object.assign({storeNodes:t},e))})),M=t.memo((function(e){var n=t.useContext(h);return n?r.createElement(0===n.debounceTime?b:v,Object.assign({},e)):r.createElement(g,null,r.createElement(v,Object.assign({},e)),";")}));exports.SmartEdge=M,exports.SmartEdgeProvider=g,exports.default=M; | ||
//# sourceMappingURL=react-flow-smart-edge.cjs.production.min.js.map |
import React, { createContext, useContext, memo, useState } from 'react'; | ||
import useDebounce from 'react-use/lib/useDebounce'; | ||
import { useStoreState, BezierEdge, getMarkerEnd } from 'react-flow-renderer'; | ||
import { useStoreState, BezierEdge, EdgeText, getMarkerEnd } from 'react-flow-renderer'; | ||
import { Grid, AStarFinder, DiagonalMovement, Util } from 'pathfinding'; | ||
@@ -281,7 +281,8 @@ import warning from 'tiny-warning'; | ||
}); | ||
var path = []; | ||
var fullPath = []; | ||
var smoothedPath = []; | ||
try { | ||
path = finder.findPath(start.x, start.y, end.x, end.y, grid); | ||
path = Util.smoothenPath(grid, path); | ||
fullPath = finder.findPath(start.x, start.y, end.x, end.y, grid); | ||
smoothedPath = Util.smoothenPath(grid, fullPath); | ||
} catch (_unused) {// No path was found. This can happen if the end point is "surrounded" | ||
@@ -292,3 +293,6 @@ // by other nodes, or if the starting and ending nodes are on top of | ||
return path; | ||
return { | ||
fullPath: fullPath, | ||
smoothedPath: smoothedPath | ||
}; | ||
}; | ||
@@ -459,3 +463,9 @@ | ||
style = props.style, | ||
storeNodes = props.storeNodes; // We use the node's information to generate bounding boxes for them | ||
storeNodes = props.storeNodes, | ||
label = props.label, | ||
labelStyle = props.labelStyle, | ||
labelShowBg = props.labelShowBg, | ||
labelBgStyle = props.labelBgStyle, | ||
labelBgPadding = props.labelBgPadding, | ||
labelBgBorderRadius = props.labelBgBorderRadius; // We use the node's information to generate bounding boxes for them | ||
// and the graph | ||
@@ -485,11 +495,14 @@ | ||
var gridPath = generatePath(grid, start, end); | ||
var _generatePath = generatePath(grid, start, end), | ||
fullPath = _generatePath.fullPath, | ||
smoothedPath = _generatePath.smoothedPath; | ||
/* | ||
Fallback to BezierEdge if no path was found. | ||
length = 0: no path was found | ||
length = 1: starting and ending points are the same | ||
length = 2: a single straight line from point A to point B | ||
*/ | ||
Fallback to BezierEdge if no path was found. | ||
length = 0: no path was found | ||
length = 1: starting and ending points are the same | ||
length = 2: a single straight line from point A to point B | ||
*/ | ||
if (gridPath.length <= 2) { | ||
if (smoothedPath.length <= 2) { | ||
return React.createElement(BezierEdge, Object.assign({}, props)); | ||
@@ -499,3 +512,3 @@ } // Here we convert the grid path to a sequence of graph coordinates. | ||
var graphPath = gridPath.map(function (gridPoint) { | ||
var graphPath = smoothedPath.map(function (gridPoint) { | ||
var x = gridPoint[0], | ||
@@ -510,5 +523,27 @@ y = gridPoint[1]; | ||
var svgPathString = drawSmoothLinePath(source, target, graphPath); | ||
var svgPathString = drawSmoothLinePath(source, target, graphPath); // The Label, if any, should be placed in the middle of the path | ||
var _fullPath$Math$floor = fullPath[Math.floor(fullPath.length / 2)], | ||
middleX = _fullPath$Math$floor[0], | ||
middleY = _fullPath$Math$floor[1]; | ||
var _gridToGraphPoint = gridToGraphPoint({ | ||
x: middleX, | ||
y: middleY | ||
}, graph.xMin, graph.yMin), | ||
labelX = _gridToGraphPoint.x, | ||
labelY = _gridToGraphPoint.y; | ||
var text = label ? React.createElement(EdgeText, { | ||
x: labelX, | ||
y: labelY, | ||
label: label, | ||
labelStyle: labelStyle, | ||
labelShowBg: labelShowBg, | ||
labelBgStyle: labelBgStyle, | ||
labelBgPadding: labelBgPadding, | ||
labelBgBorderRadius: labelBgBorderRadius | ||
}) : null; | ||
var markerEnd = getMarkerEnd(arrowHeadType, markerEndId); | ||
return React.createElement("path", { | ||
return React.createElement(React.Fragment, null, React.createElement("path", { | ||
style: style, | ||
@@ -518,3 +553,3 @@ className: "react-flow__edge-path", | ||
markerEnd: markerEnd | ||
}); | ||
}), text); | ||
}); | ||
@@ -521,0 +556,0 @@ var DebouncedPathFindingEdge = /*#__PURE__*/memo(function (props) { |
@@ -11,2 +11,5 @@ import type { Grid } from 'pathfinding'; | ||
} | ||
export declare const generatePath: (grid: Grid, start: XYPosition, end: XYPosition) => number[][]; | ||
export declare const generatePath: (grid: Grid, start: XYPosition, end: XYPosition) => { | ||
fullPath: number[][]; | ||
smoothedPath: number[][]; | ||
}; |
{ | ||
"name": "@tisoap/react-flow-smart-edge", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"keywords": [ | ||
@@ -31,3 +31,3 @@ "react", | ||
"build-storybook": "build-storybook", | ||
"lint": "tsdx lint --fix", | ||
"lint": "tsdx lint src test stories --fix", | ||
"prepare": "tsdx build", | ||
@@ -48,2 +48,4 @@ "release": "np", | ||
"singleQuote": true, | ||
"tabWidth": 2, | ||
"tabs": false, | ||
"trailingComma": "es5" | ||
@@ -50,0 +52,0 @@ }, |
@@ -19,3 +19,3 @@ import { AStarFinder, Util, DiagonalMovement } from 'pathfinding'; | ||
end: XYPosition | ||
): number[][] => { | ||
) => { | ||
const finder = new AStarFinder({ | ||
@@ -27,7 +27,8 @@ diagonalMovement: DiagonalMovement.Always, | ||
let path: number[][] = []; | ||
let fullPath: number[][] = []; | ||
let smoothedPath: number[][] = []; | ||
try { | ||
path = finder.findPath(start.x, start.y, end.x, end.y, grid); | ||
path = Util.smoothenPath(grid, path); | ||
fullPath = finder.findPath(start.x, start.y, end.x, end.y, grid); | ||
smoothedPath = Util.smoothenPath(grid, fullPath); | ||
} catch { | ||
@@ -39,3 +40,3 @@ // No path was found. This can happen if the end point is "surrounded" | ||
return path; | ||
return { fullPath, smoothedPath }; | ||
}; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
175053
1825