forked from google/create-framework
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpoint.dart
48 lines (35 loc) · 1.28 KB
/
point.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Copyright 2019 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import '../../elements.dart';
import 'styles.dart';
const X_FIELD = 'x';
const Y_FIELD = 'y';
class Point extends ImmutableCompositeData {
final DataId dataId;
final WriteOnce<double> x;
final WriteOnce<double> y;
Point(double x, double y)
: dataId = styleIdSource.nextId(),
x = WriteOnce<double>(x),
y = WriteOnce<double>(y);
Point.uninitialized([DataId dataId])
: dataId = dataId != null ? dataId : styleIdSource.nextId(),
x = WriteOnce<double>(),
y = WriteOnce<double>();
PointDataType get dataType => POINT_DATATYPE;
void visit(FieldVisitor visitor) {
visitor.doubleField(X_FIELD, x);
visitor.doubleField(Y_FIELD, y);
}
@override
int get hashCode => x.value.hashCode * 31 + y.value.hashCode;
@override
bool operator ==(dynamic o) => o is Point && o.x.value == x.value && o.y.value == y.value;
}
class PointDataType extends ImmutableCompositeDataType {
const PointDataType() : super(STYLES_NAMESPACE, 'point');
@override
Point newInstance(DataId dataId) => Point.uninitialized(dataId);
}
const PointDataType POINT_DATATYPE = const PointDataType();