Begin adding LibOMV Data Types as specified in OSS LSLEdit
This commit is contained in:
parent
e70cec7df9
commit
565480ca8e
5 changed files with 215 additions and 1 deletions
5
lib/omv/package_info.dart
Normal file
5
lib/omv/package_info.dart
Normal file
|
@ -0,0 +1,5 @@
|
|||
/// This package contains some data types and utilities from the open sourced C# LSL Editor project.
|
||||
/// All adaptations of the original code are credited to Alphons van der Heijden
|
||||
///
|
||||
/// // The code was donated on 2010-04-28 by Alphons van der Heijden to Brandon 'Dimentox Travanti' Husbands &
|
||||
/// // Malcolm J. Kudra, who in turn License under the GPLv2 in agreement with Alphons van der Heijden's wishes.
|
60
lib/omv/types/key.dart
Normal file
60
lib/omv/types/key.dart
Normal file
|
@ -0,0 +1,60 @@
|
|||
class Key {
|
||||
String _value;
|
||||
|
||||
// Getter and setter for `guid`
|
||||
String get guid {
|
||||
_value ??= '';
|
||||
return _value;
|
||||
}
|
||||
|
||||
set guid(String value) {
|
||||
_value = value;
|
||||
}
|
||||
|
||||
// Constructors
|
||||
Key.fromGuid(String guid) : _value = guid;
|
||||
|
||||
Key.fromString(String strGuid) : _value = strGuid;
|
||||
|
||||
// NULL_KEY equivalent
|
||||
static final Key NULL_KEY =
|
||||
Key.fromString("00000000-0000-0000-0000-000000000000");
|
||||
|
||||
// Implicit conversion from String to Key
|
||||
factory Key.fromStringOrNull(String? strGuid) {
|
||||
return strGuid == null ? Key.fromString('') : Key.fromString(strGuid);
|
||||
}
|
||||
|
||||
// Implicit conversion to String
|
||||
@override
|
||||
String toString() {
|
||||
return guid;
|
||||
}
|
||||
|
||||
// Equality operator
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
if (identical(this, other)) return true;
|
||||
|
||||
return other is Key && other.guid == guid;
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode => guid.hashCode;
|
||||
|
||||
// Boolean logic
|
||||
bool isTrue() {
|
||||
return !(guid == NULL_KEY.guid || guid.isEmpty);
|
||||
}
|
||||
|
||||
bool isFalse() {
|
||||
return !isTrue();
|
||||
}
|
||||
|
||||
@override
|
||||
bool equals(Object obj) {
|
||||
if (identical(this, obj)) return true;
|
||||
|
||||
return obj is Key && this == obj;
|
||||
}
|
||||
}
|
45
lib/omv/types/string.dart
Normal file
45
lib/omv/types/string.dart
Normal file
|
@ -0,0 +1,45 @@
|
|||
class string {
|
||||
String value;
|
||||
|
||||
string(this.value);
|
||||
|
||||
// Implicit conversion from String to CustomString
|
||||
string.fromString(String s) : value = s;
|
||||
|
||||
// Explicit conversions
|
||||
/// This handler in the original C# code had this note:
|
||||
/// // 3 oct 2007
|
||||
string.fromBool(bool a) : value = a ? "1" : "0";
|
||||
|
||||
/// This handler in the original C# code had this note:
|
||||
/// // 24 augustus 2007
|
||||
string.fromInt(int i) : value = i.toString();
|
||||
|
||||
string.fromLong(int i) : value = i.toString();
|
||||
|
||||
string.fromFloat(double i) : value = i.toStringAsFixed(6);
|
||||
|
||||
// Implicit conversion from CustomString to String
|
||||
String toString() => value ?? '';
|
||||
|
||||
// Conversion to bool
|
||||
bool toBool() => value != null && value.isNotEmpty;
|
||||
|
||||
// Equality operator
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
if (identical(this, other)) return true;
|
||||
|
||||
return other is string && other.value == value;
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode => value.hashCode;
|
||||
|
||||
@override
|
||||
bool equals(Object other) {
|
||||
if (identical(this, other)) return true;
|
||||
|
||||
return other is string && other.value == value;
|
||||
}
|
||||
}
|
104
lib/omv/types/vector.dart
Normal file
104
lib/omv/types/vector.dart
Normal file
|
@ -0,0 +1,104 @@
|
|||
import '../../utils/Vector3.dart';
|
||||
|
||||
class Vector {
|
||||
Vector3d _vector = Vector3d.ZERO;
|
||||
|
||||
static final Vector ZERO_VECTOR = Vector(0, 0, 0);
|
||||
|
||||
double get x => _vector.X;
|
||||
set x(double value) => _vector.X = value;
|
||||
|
||||
double get y => _vector.Y;
|
||||
set y(double value) => _vector.Y = value;
|
||||
|
||||
double get z => _vector.Z;
|
||||
set z(double value) => _vector.Z = value;
|
||||
|
||||
Vector(double x, double y, double z) : _vector = Vector3d(X: x, Y: y, Z: z);
|
||||
|
||||
Vector.fromString(String s) {
|
||||
final regex = RegExp(r'<(?<x>[^,]*),(?<y>[^,]*),(?<z>[^,]*)>');
|
||||
final match = regex.firstMatch(s);
|
||||
if (match != null) {
|
||||
_vector = Vector3d(
|
||||
X: double.parse(match.namedGroup('x') ?? '0'),
|
||||
Y: double.parse(match.namedGroup('y') ?? '0'),
|
||||
Z: double.parse(match.namedGroup('z') ?? '0'),
|
||||
);
|
||||
} else {
|
||||
_vector = Vector3d(X: 0, Y: 0, Z: 0);
|
||||
}
|
||||
}
|
||||
|
||||
double _sumSqrs() {
|
||||
return x * x + y * y + z * z;
|
||||
}
|
||||
|
||||
Vector add(Vector other) {
|
||||
return Vector(x + other.x, y + other.y, z + other.z);
|
||||
}
|
||||
|
||||
Vector subtract(Vector other) {
|
||||
return Vector(x - other.x, y - other.y, z - other.z);
|
||||
}
|
||||
|
||||
Vector negate() {
|
||||
return Vector(-x, -y, -z);
|
||||
}
|
||||
|
||||
double dot(Vector other) {
|
||||
return x * other.x + y * other.y + z * other.z;
|
||||
}
|
||||
|
||||
Vector divide(double value) {
|
||||
return Vector(x / value, y / value, z / value);
|
||||
}
|
||||
|
||||
Vector multiply(double value) {
|
||||
return Vector(x * value, y * value, z * value);
|
||||
}
|
||||
|
||||
Vector cross(Vector other) {
|
||||
return Vector(
|
||||
y * other.z - z * other.y,
|
||||
z * other.x - x * other.z,
|
||||
x * other.y - y * other.x,
|
||||
);
|
||||
}
|
||||
|
||||
bool lessThan(Vector other) {
|
||||
return _sumSqrs() < other._sumSqrs();
|
||||
}
|
||||
|
||||
bool lessThanOrEqual(Vector other) {
|
||||
return _sumSqrs() <= other._sumSqrs();
|
||||
}
|
||||
|
||||
bool greaterThan(Vector other) {
|
||||
return _sumSqrs() > other._sumSqrs();
|
||||
}
|
||||
|
||||
bool greaterThanOrEqual(Vector other) {
|
||||
return _sumSqrs() >= other._sumSqrs();
|
||||
}
|
||||
|
||||
static const double equalityTolerance = 1e-14;
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
if (other is Vector) {
|
||||
return (x - other.x).abs() <= equalityTolerance &&
|
||||
(y - other.y).abs() <= equalityTolerance &&
|
||||
(z - other.z).abs() <= equalityTolerance;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode => (x + y + z).toInt() % 2147483647; // Int32.MaxValue in C#
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return '<${x.toStringAsFixed(5)}, ${y.toStringAsFixed(5)}, ${z.toStringAsFixed(5)}>';
|
||||
}
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
name: libac_dart
|
||||
description: "Aria's Creations code library"
|
||||
version: 1.2.072724+0235
|
||||
version: 1.2.082224+1226
|
||||
homepage: "https://zontreck.com"
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue