1
0
Fork 0

replace typeof() == foo with isFoo

This commit is contained in:
Henning Stahlke 2020-05-05 20:13:06 +02:00 committed by James Turner
parent 627530cf5b
commit 5a5d958dd9
8 changed files with 26 additions and 22 deletions

View file

@ -10,10 +10,12 @@ var PropertyElement = {
# @param id ID/Name (Should be unique)
new: func(node, id)
{
if( typeof(node) == 'vector' )
if (isvec(node)) {
var node = aircraft.makeNode(node[0]).addChild(node[1], 0, 0);
else
}
else {
var node = aircraft.makeNode(node);
}
if( !isa(node, props.Node) )
return debug.warn("Not a props.Node!");

View file

@ -70,10 +70,11 @@ var get = func(arg)
{
if( isa(arg, props.Node) )
var node = arg;
else if( typeof(arg) == "hash" )
else if (ishash(arg))
var node = props.Node.new(arg);
else
die("canvas.new: Invalid argument.");
else {
die("canvas.get: Invalid argument.");
}
return wrapCanvas(_getCanvasGhost(node._g));
};

View file

@ -64,7 +64,7 @@ var Group = {
children = [];
}
var my_children = me.getChildren();
if (typeof(type) != "vector") {
if (!isvec(type)) {
type = [type];
}
foreach(var c; my_children) {
@ -87,15 +87,16 @@ var Group = {
var color = arg;
var types = [Path, Text];
var arg_c = size(color);
if (arg_c > 1 and typeof(color[-1]) == "vector") {
if (arg_c > 1 and isvec(color[-1])) {
types = color[-1];
color = subvec(color, 0, arg_c - 1);
}
var children = me.getChildrenOfType(types);
if (typeof(color) == "vector") {
if (isvec(color)) {
var first = color[0];
if (typeof(first) == "vector")
if (isvec(first)) {
color = first;
}
}
foreach(var c; children) {
c.setColor(color);

View file

@ -6,9 +6,9 @@ var _getColor = func(color) {
if (size(color) == 1)
var color = color[0];
if (typeof(color) == "scalar")
if (isscalar(color))
return color;
if (typeof(color) != "vector")
if (!isvec(color))
return debug.warn("Wrong type for color");
if (size(color) < 3 or size(color) > 4)
return debug.warn("Color needs 3 or 4 values (RGB or RGBA)");
@ -25,10 +25,10 @@ var _getColor = func(color) {
return str ~ ')';
};
var _arg2valarray = func
{
var _arg2valarray = func {
var ret = arg;
while (typeof(ret) == "vector" and size(ret) == 1 and typeof(ret[0]) == "vector")
while (isvec(ret) and size(ret) == 1 and isvec(ret[0])) {
ret = ret[0];
}
return ret;
}

View file

@ -33,7 +33,7 @@ var Image = {
if (size(arg) == 1) {
arg = arg[0];
}
elsif (size(arg) and size(arg) < 4 and typeof(arg[0]) == "vector") {
elsif (size(arg) and size(arg) < 4 and isvec(arg[0])) {
arg = arg[0]~arg[1:];
}
if (!contains(caller(0)[0], "normalized")) {

View file

@ -203,7 +203,7 @@ var Path = {
# resolve border-[top-,bottom-][left-,right-]radius
var br = opts["border-radius"];
if (typeof(br) == "scalar") {
if (isscalar(br)) {
br = [br, br];
}
@ -220,7 +220,7 @@ var Path = {
}
if (r == nil) { return br; }
else if (typeof(r) == "scalar") { return [r, r]; }
else if (isscalar(r)) { return [r, r]; }
else { return r; }
};
@ -267,7 +267,7 @@ var Path = {
# @param cx (optional) center x coordinate or vector [cx, cy]
# @param cy (optional) center y coordinate
ellipse: func(rx, ry, cx = nil, cy = nil) {
if (typeof(cx) == "vector") {
if (isvec(cx)) {
cy = cx[1];
cx = cx[0];
}
@ -345,13 +345,12 @@ var Path = {
# @param pattern Vector, Vector of alternating dash and gap lengths
# [on1, off1, on2, ...]
setStrokeDashArray: func(pattern) {
if (typeof(pattern) == "vector") {
if (isvec(pattern)) {
me.set("stroke-dasharray", string.join(",", pattern));
}
else {
debug.warn("setStrokeDashArray: vector expected!");
}
return me;
},

View file

@ -24,7 +24,7 @@ var Transform = {
f: node.getNode("m[5]", 1), #ty
};
var use_vals = typeof(vals) == "vector" and size(vals) == 6;
var use_vals = isvec(vals) and size(vals) == 6;
# initialize to identity matrix
m.a.setDoubleValue(use_vals ? vals[0] : 1);

View file

@ -64,8 +64,9 @@ var parsesvg = func(group, path, options = nil)
append(stack, stack[-1].createChild(type, id));
append(close_stack, level);
if( typeof(id) == 'scalar' and size(id) )
if (isscalar(id) and size(id)) {
id_dict[ id ] = stack[-1];
}
if( cur_clip != nil )
{