add getTranslation and setGeoPosition to transform.nas, adapt element.nas accordingly;
improve readability and comments
This commit is contained in:
parent
2eb4c78794
commit
e996f4c8c6
2 changed files with 30 additions and 14 deletions
|
@ -13,10 +13,11 @@ var Element = {
|
|||
#
|
||||
# @param ghost Element ghost as retrieved from core methods
|
||||
new: func(ghost) {
|
||||
return {
|
||||
parents: [PropertyElement, Element, ghost],
|
||||
_node: props.wrapNode(ghost._node_ghost)
|
||||
var obj = {
|
||||
parents: [Element, PropertyElement, ghost],
|
||||
_node: props.wrapNode(ghost._node_ghost),
|
||||
};
|
||||
return obj;
|
||||
},
|
||||
|
||||
# Get parent group/element
|
||||
|
@ -26,7 +27,7 @@ var Element = {
|
|||
return nil;
|
||||
|
||||
var type = props.wrapNode(parent_ghost._node_ghost).getName();
|
||||
var factory = me._getFactory(type);
|
||||
var factory = Group._getFactory(type);
|
||||
if (factory == nil)
|
||||
return parent_ghost;
|
||||
|
||||
|
@ -72,8 +73,7 @@ var Element = {
|
|||
},
|
||||
|
||||
setGeoPosition: func(lat, lon) {
|
||||
me._getTf()._node.getNode("m-geo[4]", 1).setValue("N"~lat);
|
||||
me._getTf()._node.getNode("m-geo[5]", 1).setValue("E"~lon);
|
||||
me._getTf().setGeoPosition(lat, lon);
|
||||
return me;
|
||||
},
|
||||
|
||||
|
@ -94,10 +94,10 @@ var Element = {
|
|||
|
||||
# Get translation set with #setTranslation
|
||||
getTranslation: func() {
|
||||
if (me["_tf"] == nil)
|
||||
if (me["_tf"] == nil) {
|
||||
return [0, 0];
|
||||
|
||||
return [me._tf.e.getValue(), me._tf.f.getValue()];
|
||||
}
|
||||
return me._tf.getTranslation();
|
||||
},
|
||||
|
||||
# Set rotation around transformation center (see #setCenter).
|
||||
|
@ -182,6 +182,7 @@ var Element = {
|
|||
return center;
|
||||
},
|
||||
|
||||
#return vector [sx, sy] with dimensions of bounding box
|
||||
getSize: func {
|
||||
var bb = me.getTightBoundingBox();
|
||||
return [bb[2] - bb[0], bb[3] - bb[1]];
|
||||
|
@ -189,7 +190,7 @@ var Element = {
|
|||
|
||||
# convert bounding box vector into clip string (yes, different order)
|
||||
boundingbox2clip: func(bb) {
|
||||
return sprintf("rect(%d,%d,%d,%d)", bb[1], bb[2], bb[3], bb[0])
|
||||
return sprintf("rect(%d,%d,%d,%d)", bb[1], bb[2], bb[3], bb[0]);
|
||||
},
|
||||
|
||||
# set clip by bounding box
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
# 0 0 1
|
||||
#
|
||||
# See http://www.w3.org/TR/SVG/coords.html#TransformMatrixDefined for details.
|
||||
# https://www.w3.org/TR/css-transforms-1/#mathematical-description
|
||||
#
|
||||
var Transform = {
|
||||
new: func(node, vals = nil) {
|
||||
|
@ -44,7 +45,11 @@ var Transform = {
|
|||
|
||||
return me;
|
||||
},
|
||||
|
||||
|
||||
getTranslation: func() {
|
||||
return [me.e.getValue(), me.f.getValue()];
|
||||
},
|
||||
|
||||
# Set rotation (Optionally around a specified point instead of (0,0))
|
||||
#
|
||||
# setRotation(rot)
|
||||
|
@ -58,6 +63,7 @@ var Transform = {
|
|||
var s = math.sin(angle);
|
||||
var c = math.cos(angle);
|
||||
|
||||
# rotation goes to the top-left 2x2 part of the matrix
|
||||
me.a.setDoubleValue(c); me.c.setDoubleValue(-s);
|
||||
me.b.setDoubleValue(s); me.d.setDoubleValue(c);
|
||||
|
||||
|
@ -76,15 +82,24 @@ var Transform = {
|
|||
# setScale([x, y])
|
||||
setScale: func {
|
||||
var scale = _arg2valarray(arg);
|
||||
|
||||
# the scale factors go to the diagonal elements of the matrix
|
||||
me.a.setDoubleValue(scale[0]);
|
||||
me.d.setDoubleValue(size(scale) >= 2 ? scale[1] : scale[0]);
|
||||
|
||||
return me;
|
||||
},
|
||||
|
||||
getScale: func() {
|
||||
# TODO handle rotation
|
||||
return [me.a.getValue(), me.d.getValue()];
|
||||
}
|
||||
},
|
||||
|
||||
# this function is called very often, if a canvas map is active and
|
||||
# the aircraft symbol is shown.
|
||||
setGeoPosition: func(lat, lon) {
|
||||
if (me["_gn"] == nil) { me._gn = me._node.getNode("m-geo[4]", 1); }
|
||||
if (me["_ge"] == nil) { me._ge = me._node.getNode("m-geo[5]", 1); }
|
||||
me._gn.setValue("N" ~ lat);
|
||||
me._ge.setValue("E" ~ lon);
|
||||
return me;
|
||||
},
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue