Merge branch 'HrBDev-master' into dart

This commit is contained in:
Don Cross
2022-05-06 12:53:19 -04:00
7 changed files with 201 additions and 0 deletions

10
source/dart/.gitignore vendored Normal file
View File

@@ -0,0 +1,10 @@
# Files and directories created by pub.
.dart_tool/
.packages
# Conventional directory for build outputs.
build/
# Omit committing pubspec.lock for library packages; see
# https://dart.dev/guides/libraries/private-files#pubspeclock.
pubspec.lock

3
source/dart/CHANGELOG.md Normal file
View File

@@ -0,0 +1,3 @@
## 1.0.0
- Initial version.

39
source/dart/README.md Normal file
View File

@@ -0,0 +1,39 @@
<!--
This README describes the package. If you publish this package to pub.dev,
this README's contents appear on the landing page for your package.
For information about how to write a good package README, see the guide for
[writing package pages](https://dart.dev/guides/libraries/writing-package-pages).
For general information about developing packages, see the Dart guide for
[creating packages](https://dart.dev/guides/libraries/create-library-packages)
and the Flutter guide for
[developing packages and plugins](https://flutter.dev/developing-packages).
-->
TODO: Put a short description of the package here that helps potential users
know whether this package might be useful for them.
## Features
TODO: List what your package can do. Maybe include images, gifs, or videos.
## Getting started
TODO: List prerequisites and provide or point to information on how to
start using the package.
## Usage
TODO: Include short and useful examples for package users. Add longer examples
to `/example` folder.
```dart
const like = 'sample';
```
## Additional information
TODO: Tell users more about the package: where to find more information, how to
contribute to the package, how to file issues, what response they can expect
from the package authors, and more.

View File

@@ -0,0 +1,30 @@
# This file configures the static analysis results for your project (errors,
# warnings, and lints).
#
# This enables the 'recommended' set of lints from `package:lints`.
# This set helps identify many issues that may lead to problems when running
# or consuming Dart code, and enforces writing Dart using a single, idiomatic
# style and format.
#
# If you want a smaller set of lints you can change this to specify
# 'package:lints/core.yaml'. These are just the most critical lints
# (the recommended set includes the core lints).
# The core lints are also what is used by pub.dev for scoring packages.
include: package:lints/recommended.yaml
# Uncomment the following section to specify additional rules.
# linter:
# rules:
# - camel_case_types
# analyzer:
# exclude:
# - path/to/excluded/files/**
# For more information about the core and recommended set of lints, see
# https://dart.dev/go/core-lints
# For additional information about configuring this file, see
# https://dart.dev/guides/language/analysis-options

View File

@@ -0,0 +1,90 @@
library astronomy;
import 'dart:math';
class TerseVector {
final double x;
final double y;
final double z;
const TerseVector({
required this.x,
required this.y,
required this.z,
});
static final TerseVector zero = TerseVector(x: 0.0, y: 0.0, z: 0.0);
TerseVector operator +(TerseVector other) {
return TerseVector(x: x + other.x, y: y + other.y, z: z + other.z);
}
TerseVector operator -(TerseVector other) {
return TerseVector(x: x - other.x, y: y - other.y, z: z - other.z);
}
TerseVector operator *(double s) {
return TerseVector(x: s * x, y: s * y, z: s * z);
}
TerseVector operator /(double s) {
return TerseVector(x: x / s, y: y / s, z: z / s);
}
double quadrature() {
return x * x + y * y + z * z;
}
double magnitude() {
return sqrt(quadrature());
}
//<editor-fold desc="Data Methods">
@override
bool operator ==(Object other) =>
identical(this, other) ||
(other is TerseVector &&
runtimeType == other.runtimeType &&
x == other.x &&
y == other.y &&
z == other.z);
@override
int get hashCode => x.hashCode ^ y.hashCode ^ z.hashCode;
@override
String toString() {
return 'TerseVector{' + ' x: $x,' + ' y: $y,' + ' z: $z,' + '}';
}
TerseVector copyWith({
double? x,
double? y,
double? z,
}) {
return TerseVector(
x: x ?? this.x,
y: y ?? this.y,
z: z ?? this.z,
);
}
Map<String, dynamic> toMap() {
return {
'x': this.x,
'y': this.y,
'z': this.z,
};
}
factory TerseVector.fromMap(Map<String, dynamic> map) {
return TerseVector(
x: map['x'] as double,
y: map['y'] as double,
z: map['z'] as double,
);
}
//</editor-fold>
}

15
source/dart/pubspec.yaml Normal file
View File

@@ -0,0 +1,15 @@
name: astronomy
description: A starting point for Dart libraries or applications.
version: 1.0.0
# homepage: https://www.example.com
environment:
sdk: '>=2.16.2 <3.0.0'
# dependencies:
# path: ^1.8.0
dev_dependencies:
lints: ^1.0.0
test: ^1.16.0

View File

@@ -0,0 +1,14 @@
import 'package:astronomy/astronomy.dart';
import 'package:test/test.dart';
void main() {
test('TerseVector methods', () {
final ones = TerseVector(x: 1.0, y: 1.0, z: 1.0);
expect(ones, ones + TerseVector.zero);
expect(ones, ones + TerseVector.zero);
expect(TerseVector(x: 6.0, y: 8.0, z: 4.0), TerseVector(x: 3.0, y: 4.0, z: 2.0) * 2.0);
expect(TerseVector(x: -1.5, y: 2.0, z: -1.0), TerseVector(x: -3.0, y: 4.0, z: -2.0) / 2.0);
expect(29.0, TerseVector(x: -3.0, y: 4.0, z: -2.0).quadrature());
expect(5.744562646538029, TerseVector(x: -2.0, y: -2.0, z: 5.0).magnitude());
});
}