- Breaking change: Rename "svgutils.js" to "utilities.js" (make in conformity with JSDoc module naming convention) - Breaking change: Rename "svgedit.js" to "namespaces.js" (to make clear purpose and avoid confusing with editor) - Breaking change: Rename "jquery-svg.js" to "jQuery.attr.js" - Breaking change: Rename "jquery.contextMenu.js" to "jQuery.contextMenu.js" - Breaking change: Rename "jquery.jpicker.js" to "jQuery.jPicker.js" - Breaking change: Rename "JQuerySpinBtn.css" to "jQuery.SpinButton.css" - Breaking change: Rename "JQuerySpinBtn.js" to "jQuery.SpinButton.js" (to have file name more closely reflect name) - Breaking change: Rename "jquery.svgicons.js" to "jQuery.svgIcons.js" - Breaking change: Rename "jquery.jgraduate.js" to "jQuery.jGraduate.js" - Breaking change: Rename "pathseg.js" to "svgpathseg.js" (as it is a poyfill of SVGPathSeg) - Breaking change: Rename `addSvgElementFromJson()` to `addSVGElementFromJson` for consistency - Breaking change: Rename `changeSvgContent()` to `changeSVGContent()` for consistency - Breaking change: Have `exportPDF` resolve with `output` and `outputType` rather than `dataurlstring` (as type may vary) - Breaking change: Rename `extensions/mathjax/MathJax.js` to `extensions/mathjax/MathJax.min.js` - Breaking change: Avoid recent change to have editor ready callbacks return Promises (we're not using and advantageous to keep sequential) - Breaking change: Avoid recent addition of locale-side function in ext-imagelib for l10n - Breaking change: Change name of ext-arrows.js from `Arrows` to `arrows` for sake of file path (not localized anyways). - Breaking change: Change `addlangData` extension event to `addLangData` for consistency with method name - Breaking change: Have `readLang` return lang and data but do not call `setLang` - Fix: Have general locales load first so extensions may use - Fix: Provide `importLocale` to extensions `init` so it may delay adding of the extension until locale data loaded - Fix: Ensure call to `rasterExport` without `imgType` properly sets MIME type to PNG - Fix: Wrong name for moinsave - Update: Update WebAppFind per new API changes - Enhancement: Make `setStrings` public on editor for late setting (used by `ext-shapes.js`) - Enhancement: Add `extensions_added` event - Enhancement: Add `message` event (Relay messages including those which have been been received prior to extension load) - Enhancement: Allow SVGEdit to work out of the box--avoid need for copying sample config file. Should also help with Github-based file servers - Enhancement: Allow avoiding "name" in extension export (just extract out of file name) - Enhancement: Add stack blur to canvg by default (and refactoring it) - Enhancement: Return `Promise` for `embedImage` (as with some other loading methods) - Enhancement: Supply `importLocale` to `langReady` to facilitate extension locale loading - Enhancement: Recover if an extension fails to load (just log and otherwise ignore) - Enhancement: More i18n of extensions (also fixed issue with some console warnings about missing locale strings); i18nize Hello World too - Enhancement: Allowing importing of locales within `addLangData` - npm: Update devDeps - Docs: Migrate copies of all old wiki pages to docs/from-old-wiki folder; intended for a possible move to Markdown, so raw HTML (with formatting) was not preserved, though named links had their absolute URL links preserved - Docs: Begin deleting `SvgCanvas.md` as ensuring jsdoc has replacements - Docs: Add Edtior doc file for help to general users - Docs: Clarify/simplify install instructions - npm/Docs (JSDoc): Add script to check for overly generic types - Docs (JSDoc): For config/prefs and extension creating, link to tutorials (moved tutorials to own directory to avoid recursion problems by jsdoc) - Docs (JSDoc): Add modules (upper case for usual main entrance files or regular names) - Docs (JSDoc): Fill out missing areas; indicate return of `undefined`; consistency with `@returns` - Docs (JSDoc): Add our own layout template to support overflow - Docs (JSDoc): Use cleverLinks and disallow unknown tags - Docs (JSDoc): Insist on "pedantic" flag; put output directory in config - Docs (JSDoc): Use more precise Integer/Float over number, the specific type of array/function/object - Docs (JSDoc): Use `@throws`, `@enum`, `@event`/`@fires`/`@listens` - Docs: Generally update/improve docs (fixes #92) - Docs: Update links to `latest` path (Avoid needing to update such references upon each release) - Docs: 80 chars max - Refactoring: Drop code for extension as function (already requiring export to be an object) - Refactoring: Object destructuring, `Object.entries`, Object shorthand, array extras, more camelCase variable names - Refactoring: Add a `Command` base class - Refactoring: Simplify svgicons `callback` ready detection - Refactoring: Put `let` or `const` closer to scope - Refactoring: Remove unneeded `delimiter` from regex escaping utility - Refactoring: Clearer variable names - Refactoring: Use (non-deprecated) Event constructors - Testing: Use new Sinon
122 lines
3.8 KiB
JavaScript
122 lines
3.8 KiB
JavaScript
/* eslint-env qunit */
|
|
import {NS} from '../editor/namespaces.js';
|
|
import * as math from '../editor/math.js';
|
|
|
|
// log function
|
|
QUnit.log((details) => {
|
|
if (window.console && window.console.log) {
|
|
window.console.log(details.result + ' :: ' + details.message);
|
|
}
|
|
});
|
|
|
|
const svg = document.createElementNS(NS.SVG, 'svg');
|
|
|
|
QUnit.module('svgedit.math');
|
|
|
|
QUnit.test('Test svgedit.math package', function (assert) {
|
|
assert.expect(7);
|
|
|
|
assert.ok(math);
|
|
assert.ok(math.transformPoint);
|
|
assert.ok(math.isIdentity);
|
|
assert.ok(math.matrixMultiply);
|
|
assert.equal(typeof math.transformPoint, typeof function () {});
|
|
assert.equal(typeof math.isIdentity, typeof function () {});
|
|
assert.equal(typeof math.matrixMultiply, typeof function () {});
|
|
});
|
|
|
|
QUnit.test('Test svgedit.math.transformPoint() function', function (assert) {
|
|
assert.expect(6);
|
|
const {transformPoint} = math;
|
|
|
|
const m = svg.createSVGMatrix();
|
|
m.a = 1; m.b = 0;
|
|
m.c = 0; m.d = 1;
|
|
m.e = 0; m.f = 0;
|
|
let pt = transformPoint(100, 200, m);
|
|
assert.equal(pt.x, 100);
|
|
assert.equal(pt.y, 200);
|
|
|
|
m.e = 300; m.f = 400;
|
|
pt = transformPoint(100, 200, m);
|
|
assert.equal(pt.x, 400);
|
|
assert.equal(pt.y, 600);
|
|
|
|
m.a = 0.5; m.b = 0.75;
|
|
m.c = 1.25; m.d = 2;
|
|
pt = transformPoint(100, 200, m);
|
|
assert.equal(pt.x, 100 * m.a + 200 * m.c + m.e);
|
|
assert.equal(pt.y, 100 * m.b + 200 * m.d + m.f);
|
|
});
|
|
|
|
QUnit.test('Test svgedit.math.isIdentity() function', function (assert) {
|
|
assert.expect(2);
|
|
|
|
assert.ok(math.isIdentity(svg.createSVGMatrix()));
|
|
|
|
const m = svg.createSVGMatrix();
|
|
m.a = 1; m.b = 0;
|
|
m.c = 0; m.d = 1;
|
|
m.e = 0; m.f = 0;
|
|
assert.ok(math.isIdentity(m));
|
|
});
|
|
|
|
QUnit.test('Test svgedit.math.matrixMultiply() function', function (assert) {
|
|
assert.expect(5);
|
|
const mult = math.matrixMultiply;
|
|
const {isIdentity} = math;
|
|
|
|
// translate there and back
|
|
const tr1 = svg.createSVGMatrix().translate(100, 50),
|
|
tr2 = svg.createSVGMatrix().translate(-90, 0),
|
|
tr3 = svg.createSVGMatrix().translate(-10, -50);
|
|
let I = mult(tr1, tr2, tr3);
|
|
assert.ok(isIdentity(I), 'Expected identity matrix when translating there and back');
|
|
|
|
// rotate there and back
|
|
// TODO: currently Mozilla fails this when rotating back at -50 and then -40 degrees
|
|
// (b and c are *almost* zero, but not zero)
|
|
const rotThere = svg.createSVGMatrix().rotate(90),
|
|
rotBack = svg.createSVGMatrix().rotate(-90), // TODO: set this to -50
|
|
rotBackMore = svg.createSVGMatrix().rotate(0); // TODO: set this to -40
|
|
I = mult(rotThere, rotBack, rotBackMore);
|
|
assert.ok(isIdentity(I), 'Expected identity matrix when rotating there and back');
|
|
|
|
// scale up and down
|
|
const scaleUp = svg.createSVGMatrix().scale(4),
|
|
scaleDown = svg.createSVGMatrix().scaleNonUniform(0.25, 1),
|
|
scaleDownMore = svg.createSVGMatrix().scaleNonUniform(1, 0.25);
|
|
I = mult(scaleUp, scaleDown, scaleDownMore);
|
|
assert.ok(isIdentity(I), 'Expected identity matrix when scaling up and down');
|
|
|
|
// test multiplication with its inverse
|
|
I = mult(rotThere, rotThere.inverse());
|
|
assert.ok(isIdentity(I), 'Expected identity matrix when multiplying a matrix by its inverse');
|
|
I = mult(rotThere.inverse(), rotThere);
|
|
assert.ok(isIdentity(I), 'Expected identity matrix when multiplying a matrix by its inverse');
|
|
});
|
|
|
|
QUnit.test('Test svgedit.math.transformBox() function', function (assert) {
|
|
assert.expect(12);
|
|
const {transformBox} = math;
|
|
|
|
const m = svg.createSVGMatrix();
|
|
m.a = 1; m.b = 0;
|
|
m.c = 0; m.d = 1;
|
|
m.e = 0; m.f = 0;
|
|
|
|
const r = transformBox(10, 10, 200, 300, m);
|
|
assert.equal(r.tl.x, 10);
|
|
assert.equal(r.tl.y, 10);
|
|
assert.equal(r.tr.x, 210);
|
|
assert.equal(r.tr.y, 10);
|
|
assert.equal(r.bl.x, 10);
|
|
assert.equal(r.bl.y, 310);
|
|
assert.equal(r.br.x, 210);
|
|
assert.equal(r.br.y, 310);
|
|
assert.equal(r.aabox.x, 10);
|
|
assert.equal(r.aabox.y, 10);
|
|
assert.equal(r.aabox.width, 200);
|
|
assert.equal(r.aabox.height, 300);
|
|
});
|