2010-10-22 02:54:00 +00:00
|
|
|
(function(global) {
|
2012-06-26 14:42:45 +00:00
|
|
|
|
2014-02-16 21:36:03 +00:00
|
|
|
'use strict';
|
2012-06-26 14:42:45 +00:00
|
|
|
|
2010-10-22 02:54:00 +00:00
|
|
|
var fabric = global.fabric || (global.fabric = { }),
|
2011-09-19 21:48:16 +00:00
|
|
|
extend = fabric.util.object.extend,
|
2016-12-30 21:41:16 +00:00
|
|
|
clone = fabric.util.object.clone,
|
2014-02-16 21:36:03 +00:00
|
|
|
coordProps = { x1: 1, x2: 1, y1: 1, y2: 1 },
|
2013-05-05 00:29:59 +00:00
|
|
|
supportsLineDash = fabric.StaticCanvas.supports('setLineDash');
|
2012-06-26 14:42:45 +00:00
|
|
|
|
2010-07-09 23:43:50 +00:00
|
|
|
if (fabric.Line) {
|
2010-10-14 21:42:39 +00:00
|
|
|
fabric.warn('fabric.Line is already defined');
|
2010-06-10 17:57:59 +00:00
|
|
|
return;
|
|
|
|
|
}
|
2012-06-26 14:42:45 +00:00
|
|
|
|
2016-12-03 21:53:51 +00:00
|
|
|
var cacheProperties = fabric.Object.prototype.cacheProperties.concat();
|
|
|
|
|
cacheProperties.push(
|
|
|
|
|
'x1',
|
|
|
|
|
'x2',
|
|
|
|
|
'y1',
|
|
|
|
|
'y2'
|
|
|
|
|
);
|
|
|
|
|
|
2012-06-26 14:42:45 +00:00
|
|
|
/**
|
2012-12-13 14:36:43 +00:00
|
|
|
* Line class
|
2013-04-25 18:21:32 +00:00
|
|
|
* @class fabric.Line
|
2010-10-14 21:42:39 +00:00
|
|
|
* @extends fabric.Object
|
2013-10-05 18:21:28 +00:00
|
|
|
* @see {@link fabric.Line#initialize} for constructor definition
|
2010-10-14 21:42:39 +00:00
|
|
|
*/
|
2013-04-24 16:58:04 +00:00
|
|
|
fabric.Line = fabric.util.createClass(fabric.Object, /** @lends fabric.Line.prototype */ {
|
2012-06-26 14:42:45 +00:00
|
|
|
|
2010-10-15 02:16:24 +00:00
|
|
|
/**
|
2012-12-13 14:36:43 +00:00
|
|
|
* Type of an object
|
2010-10-15 02:16:24 +00:00
|
|
|
* @type String
|
2013-05-18 11:01:34 +00:00
|
|
|
* @default
|
2010-10-15 02:16:24 +00:00
|
|
|
*/
|
2010-06-09 22:34:55 +00:00
|
|
|
type: 'line',
|
2012-06-26 14:42:45 +00:00
|
|
|
|
2014-01-23 15:48:37 +00:00
|
|
|
/**
|
|
|
|
|
* x value or first line edge
|
|
|
|
|
* @type Number
|
|
|
|
|
* @default
|
|
|
|
|
*/
|
2014-01-18 17:01:19 +00:00
|
|
|
x1: 0,
|
2014-01-23 15:48:37 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* y value or first line edge
|
|
|
|
|
* @type Number
|
|
|
|
|
* @default
|
|
|
|
|
*/
|
2014-01-18 17:01:19 +00:00
|
|
|
y1: 0,
|
|
|
|
|
|
2014-01-23 15:48:37 +00:00
|
|
|
/**
|
|
|
|
|
* x value or second line edge
|
|
|
|
|
* @type Number
|
|
|
|
|
* @default
|
|
|
|
|
*/
|
2014-01-18 17:01:19 +00:00
|
|
|
x2: 0,
|
2014-01-23 15:48:37 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* y value or second line edge
|
|
|
|
|
* @type Number
|
|
|
|
|
* @default
|
|
|
|
|
*/
|
2014-01-18 17:01:19 +00:00
|
|
|
y2: 0,
|
|
|
|
|
|
2016-12-03 21:53:51 +00:00
|
|
|
cacheProperties: cacheProperties,
|
|
|
|
|
|
2010-06-09 22:34:55 +00:00
|
|
|
/**
|
2010-10-14 21:42:39 +00:00
|
|
|
* Constructor
|
2012-12-15 16:05:23 +00:00
|
|
|
* @param {Array} [points] Array of points
|
2010-10-14 21:42:39 +00:00
|
|
|
* @param {Object} [options] Options object
|
|
|
|
|
* @return {fabric.Line} thisArg
|
2010-06-09 22:34:55 +00:00
|
|
|
*/
|
|
|
|
|
initialize: function(points, options) {
|
|
|
|
|
if (!points) {
|
|
|
|
|
points = [0, 0, 0, 0];
|
|
|
|
|
}
|
2012-06-26 14:42:45 +00:00
|
|
|
|
2010-06-09 22:34:55 +00:00
|
|
|
this.callSuper('initialize', options);
|
2012-06-26 14:42:45 +00:00
|
|
|
|
2010-06-09 22:34:55 +00:00
|
|
|
this.set('x1', points[0]);
|
|
|
|
|
this.set('y1', points[1]);
|
|
|
|
|
this.set('x2', points[2]);
|
|
|
|
|
this.set('y2', points[3]);
|
2012-06-26 14:42:45 +00:00
|
|
|
|
2012-06-28 18:36:55 +00:00
|
|
|
this._setWidthHeight(options);
|
2011-09-19 21:48:16 +00:00
|
|
|
},
|
2012-06-26 14:42:45 +00:00
|
|
|
|
2012-08-09 10:24:22 +00:00
|
|
|
/**
|
|
|
|
|
* @private
|
2012-12-13 14:36:43 +00:00
|
|
|
* @param {Object} [options] Options
|
2012-08-09 10:24:22 +00:00
|
|
|
*/
|
2012-06-28 18:36:55 +00:00
|
|
|
_setWidthHeight: function(options) {
|
|
|
|
|
options || (options = { });
|
|
|
|
|
|
2014-11-10 10:53:30 +00:00
|
|
|
this.width = Math.abs(this.x2 - this.x1);
|
|
|
|
|
this.height = Math.abs(this.y2 - this.y1);
|
2012-06-28 19:14:19 +00:00
|
|
|
|
2014-01-17 16:57:31 +00:00
|
|
|
this.left = 'left' in options
|
|
|
|
|
? options.left
|
2014-02-05 14:42:52 +00:00
|
|
|
: this._getLeftToOriginX();
|
2014-01-17 16:57:31 +00:00
|
|
|
|
|
|
|
|
this.top = 'top' in options
|
|
|
|
|
? options.top
|
2014-02-05 14:42:52 +00:00
|
|
|
: this._getTopToOriginY();
|
2010-06-09 22:34:55 +00:00
|
|
|
},
|
2012-06-26 14:42:45 +00:00
|
|
|
|
2012-08-09 10:24:22 +00:00
|
|
|
/**
|
|
|
|
|
* @private
|
|
|
|
|
* @param {String} key
|
2016-08-20 10:05:19 +00:00
|
|
|
* @param {*} value
|
2012-08-09 10:24:22 +00:00
|
|
|
*/
|
|
|
|
|
_set: function(key, value) {
|
2014-09-30 19:11:45 +00:00
|
|
|
this.callSuper('_set', key, value);
|
2014-01-17 16:51:16 +00:00
|
|
|
if (typeof coordProps[key] !== 'undefined') {
|
2011-09-19 21:48:16 +00:00
|
|
|
this._setWidthHeight();
|
|
|
|
|
}
|
|
|
|
|
return this;
|
|
|
|
|
},
|
2012-06-26 14:42:45 +00:00
|
|
|
|
2014-02-05 14:42:52 +00:00
|
|
|
/**
|
|
|
|
|
* @private
|
|
|
|
|
* @return {Number} leftToOriginX Distance from left edge of canvas to originX of Line.
|
|
|
|
|
*/
|
|
|
|
|
_getLeftToOriginX: makeEdgeToOriginGetter(
|
|
|
|
|
{ // property names
|
|
|
|
|
origin: 'originX',
|
|
|
|
|
axis1: 'x1',
|
|
|
|
|
axis2: 'x2',
|
2014-02-23 18:25:23 +00:00
|
|
|
dimension: 'width'
|
2014-02-05 14:42:52 +00:00
|
|
|
},
|
|
|
|
|
{ // possible values of origin
|
|
|
|
|
nearest: 'left',
|
|
|
|
|
center: 'center',
|
2014-02-23 18:25:23 +00:00
|
|
|
farthest: 'right'
|
2014-02-05 14:42:52 +00:00
|
|
|
}
|
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @private
|
|
|
|
|
* @return {Number} topToOriginY Distance from top edge of canvas to originY of Line.
|
|
|
|
|
*/
|
|
|
|
|
_getTopToOriginY: makeEdgeToOriginGetter(
|
|
|
|
|
{ // property names
|
|
|
|
|
origin: 'originY',
|
|
|
|
|
axis1: 'y1',
|
|
|
|
|
axis2: 'y2',
|
2014-02-23 18:25:23 +00:00
|
|
|
dimension: 'height'
|
2014-02-05 14:42:52 +00:00
|
|
|
},
|
|
|
|
|
{ // possible values of origin
|
|
|
|
|
nearest: 'top',
|
|
|
|
|
center: 'center',
|
2014-02-23 18:25:23 +00:00
|
|
|
farthest: 'bottom'
|
2014-02-05 14:42:52 +00:00
|
|
|
}
|
|
|
|
|
),
|
|
|
|
|
|
2010-06-09 22:34:55 +00:00
|
|
|
/**
|
|
|
|
|
* @private
|
2010-10-14 21:42:39 +00:00
|
|
|
* @param {CanvasRenderingContext2D} ctx Context to render on
|
2016-08-20 15:58:16 +00:00
|
|
|
* @param {Boolean} noTransform
|
2010-06-09 22:34:55 +00:00
|
|
|
*/
|
2014-08-05 10:49:34 +00:00
|
|
|
_render: function(ctx, noTransform) {
|
2010-06-09 22:34:55 +00:00
|
|
|
ctx.beginPath();
|
2012-06-26 14:42:45 +00:00
|
|
|
|
2014-08-05 10:49:34 +00:00
|
|
|
if (noTransform) {
|
2014-02-05 16:33:20 +00:00
|
|
|
// Line coords are distances from left-top of canvas to origin of line.
|
|
|
|
|
// To render line in a path-group, we need to translate them to
|
|
|
|
|
// distances from center of path-group to center of line.
|
2017-02-25 20:17:24 +00:00
|
|
|
var cp = this.getCenterPoint(),
|
|
|
|
|
offset = this.strokeWidth / 2;
|
2014-02-05 14:42:52 +00:00
|
|
|
ctx.translate(
|
2017-02-25 20:17:24 +00:00
|
|
|
cp.x - (this.strokeLineCap === 'butt' && this.height === 0 ? 0 : offset),
|
|
|
|
|
cp.y - (this.strokeLineCap === 'butt' && this.width === 0 ? 0 : offset)
|
2014-02-05 14:42:52 +00:00
|
|
|
);
|
2012-09-06 20:41:31 +00:00
|
|
|
}
|
|
|
|
|
|
2013-05-05 00:29:59 +00:00
|
|
|
if (!this.strokeDashArray || this.strokeDashArray && supportsLineDash) {
|
2013-05-04 16:25:57 +00:00
|
|
|
// move from center (of virtual box) to its left/top corner
|
2013-05-25 22:05:49 +00:00
|
|
|
// we can't assume x1, y1 is top left and x2, y2 is bottom right
|
2014-11-10 10:53:30 +00:00
|
|
|
var p = this.calcLinePoints();
|
|
|
|
|
ctx.moveTo(p.x1, p.y1);
|
|
|
|
|
ctx.lineTo(p.x2, p.y2);
|
2013-05-04 16:25:57 +00:00
|
|
|
}
|
2012-06-26 14:42:45 +00:00
|
|
|
|
2011-05-31 18:23:30 +00:00
|
|
|
ctx.lineWidth = this.strokeWidth;
|
2012-06-26 14:42:45 +00:00
|
|
|
|
2010-07-24 03:42:06 +00:00
|
|
|
// TODO: test this
|
|
|
|
|
// make sure setting "fill" changes color of a line
|
|
|
|
|
// (by copying fillStyle to strokeStyle, since line is stroked, not filled)
|
|
|
|
|
var origStrokeStyle = ctx.strokeStyle;
|
2013-04-19 01:42:27 +00:00
|
|
|
ctx.strokeStyle = this.stroke || ctx.fillStyle;
|
2014-01-17 16:57:54 +00:00
|
|
|
this.stroke && this._renderStroke(ctx);
|
2010-07-24 03:42:06 +00:00
|
|
|
ctx.strokeStyle = origStrokeStyle;
|
2010-06-09 22:34:55 +00:00
|
|
|
},
|
2012-06-26 14:42:45 +00:00
|
|
|
|
2013-05-04 16:25:57 +00:00
|
|
|
/**
|
|
|
|
|
* @private
|
|
|
|
|
* @param {CanvasRenderingContext2D} ctx Context to render on
|
|
|
|
|
*/
|
|
|
|
|
_renderDashedStroke: function(ctx) {
|
2014-11-10 10:53:30 +00:00
|
|
|
var p = this.calcLinePoints();
|
2013-05-04 16:25:57 +00:00
|
|
|
|
|
|
|
|
ctx.beginPath();
|
2014-11-10 10:53:30 +00:00
|
|
|
fabric.util.drawDashedLine(ctx, p.x1, p.y1, p.x2, p.y2, this.strokeDashArray);
|
2013-05-04 16:25:57 +00:00
|
|
|
ctx.closePath();
|
|
|
|
|
},
|
|
|
|
|
|
2010-06-09 22:34:55 +00:00
|
|
|
/**
|
2010-10-14 21:42:39 +00:00
|
|
|
* Returns object representation of an instance
|
2010-06-09 22:34:55 +00:00
|
|
|
* @methd toObject
|
2013-09-26 12:12:02 +00:00
|
|
|
* @param {Array} [propertiesToInclude] Any properties that you might want to additionally include in the output
|
2012-12-01 12:57:27 +00:00
|
|
|
* @return {Object} object representation of an instance
|
2010-06-09 22:34:55 +00:00
|
|
|
*/
|
2012-11-30 22:46:09 +00:00
|
|
|
toObject: function(propertiesToInclude) {
|
2014-09-30 19:11:45 +00:00
|
|
|
return extend(this.callSuper('toObject', propertiesToInclude), this.calcLinePoints());
|
|
|
|
|
},
|
|
|
|
|
|
2016-11-13 20:00:10 +00:00
|
|
|
/*
|
|
|
|
|
* Calculate object dimensions from its properties
|
|
|
|
|
* @private
|
|
|
|
|
*/
|
|
|
|
|
_getNonTransformedDimensions: function() {
|
|
|
|
|
var dim = this.callSuper('_getNonTransformedDimensions');
|
|
|
|
|
if (this.strokeLineCap === 'butt') {
|
2017-02-25 20:17:24 +00:00
|
|
|
if (this.width === 0) {
|
2016-11-13 20:00:10 +00:00
|
|
|
dim.y -= this.strokeWidth;
|
|
|
|
|
}
|
2017-02-25 20:17:24 +00:00
|
|
|
if (this.height === 0) {
|
2016-11-13 20:00:10 +00:00
|
|
|
dim.x -= this.strokeWidth;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return dim;
|
|
|
|
|
},
|
|
|
|
|
|
2014-09-30 19:11:45 +00:00
|
|
|
/**
|
2015-01-14 11:35:00 +00:00
|
|
|
* Recalculates line points given width and height
|
2014-09-30 19:11:45 +00:00
|
|
|
* @private
|
|
|
|
|
*/
|
|
|
|
|
calcLinePoints: function() {
|
|
|
|
|
var xMult = this.x1 <= this.x2 ? -1 : 1,
|
|
|
|
|
yMult = this.y1 <= this.y2 ? -1 : 1,
|
2014-11-10 10:53:30 +00:00
|
|
|
x1 = (xMult * this.width * 0.5),
|
|
|
|
|
y1 = (yMult * this.height * 0.5),
|
|
|
|
|
x2 = (xMult * this.width * -0.5),
|
|
|
|
|
y2 = (yMult * this.height * -0.5);
|
2014-09-30 19:11:45 +00:00
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
x1: x1,
|
|
|
|
|
x2: x2,
|
|
|
|
|
y1: y1,
|
|
|
|
|
y2: y2
|
|
|
|
|
};
|
2012-01-02 21:14:20 +00:00
|
|
|
},
|
2012-06-26 14:42:45 +00:00
|
|
|
|
2013-05-09 18:19:06 +00:00
|
|
|
/* _TO_SVG_START_ */
|
2012-01-02 21:14:20 +00:00
|
|
|
/**
|
2012-12-13 14:36:43 +00:00
|
|
|
* Returns SVG representation of an instance
|
2013-09-29 07:22:44 +00:00
|
|
|
* @param {Function} [reviver] Method for further parsing of svg representation.
|
2012-12-13 14:36:43 +00:00
|
|
|
* @return {String} svg representation of an instance
|
2012-01-02 21:14:20 +00:00
|
|
|
*/
|
2013-09-29 07:22:44 +00:00
|
|
|
toSVG: function(reviver) {
|
2014-09-25 23:28:39 +00:00
|
|
|
var markup = this._createBaseSVGMarkup(),
|
2014-09-30 19:11:45 +00:00
|
|
|
p = { x1: this.x1, x2: this.x2, y1: this.y1, y2: this.y2 };
|
2014-09-25 23:28:39 +00:00
|
|
|
|
2014-09-24 12:24:03 +00:00
|
|
|
if (!(this.group && this.group.type === 'path-group')) {
|
2014-09-30 19:11:45 +00:00
|
|
|
p = this.calcLinePoints();
|
2014-08-05 10:49:34 +00:00
|
|
|
}
|
2013-02-23 16:02:52 +00:00
|
|
|
markup.push(
|
2016-05-21 13:07:04 +00:00
|
|
|
'<line ', this.getSvgId(),
|
2014-09-30 19:11:45 +00:00
|
|
|
'x1="', p.x1,
|
|
|
|
|
'" y1="', p.y1,
|
|
|
|
|
'" x2="', p.x2,
|
|
|
|
|
'" y2="', p.y2,
|
2013-02-23 16:02:52 +00:00
|
|
|
'" style="', this.getSvgStyles(),
|
2014-09-25 23:28:39 +00:00
|
|
|
'" transform="', this.getSvgTransform(),
|
2014-08-05 10:49:34 +00:00
|
|
|
this.getSvgTransformMatrix(),
|
|
|
|
|
'"/>\n'
|
2013-02-23 16:02:52 +00:00
|
|
|
);
|
|
|
|
|
|
2013-09-29 07:22:44 +00:00
|
|
|
return reviver ? reviver(markup.join('')) : markup.join('');
|
2013-05-09 18:19:06 +00:00
|
|
|
},
|
|
|
|
|
/* _TO_SVG_END_ */
|
2010-06-09 22:34:55 +00:00
|
|
|
});
|
2012-06-26 14:42:45 +00:00
|
|
|
|
2013-05-30 19:53:49 +00:00
|
|
|
/* _FROM_SVG_START_ */
|
2010-10-14 21:42:39 +00:00
|
|
|
/**
|
2012-11-23 12:38:13 +00:00
|
|
|
* List of attribute names to account for when parsing SVG element (used by {@link fabric.Line.fromElement})
|
2010-10-19 20:27:24 +00:00
|
|
|
* @static
|
2013-08-08 16:31:26 +00:00
|
|
|
* @memberOf fabric.Line
|
2010-10-14 21:42:39 +00:00
|
|
|
* @see http://www.w3.org/TR/SVG/shapes.html#LineElement
|
|
|
|
|
*/
|
2013-05-18 14:43:49 +00:00
|
|
|
fabric.Line.ATTRIBUTE_NAMES = fabric.SHARED_ATTRIBUTES.concat('x1 y1 x2 y2'.split(' '));
|
2012-06-26 14:42:45 +00:00
|
|
|
|
2010-06-09 22:34:55 +00:00
|
|
|
/**
|
2010-10-19 20:27:24 +00:00
|
|
|
* Returns fabric.Line instance from an SVG element
|
2010-06-09 22:34:55 +00:00
|
|
|
* @static
|
2013-08-08 16:31:26 +00:00
|
|
|
* @memberOf fabric.Line
|
2010-10-14 21:42:39 +00:00
|
|
|
* @param {SVGElement} element Element to parse
|
|
|
|
|
* @param {Object} [options] Options object
|
|
|
|
|
* @return {fabric.Line} instance of fabric.Line
|
2010-06-09 22:34:55 +00:00
|
|
|
*/
|
2010-07-09 23:43:50 +00:00
|
|
|
fabric.Line.fromElement = function(element, options) {
|
2017-01-07 13:31:14 +00:00
|
|
|
options = options || { };
|
2014-02-16 21:36:03 +00:00
|
|
|
var parsedAttributes = fabric.parseAttributes(element, fabric.Line.ATTRIBUTE_NAMES),
|
|
|
|
|
points = [
|
|
|
|
|
parsedAttributes.x1 || 0,
|
|
|
|
|
parsedAttributes.y1 || 0,
|
|
|
|
|
parsedAttributes.x2 || 0,
|
|
|
|
|
parsedAttributes.y2 || 0
|
|
|
|
|
];
|
2017-01-03 14:27:51 +00:00
|
|
|
options.originX = 'left';
|
|
|
|
|
options.originY = 'top';
|
2010-07-26 23:20:19 +00:00
|
|
|
return new fabric.Line(points, extend(parsedAttributes, options));
|
2010-06-09 22:34:55 +00:00
|
|
|
};
|
2013-05-30 19:53:49 +00:00
|
|
|
/* _FROM_SVG_END_ */
|
2012-06-26 14:42:45 +00:00
|
|
|
|
2010-06-09 22:34:55 +00:00
|
|
|
/**
|
2010-10-19 20:27:24 +00:00
|
|
|
* Returns fabric.Line instance from an object representation
|
2010-06-09 22:34:55 +00:00
|
|
|
* @static
|
2013-08-08 16:31:26 +00:00
|
|
|
* @memberOf fabric.Line
|
2010-10-14 21:42:39 +00:00
|
|
|
* @param {Object} object Object to create an instance from
|
2016-09-10 14:09:17 +00:00
|
|
|
* @param {function} [callback] invoked with new instance as first argument
|
2016-12-30 21:41:16 +00:00
|
|
|
* @param {Boolean} [forceAsync] Force an async behaviour trying to create pattern first
|
2010-10-14 21:42:39 +00:00
|
|
|
* @return {fabric.Line} instance of fabric.Line
|
2010-06-09 22:34:55 +00:00
|
|
|
*/
|
2016-12-30 21:41:16 +00:00
|
|
|
fabric.Line.fromObject = function(object, callback, forceAsync) {
|
|
|
|
|
function _callback(instance) {
|
|
|
|
|
delete instance.points;
|
|
|
|
|
callback && callback(instance);
|
|
|
|
|
};
|
|
|
|
|
var options = clone(object, true);
|
|
|
|
|
options.points = [object.x1, object.y1, object.x2, object.y2];
|
|
|
|
|
var line = fabric.Object._fromObject('Line', options, _callback, forceAsync, 'points');
|
|
|
|
|
if (line) {
|
|
|
|
|
delete line.points;
|
|
|
|
|
}
|
2016-09-10 14:09:17 +00:00
|
|
|
return line;
|
2010-06-09 22:34:55 +00:00
|
|
|
};
|
2011-08-05 23:00:26 +00:00
|
|
|
|
2014-02-05 14:42:52 +00:00
|
|
|
/**
|
|
|
|
|
* Produces a function that calculates distance from canvas edge to Line origin.
|
|
|
|
|
*/
|
|
|
|
|
function makeEdgeToOriginGetter(propertyNames, originValues) {
|
|
|
|
|
var origin = propertyNames.origin,
|
|
|
|
|
axis1 = propertyNames.axis1,
|
|
|
|
|
axis2 = propertyNames.axis2,
|
|
|
|
|
dimension = propertyNames.dimension,
|
|
|
|
|
nearest = originValues.nearest,
|
|
|
|
|
center = originValues.center,
|
|
|
|
|
farthest = originValues.farthest;
|
|
|
|
|
|
|
|
|
|
return function() {
|
|
|
|
|
switch (this.get(origin)) {
|
2016-09-10 13:14:23 +00:00
|
|
|
case nearest:
|
|
|
|
|
return Math.min(this.get(axis1), this.get(axis2));
|
|
|
|
|
case center:
|
|
|
|
|
return Math.min(this.get(axis1), this.get(axis2)) + (0.5 * this.get(dimension));
|
|
|
|
|
case farthest:
|
|
|
|
|
return Math.max(this.get(axis1), this.get(axis2));
|
2014-02-05 14:42:52 +00:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-04 10:56:22 +00:00
|
|
|
})(typeof exports !== 'undefined' ? exports : this);
|