Created with <3 with dartpad.dev.
Last active
September 5, 2023 17:49
-
-
Save ElanDeyan/f07c9adc608d61bcbac6dbbf617b4321 to your computer and use it in GitHub Desktop.
primal-jungle-2630
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void main() { | |
const a = Vec2(horizontalDimension: 2, verticalDimension: 3); | |
const b = Vec2(horizontalDimension: -4, verticalDimension: -2); | |
print(4.multiplyInVec2(a) - 2.multiplyInVec2(b)); | |
} | |
final class Vec2 { | |
final num horizontalDimension; | |
final num verticalDimension; | |
const Vec2( | |
{required this.horizontalDimension, required this.verticalDimension,}); | |
Vec2 operator +(Vec2 other) => Vec2( | |
horizontalDimension: horizontalDimension + other.horizontalDimension, | |
verticalDimension: verticalDimension + other.verticalDimension, | |
); | |
Vec2 operator -(Vec2 other) => | |
this + (other.multipliedByScalar(-1)); | |
Vec2 multipliedByScalar(num scalar) => Vec2( | |
horizontalDimension: scalar * horizontalDimension, | |
verticalDimension: scalar * verticalDimension, | |
); | |
@override | |
String toString() => '[$horizontalDimension,$verticalDimension]'; | |
} | |
extension Vector2 on num { | |
Vec2 multiplyInVec2(Vec2 vector) => Vec2( | |
horizontalDimension: this * vector.horizontalDimension, | |
verticalDimension: this * vector.verticalDimension, | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment