added photography values

This commit is contained in:
Vadim 2022-10-25 22:53:39 +03:00
parent 20ea464367
commit 8563ff3b15
7 changed files with 268 additions and 32 deletions

View file

@ -0,0 +1,67 @@
part of 'photography_value.dart';
class ApertureValue extends PhotographyValue<double> {
const ApertureValue(super.rawValue, super.stopType);
@override
double get value => 1 / rawValue;
@override
String toString() {
final buffer = StringBuffer("f/");
if (rawValue - rawValue.floor() == 0 && rawValue >= 8) {
buffer.write(rawValue.toInt().toString());
} else {
buffer.write(rawValue.toStringAsFixed(1));
}
return buffer.toString();
}
}
const List<ApertureValue> apertureValues = [
ApertureValue(1.0, Stop.full),
ApertureValue(1.1, Stop.third),
ApertureValue(1.2, Stop.half),
ApertureValue(1.2, Stop.third),
ApertureValue(1.4, Stop.full),
ApertureValue(1.6, Stop.third),
ApertureValue(1.7, Stop.half),
ApertureValue(1.8, Stop.third),
ApertureValue(2.0, Stop.full),
ApertureValue(2.2, Stop.third),
ApertureValue(2.4, Stop.half),
ApertureValue(2.4, Stop.third),
ApertureValue(2.8, Stop.full),
ApertureValue(3.2, Stop.third),
ApertureValue(3.3, Stop.half),
ApertureValue(3.5, Stop.third),
ApertureValue(4.0, Stop.full),
ApertureValue(4.5, Stop.third),
ApertureValue(4.8, Stop.half),
ApertureValue(5.0, Stop.third),
ApertureValue(5.6, Stop.full),
ApertureValue(6.3, Stop.third),
ApertureValue(6.7, Stop.half),
ApertureValue(7.1, Stop.third),
ApertureValue(8, Stop.full),
ApertureValue(9, Stop.third),
ApertureValue(9.5, Stop.half),
ApertureValue(10, Stop.third),
ApertureValue(11, Stop.full),
ApertureValue(13, Stop.third),
ApertureValue(13, Stop.half),
ApertureValue(14, Stop.third),
ApertureValue(16, Stop.full),
ApertureValue(18, Stop.third),
ApertureValue(19, Stop.half),
ApertureValue(20, Stop.third),
ApertureValue(22, Stop.full),
ApertureValue(25, Stop.third),
ApertureValue(27, Stop.half),
ApertureValue(29, Stop.third),
ApertureValue(32, Stop.full),
ApertureValue(36, Stop.third),
ApertureValue(38, Stop.half),
ApertureValue(42, Stop.third),
ApertureValue(45, Stop.full),
];

48
lib/models/iso_value.dart Normal file
View file

@ -0,0 +1,48 @@
part of 'photography_value.dart';
class IsoValue extends PhotographyValue<int> {
const IsoValue(super.rawValue, super.stopType);
@override
int get value => rawValue;
@override
String toString() => value.toString();
}
const List<IsoValue> isoValues = [
IsoValue(3, Stop.full),
IsoValue(4, Stop.third),
IsoValue(5, Stop.third),
IsoValue(6, Stop.full),
IsoValue(8, Stop.third),
IsoValue(10, Stop.third),
IsoValue(12, Stop.full),
IsoValue(16, Stop.third),
IsoValue(20, Stop.third),
IsoValue(25, Stop.full),
IsoValue(32, Stop.third),
IsoValue(40, Stop.third),
IsoValue(50, Stop.full),
IsoValue(64, Stop.third),
IsoValue(80, Stop.third),
IsoValue(100, Stop.full),
IsoValue(125, Stop.third),
IsoValue(160, Stop.third),
IsoValue(200, Stop.full),
IsoValue(250, Stop.third),
IsoValue(320, Stop.third),
IsoValue(400, Stop.full),
IsoValue(500, Stop.third),
IsoValue(640, Stop.third),
IsoValue(800, Stop.full),
IsoValue(1000, Stop.third),
IsoValue(1250, Stop.third),
IsoValue(1600, Stop.full),
IsoValue(2000, Stop.third),
IsoValue(2500, Stop.third),
IsoValue(3200, Stop.full),
IsoValue(4000, Stop.third),
IsoValue(5000, Stop.third),
IsoValue(6400, Stop.full),
];

View file

@ -0,0 +1,22 @@
part 'aperture_value.dart';
part 'iso_value.dart';
part 'shutter_speed_value.dart';
enum Stop { full, half, third }
abstract class PhotographyValue<T> {
final T rawValue;
final Stop stopType;
const PhotographyValue(this.rawValue, this.stopType);
T get value;
}
extension PhotographyValues<T> on List<PhotographyValue<T>> {
List<PhotographyValue<T>> fullStops() => where((e) => e.stopType == Stop.full).toList();
List<PhotographyValue<T>> halfStops() => where((e) => e.stopType == Stop.full || e.stopType == Stop.half).toList();
List<PhotographyValue<T>> thirdStops() => where((e) => e.stopType == Stop.full || e.stopType == Stop.third).toList();
}

View file

@ -0,0 +1,87 @@
part of 'photography_value.dart';
class ShutterSpeedValue extends PhotographyValue<double> {
final bool isFraction;
const ShutterSpeedValue(super.rawValue, this.isFraction, super.stopType);
@override
double get value => isFraction ? 1 / rawValue : rawValue;
@override
String toString() {
final buffer = StringBuffer();
if (isFraction) buffer.write("1/");
if (rawValue - rawValue.floor() == 0) {
buffer.write(rawValue.toInt().toString());
} else {
buffer.write(rawValue.toStringAsFixed(1));
}
if (!isFraction) buffer.write("\"");
return buffer.toString();
}
}
const List<ShutterSpeedValue> shutterSpeedValues = [
ShutterSpeedValue(2000, true, Stop.full),
ShutterSpeedValue(1600, true, Stop.third),
ShutterSpeedValue(1500, true, Stop.half),
ShutterSpeedValue(1250, true, Stop.third),
ShutterSpeedValue(1000, true, Stop.full),
ShutterSpeedValue(800, true, Stop.third),
ShutterSpeedValue(750, true, Stop.half),
ShutterSpeedValue(640, true, Stop.third),
ShutterSpeedValue(500, true, Stop.full),
ShutterSpeedValue(400, true, Stop.third),
ShutterSpeedValue(350, true, Stop.half),
ShutterSpeedValue(320, true, Stop.third),
ShutterSpeedValue(250, true, Stop.full),
ShutterSpeedValue(200, true, Stop.third),
ShutterSpeedValue(180, true, Stop.half),
ShutterSpeedValue(160, true, Stop.third),
ShutterSpeedValue(125, true, Stop.full),
ShutterSpeedValue(100, true, Stop.third),
ShutterSpeedValue(90, true, Stop.half),
ShutterSpeedValue(80, true, Stop.third),
ShutterSpeedValue(60, true, Stop.full),
ShutterSpeedValue(50, true, Stop.third),
ShutterSpeedValue(45, true, Stop.half),
ShutterSpeedValue(40, true, Stop.third),
ShutterSpeedValue(30, true, Stop.full),
ShutterSpeedValue(25, true, Stop.third),
ShutterSpeedValue(20, true, Stop.half),
ShutterSpeedValue(20, true, Stop.third),
ShutterSpeedValue(15, true, Stop.full),
ShutterSpeedValue(13, true, Stop.third),
ShutterSpeedValue(10, true, Stop.half),
ShutterSpeedValue(10, true, Stop.third),
ShutterSpeedValue(8, true, Stop.full),
ShutterSpeedValue(6, true, Stop.third),
ShutterSpeedValue(6, true, Stop.half),
ShutterSpeedValue(5, true, Stop.third),
ShutterSpeedValue(4, true, Stop.full),
ShutterSpeedValue(3, true, Stop.third),
ShutterSpeedValue(3, true, Stop.half),
ShutterSpeedValue(2.5, true, Stop.third),
ShutterSpeedValue(2, true, Stop.full),
ShutterSpeedValue(1.6, true, Stop.third),
ShutterSpeedValue(1.5, true, Stop.half),
ShutterSpeedValue(1.3, true, Stop.third),
ShutterSpeedValue(1, false, Stop.full),
ShutterSpeedValue(1.3, false, Stop.third),
ShutterSpeedValue(1.5, false, Stop.half),
ShutterSpeedValue(1.6, false, Stop.third),
ShutterSpeedValue(2, false, Stop.full),
ShutterSpeedValue(2.5, false, Stop.third),
ShutterSpeedValue(3, false, Stop.half),
ShutterSpeedValue(3, false, Stop.third),
ShutterSpeedValue(4, false, Stop.full),
ShutterSpeedValue(5, false, Stop.third),
ShutterSpeedValue(6, false, Stop.half),
ShutterSpeedValue(6, false, Stop.third),
ShutterSpeedValue(8, false, Stop.full),
ShutterSpeedValue(10, false, Stop.third),
ShutterSpeedValue(12, false, Stop.half),
ShutterSpeedValue(13, false, Stop.third),
ShutterSpeedValue(16, false, Stop.full),
];

