mirror of
https://github.com/konvajs/konva.git
synced 2025-06-28 11:42:17 +08:00
Corrected Kinetic.Path.getPointOnLine() to work in negative x direction. Including Unit test.
This commit is contained in:
parent
90ba0d9a78
commit
869e420099
4
dist/kinetic-core.js
vendored
4
dist/kinetic-core.js
vendored
@ -3,7 +3,7 @@
|
|||||||
* http://www.kineticjs.com/
|
* http://www.kineticjs.com/
|
||||||
* Copyright 2012, Eric Rowell
|
* Copyright 2012, Eric Rowell
|
||||||
* Licensed under the MIT or GPL Version 2 licenses.
|
* Licensed under the MIT or GPL Version 2 licenses.
|
||||||
* Date: Sep 24 2012
|
* Date: Sep 25 2012
|
||||||
*
|
*
|
||||||
* Copyright (C) 2011 - 2012 by Eric Rowell
|
* Copyright (C) 2011 - 2012 by Eric Rowell
|
||||||
*
|
*
|
||||||
@ -5780,6 +5780,7 @@ Kinetic.Path.getPointOnLine = function(dist, P1x, P1y, P2x, P2y, fromX, fromY) {
|
|||||||
|
|
||||||
var m = (P2y - P1y) / ((P2x - P1x) + 0.00000001);
|
var m = (P2y - P1y) / ((P2x - P1x) + 0.00000001);
|
||||||
var run = Math.sqrt(dist * dist / (1 + m * m));
|
var run = Math.sqrt(dist * dist / (1 + m * m));
|
||||||
|
if(P2x < P1x) run *= -1;
|
||||||
var rise = m * run;
|
var rise = m * run;
|
||||||
var pt;
|
var pt;
|
||||||
|
|
||||||
@ -5804,6 +5805,7 @@ Kinetic.Path.getPointOnLine = function(dist, P1x, P1y, P2x, P2y, fromX, fromY) {
|
|||||||
var pRise = this.getLineLength(fromX, fromY, ix, iy);
|
var pRise = this.getLineLength(fromX, fromY, ix, iy);
|
||||||
var pRun = Math.sqrt(dist * dist - pRise * pRise);
|
var pRun = Math.sqrt(dist * dist - pRise * pRise);
|
||||||
run = Math.sqrt(pRun * pRun / (1 + m * m));
|
run = Math.sqrt(pRun * pRun / (1 + m * m));
|
||||||
|
if(P2x < P1x) run *= -1;
|
||||||
rise = m * run;
|
rise = m * run;
|
||||||
pt = {
|
pt = {
|
||||||
x: ix + run,
|
x: ix + run,
|
||||||
|
6
dist/kinetic-core.min.js
vendored
6
dist/kinetic-core.min.js
vendored
File diff suppressed because one or more lines are too long
@ -90,6 +90,7 @@ Kinetic.Path.getPointOnLine = function(dist, P1x, P1y, P2x, P2y, fromX, fromY) {
|
|||||||
|
|
||||||
var m = (P2y - P1y) / ((P2x - P1x) + 0.00000001);
|
var m = (P2y - P1y) / ((P2x - P1x) + 0.00000001);
|
||||||
var run = Math.sqrt(dist * dist / (1 + m * m));
|
var run = Math.sqrt(dist * dist / (1 + m * m));
|
||||||
|
if(P2x < P1x) run *= -1;
|
||||||
var rise = m * run;
|
var rise = m * run;
|
||||||
var pt;
|
var pt;
|
||||||
|
|
||||||
@ -114,6 +115,7 @@ Kinetic.Path.getPointOnLine = function(dist, P1x, P1y, P2x, P2y, fromX, fromY) {
|
|||||||
var pRise = this.getLineLength(fromX, fromY, ix, iy);
|
var pRise = this.getLineLength(fromX, fromY, ix, iy);
|
||||||
var pRun = Math.sqrt(dist * dist - pRise * pRise);
|
var pRun = Math.sqrt(dist * dist - pRise * pRise);
|
||||||
run = Math.sqrt(pRun * pRun / (1 + m * m));
|
run = Math.sqrt(pRun * pRun / (1 + m * m));
|
||||||
|
if(P2x < P1x) run *= -1;
|
||||||
rise = m * run;
|
rise = m * run;
|
||||||
pt = {
|
pt = {
|
||||||
x: ix + run,
|
x: ix + run,
|
||||||
|
@ -5794,6 +5794,51 @@ Test.prototype.tests = {
|
|||||||
layer.add(textpath);
|
layer.add(textpath);
|
||||||
stage.add(layer);
|
stage.add(layer);
|
||||||
},
|
},
|
||||||
|
'*PATH - getPointOnLine for different directions': function() {
|
||||||
|
var origo = {x: 0, y: 0};
|
||||||
|
|
||||||
|
var p, point;
|
||||||
|
|
||||||
|
//point up left
|
||||||
|
p = {x:-10, y: -10};
|
||||||
|
point = Kinetic.Path.getPointOnLine(10, origo.x, origo.y, p.x, p.y);
|
||||||
|
test(point.x < 0 && point.y < 0, 'The new point should be up left');
|
||||||
|
|
||||||
|
//point up right
|
||||||
|
p = {x:10, y: -10};
|
||||||
|
point = Kinetic.Path.getPointOnLine(10, origo.x, origo.y, p.x, p.y);
|
||||||
|
test(point.x > 0 && point.y < 0, 'The new point should be up right');
|
||||||
|
|
||||||
|
//point down right
|
||||||
|
p = {x:10, y: 10};
|
||||||
|
point = Kinetic.Path.getPointOnLine(10, origo.x, origo.y, p.x, p.y);
|
||||||
|
test(point.x > 0 && point.y > 0, 'The new point should be down right');
|
||||||
|
|
||||||
|
//point down left
|
||||||
|
p = {x:-10, y: 10};
|
||||||
|
point = Kinetic.Path.getPointOnLine(10, origo.x, origo.y, p.x, p.y);
|
||||||
|
test(point.x < 0 && point.y > 0, 'The new point should be down left');
|
||||||
|
|
||||||
|
//point left
|
||||||
|
p = {x:-10, y: 0};
|
||||||
|
point = Kinetic.Path.getPointOnLine(10, origo.x, origo.y, p.x, p.y);
|
||||||
|
test(point.x == -10 && point.y == 0, 'The new point should be left');
|
||||||
|
|
||||||
|
//point up
|
||||||
|
p = {x:0, y: -10};
|
||||||
|
point = Kinetic.Path.getPointOnLine(10, origo.x, origo.y, p.x, p.y);
|
||||||
|
test(Math.abs(point.x) < 0.0000001 && point.y == -10, 'The new point should be up');
|
||||||
|
|
||||||
|
//point right
|
||||||
|
p = {x:10, y: 0};
|
||||||
|
point = Kinetic.Path.getPointOnLine(10, origo.x, origo.y, p.x, p.y);
|
||||||
|
test(point.x == 10 && point.y == 0, 'The new point should be right');
|
||||||
|
|
||||||
|
//point down
|
||||||
|
p = {x:0, y: 10};
|
||||||
|
point = Kinetic.Path.getPointOnLine(10, origo.x, origo.y, p.x, p.y);
|
||||||
|
test(Math.abs(point.x) < 0.0000001 && point.y == 10, 'The new point should be down');
|
||||||
|
},
|
||||||
'PATH - Borneo Map (has scientific notation: -10e-4)': function(containerId) {
|
'PATH - Borneo Map (has scientific notation: -10e-4)': function(containerId) {
|
||||||
|
|
||||||
var stage = new Kinetic.Stage({
|
var stage = new Kinetic.Stage({
|
||||||
|
Loading…
Reference in New Issue
Block a user