memberGet method
Fetch a member by the varName
, in the form of
object.varName
varName
must be of String type.
Implementation
@override
dynamic memberGet(String varName, {String? from}) {
switch (varName) {
case 'Math.e':
return math.e;
case 'Math.pi':
return math.pi;
case 'Math.degrees':
return (HTEntity entity,
{List<dynamic> positionalArgs = const [],
Map<String, dynamic> namedArgs = const {},
List<HTType> typeArgs = const []}) =>
degrees(positionalArgs.first.toDouble());
case 'Math.radians':
return (HTEntity entity,
{List<dynamic> positionalArgs = const [],
Map<String, dynamic> namedArgs = const {},
List<HTType> typeArgs = const []}) =>
radians(positionalArgs.first.toDouble());
case 'Math.radiusToSigma':
return (HTEntity entity,
{List<dynamic> positionalArgs = const [],
Map<String, dynamic> namedArgs = const {},
List<HTType> typeArgs = const []}) =>
radiusToSigma(positionalArgs.first.toDouble());
case 'Math.gaussianNoise':
return (HTEntity entity,
{List<dynamic> positionalArgs = const [],
Map<String, dynamic> namedArgs = const {},
List<HTType> typeArgs = const []}) {
final mean = positionalArgs[0].toDouble();
final standardDeviation = positionalArgs[1].toDouble();
final math.Random? randomGenerator = namedArgs['randomGenerator'];
assert(standardDeviation > 0);
final num? min = namedArgs['min'];
final num? max = namedArgs['max'];
double r;
do {
r = gaussianNoise(
mean,
standardDeviation,
randomGenerator: randomGenerator,
);
} while ((min != null && r < min) || (max != null && r > max));
return r;
};
case 'Math.noise2d':
return (HTEntity entity,
{List<dynamic> positionalArgs = const [],
Map<String, dynamic> namedArgs = const {},
List<HTType> typeArgs = const []}) {
final int size = positionalArgs[0].toInt();
final seed = namedArgs['seed'] ?? math.Random().nextInt(1 << 32);
final frequency = namedArgs['frequency'];
final noiseTypeString = namedArgs['noiseType'];
NoiseType noiseType;
switch (noiseTypeString) {
case 'perlinFractal':
noiseType = NoiseType.PerlinFractal;
break;
case 'perlin':
noiseType = NoiseType.Perlin;
break;
case 'cubicFractal':
noiseType = NoiseType.CubicFractal;
break;
case 'cubic':
default:
noiseType = NoiseType.Cubic;
}
return noise2(
size,
size,
seed: seed,
frequency: frequency,
noiseType: noiseType,
);
};
case 'Math.min':
return (HTEntity entity,
{List<dynamic> positionalArgs = const [],
Map<String, dynamic> namedArgs = const {},
List<HTType> typeArgs = const []}) =>
math.min(positionalArgs[0] as num, positionalArgs[1] as num);
case 'Math.max':
return (HTEntity entity,
{List<dynamic> positionalArgs = const [],
Map<String, dynamic> namedArgs = const {},
List<HTType> typeArgs = const []}) =>
math.max(positionalArgs[0] as num, positionalArgs[1] as num);
case 'Math.sqrt':
return (HTEntity entity,
{List<dynamic> positionalArgs = const [],
Map<String, dynamic> namedArgs = const {},
List<HTType> typeArgs = const []}) =>
math.sqrt(positionalArgs.first as num);
case 'Math.pow':
return (HTEntity entity,
{List<dynamic> positionalArgs = const [],
Map<String, dynamic> namedArgs = const {},
List<HTType> typeArgs = const []}) =>
math.pow(positionalArgs[0] as num, positionalArgs[1] as num);
case 'Math.sin':
return (HTEntity entity,
{List<dynamic> positionalArgs = const [],
Map<String, dynamic> namedArgs = const {},
List<HTType> typeArgs = const []}) =>
math.sin(positionalArgs.first as num);
case 'Math.cos':
return (HTEntity entity,
{List<dynamic> positionalArgs = const [],
Map<String, dynamic> namedArgs = const {},
List<HTType> typeArgs = const []}) =>
math.cos(positionalArgs.first as num);
case 'Math.tan':
return (HTEntity entity,
{List<dynamic> positionalArgs = const [],
Map<String, dynamic> namedArgs = const {},
List<HTType> typeArgs = const []}) =>
math.tan(positionalArgs.first as num);
case 'Math.exp':
return (HTEntity entity,
{List<dynamic> positionalArgs = const [],
Map<String, dynamic> namedArgs = const {},
List<HTType> typeArgs = const []}) =>
math.exp(positionalArgs.first as num);
case 'Math.log':
return (HTEntity entity,
{List<dynamic> positionalArgs = const [],
Map<String, dynamic> namedArgs = const {},
List<HTType> typeArgs = const []}) =>
math.log(positionalArgs.first as num);
case 'Math.parseInt':
return (HTEntity entity,
{List<dynamic> positionalArgs = const [],
Map<String, dynamic> namedArgs = const {},
List<HTType> typeArgs = const []}) =>
int.tryParse(positionalArgs.first as String,
radix: namedArgs['radix']) ??
0;
case 'Math.parseDouble':
return (HTEntity entity,
{List<dynamic> positionalArgs = const [],
Map<String, dynamic> namedArgs = const {},
List<HTType> typeArgs = const []}) =>
double.tryParse(positionalArgs.first as String) ?? 0.0;
case 'Math.sum':
return (HTEntity entity,
{List<dynamic> positionalArgs = const [],
Map<String, dynamic> namedArgs = const {},
List<HTType> typeArgs = const []}) =>
(positionalArgs.first as List<num>)
.reduce((value, element) => value + element);
case 'Math.checkBit':
return (HTEntity entity,
{List<dynamic> positionalArgs = const [],
Map<String, dynamic> namedArgs = const {},
List<HTType> typeArgs = const []}) =>
((positionalArgs[0] as int) & (1 << (positionalArgs[1] as int))) !=
0;
case 'Math.bitLS':
return (HTEntity entity,
{List<dynamic> positionalArgs = const [],
Map<String, dynamic> namedArgs = const {},
List<HTType> typeArgs = const []}) =>
(positionalArgs[0] as int) << (positionalArgs[1] as int);
case 'Math.bitRS':
return (HTEntity entity,
{List<dynamic> positionalArgs = const [],
Map<String, dynamic> namedArgs = const {},
List<HTType> typeArgs = const []}) =>
(positionalArgs[0] as int) >> (positionalArgs[1] as int);
case 'Math.bitAnd':
return (HTEntity entity,
{List<dynamic> positionalArgs = const [],
Map<String, dynamic> namedArgs = const {},
List<HTType> typeArgs = const []}) =>
(positionalArgs[0] as int) & (positionalArgs[1] as int);
case 'Math.bitOr':
return (HTEntity entity,
{List<dynamic> positionalArgs = const [],
Map<String, dynamic> namedArgs = const {},
List<HTType> typeArgs = const []}) =>
(positionalArgs[0] as int) | (positionalArgs[1] as int);
case 'Math.bitNot':
return (HTEntity entity,
{List<dynamic> positionalArgs = const [],
Map<String, dynamic> namedArgs = const {},
List<HTType> typeArgs = const []}) =>
~(positionalArgs[0] as int);
case 'Math.bitXor':
return (HTEntity entity,
{List<dynamic> positionalArgs = const [],
Map<String, dynamic> namedArgs = const {},
List<HTType> typeArgs = const []}) =>
(positionalArgs[0] as int) ^ (positionalArgs[1] as int);
default:
throw HTError.undefined(varName);
}
}