Skip to content

Commit

Permalink
v1.2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
chanind committed Dec 8, 2018
1 parent 28d44a1 commit d531348
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 15 deletions.
45 changes: 40 additions & 5 deletions dist/hanzi-writer-lib.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* Hanzi Writer v1.2.0
* Hanzi Writer v1.2.1
* https://chanind.github.io/hanzi-writer
*/
module.exports =
Expand Down Expand Up @@ -421,12 +421,46 @@ var subdivideCurve = function subdivideCurve(curve) {
return newCurve;
};

// redraw the curve using numPoints equally spaced out along the length of the curve
var outlineCurve = function outlineCurve(curve) {
var numPoints = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 30;

var curveLen = length(curve);
var segmentLen = curveLen / (numPoints - 1);
var outlinePoints = [curve[0]];
var endPoint = arrLast(curve);
var remainingCurvePoints = curve.slice(1);
for (var i = 0; i < numPoints - 2; i++) {
var lastPoint = arrLast(outlinePoints);
var remainingDist = segmentLen;
var outlinePointFound = false;
while (!outlinePointFound) {
var nextPointDist = distance(lastPoint, remainingCurvePoints[0]);
if (nextPointDist < remainingDist) {
remainingDist -= nextPointDist;
lastPoint = remainingCurvePoints.shift();
} else {
var nextPoint = extendPointOnLine(lastPoint, remainingCurvePoints[0], remainingDist - nextPointDist);
outlinePoints.push(nextPoint);
outlinePointFound = true;
}
}
}
outlinePoints.push(endPoint);
return outlinePoints;
};

// translate and scale from https://en.wikipedia.org/wiki/Procrustes_analysis
var normalizeCurve = function normalizeCurve(curve) {
var meanX = average([curve[0].x, arrLast(curve).x]);
var meanY = average([curve[0].y, arrLast(curve).y]);
var outlinedCurve = outlineCurve(curve);
var meanX = average(outlinedCurve.map(function (point) {
return point.x;
}));
var meanY = average(outlinedCurve.map(function (point) {
return point.y;
}));
var mean = { x: meanX, y: meanY };
var translatedCurve = curve.map(function (point) {
var translatedCurve = outlinedCurve.map(function (point) {
return subtract(point, mean);
});
var scale = Math.sqrt(average([Math.pow(translatedCurve[0].x, 2) + Math.pow(translatedCurve[0].y, 2), Math.pow(arrLast(translatedCurve).x, 2) + Math.pow(arrLast(translatedCurve).y, 2)]));
Expand Down Expand Up @@ -473,6 +507,7 @@ module.exports = {
rotate: rotate,
subtract: subtract,
cosineSimilarity: cosineSimilarity,
outlineCurve: outlineCurve,
extendPointOnLine: extendPointOnLine,
filterParallelPoints: filterParallelPoints,
subdivideCurve: subdivideCurve,
Expand Down Expand Up @@ -1953,7 +1988,7 @@ var _require2 = __webpack_require__(2),
var AVG_DIST_THRESHOLD = 350; // bigger = more lenient
var COSINE_SIMILARITY_THRESHOLD = 0; // -1 to 1, smaller = more lenient
var START_AND_END_DIST_THRESHOLD = 250; // bigger = more lenient
var FRECHET_THRESHOLD = 0.75; // bigger = more lenient
var FRECHET_THRESHOLD = 0.40; // bigger = more lenient
var MIN_LEN_THRESHOLD = 0.35; // smalled = more lenient

var startAndEndMatches = function startAndEndMatches(points, closestStroke, leniency) {
Expand Down
4 changes: 2 additions & 2 deletions dist/hanzi-writer-lib.min.js

Large diffs are not rendered by default.

45 changes: 40 additions & 5 deletions dist/hanzi-writer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* Hanzi Writer v1.2.0
* Hanzi Writer v1.2.1
* https://chanind.github.io/hanzi-writer
*/
/******/ (function(modules) { // webpackBootstrap
Expand Down Expand Up @@ -420,12 +420,46 @@ var subdivideCurve = function subdivideCurve(curve) {
return newCurve;
};

// redraw the curve using numPoints equally spaced out along the length of the curve
var outlineCurve = function outlineCurve(curve) {
var numPoints = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 30;

var curveLen = length(curve);
var segmentLen = curveLen / (numPoints - 1);
var outlinePoints = [curve[0]];
var endPoint = arrLast(curve);
var remainingCurvePoints = curve.slice(1);
for (var i = 0; i < numPoints - 2; i++) {
var lastPoint = arrLast(outlinePoints);
var remainingDist = segmentLen;
var outlinePointFound = false;
while (!outlinePointFound) {
var nextPointDist = distance(lastPoint, remainingCurvePoints[0]);
if (nextPointDist < remainingDist) {
remainingDist -= nextPointDist;
lastPoint = remainingCurvePoints.shift();
} else {
var nextPoint = extendPointOnLine(lastPoint, remainingCurvePoints[0], remainingDist - nextPointDist);
outlinePoints.push(nextPoint);
outlinePointFound = true;
}
}
}
outlinePoints.push(endPoint);
return outlinePoints;
};

// translate and scale from https://en.wikipedia.org/wiki/Procrustes_analysis
var normalizeCurve = function normalizeCurve(curve) {
var meanX = average([curve[0].x, arrLast(curve).x]);
var meanY = average([curve[0].y, arrLast(curve).y]);
var outlinedCurve = outlineCurve(curve);
var meanX = average(outlinedCurve.map(function (point) {
return point.x;
}));
var meanY = average(outlinedCurve.map(function (point) {
return point.y;
}));
var mean = { x: meanX, y: meanY };
var translatedCurve = curve.map(function (point) {
var translatedCurve = outlinedCurve.map(function (point) {
return subtract(point, mean);
});
var scale = Math.sqrt(average([Math.pow(translatedCurve[0].x, 2) + Math.pow(translatedCurve[0].y, 2), Math.pow(arrLast(translatedCurve).x, 2) + Math.pow(arrLast(translatedCurve).y, 2)]));
Expand Down Expand Up @@ -472,6 +506,7 @@ module.exports = {
rotate: rotate,
subtract: subtract,
cosineSimilarity: cosineSimilarity,
outlineCurve: outlineCurve,
extendPointOnLine: extendPointOnLine,
filterParallelPoints: filterParallelPoints,
subdivideCurve: subdivideCurve,
Expand Down Expand Up @@ -1952,7 +1987,7 @@ var _require2 = __webpack_require__(2),
var AVG_DIST_THRESHOLD = 350; // bigger = more lenient
var COSINE_SIMILARITY_THRESHOLD = 0; // -1 to 1, smaller = more lenient
var START_AND_END_DIST_THRESHOLD = 250; // bigger = more lenient
var FRECHET_THRESHOLD = 0.75; // bigger = more lenient
var FRECHET_THRESHOLD = 0.40; // bigger = more lenient
var MIN_LEN_THRESHOLD = 0.35; // smalled = more lenient

var startAndEndMatches = function startAndEndMatches(points, closestStroke, leniency) {
Expand Down
4 changes: 2 additions & 2 deletions dist/hanzi-writer.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hanzi-writer",
"version": "1.2.0",
"version": "1.2.1",
"author": "David Chanin <[email protected]> (http://chanind.github.io/hanzi-writer/)",
"description": "Hanzi Writer is a free and open-source javascript library for both animating simplified Chinese characters and quizzing users on character stroke order.",
"repository": "chanind/hanzi-writer",
Expand Down

0 comments on commit d531348

Please sign in to comment.