View file

@ -9,11 +9,15 @@ environment:
dependencies:
flutter:
sdk: flutter
material_color_utilities: ^0.2.0
dev_dependencies:
flutter_test:
sdk: flutter
google_fonts: ^3.0.1
flutter_lints: ^2.0.0
test: ^1.21.6
dependency_overrides:
material_color_utilities: ^0.2.0
flutter:
uses-material-design: true

View file

@ -0,0 +1,38 @@
import 'package:lightmeter/models/photography_value.dart';
import 'package:test/test.dart';
void main() {
// Stringify
test('Stringify aperture values', () {
expect(apertureValues.first.toString(), "f/1.0");
expect(apertureValues.last.toString(), "f/45");
});
test('Stringify iso values', () {
expect(isoValues.first.toString(), "3");
expect(isoValues.last.toString(), "6400");
});
test('Stringify shutter speed values', () {
expect(shutterSpeedValues.first.toString(), "1/2000");
expect(shutterSpeedValues.last.toString(), "16\"");
});
// Stops
test('Aperture values stops lists', () {
expect(apertureValues.fullStops().length, 12);
expect(apertureValues.halfStops().length, 12 + 11);
expect(apertureValues.thirdStops().length, 12 + 22);
});
test('Iso values stops lists', () {
expect(isoValues.fullStops().length, 12);
expect(isoValues.thirdStops().length, 12 + 22);
});
test('Shutter speed values stops lists', () {
expect(shutterSpeedValues.fullStops().length, 16);
expect(shutterSpeedValues.halfStops().length, 16 + 15);
expect(shutterSpeedValues.thirdStops().length, 16 + 30);
});
}

View file

@ -1,30 +0,0 @@
// This is a basic Flutter widget test.
//
// To perform an interaction with a widget in your test, use the WidgetTester
// utility in the flutter_test package. For example, you can send tap and scroll
// gestures. You can also use WidgetTester to find child widgets in the widget
// tree, read text, and verify that the values of widget properties are correct.
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:lightmeter/main.dart';
void main() {
testWidgets('Counter increments smoke test', (WidgetTester tester) async {
// Build our app and trigger a frame.
await tester.pumpWidget(const MyApp());
// Verify that our counter starts at 0.
expect(find.text('0'), findsOneWidget);
expect(find.text('1'), findsNothing);
// Tap the '+' icon and trigger a frame.
await tester.tap(find.byIcon(Icons.add));
await tester.pump();
// Verify that our counter has incremented.
expect(find.text('0'), findsNothing);
expect(find.text('1'), findsOneWidget);
});
}