Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions color_models/lib/src/color_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ abstract class ColorModel {
: toListWithAlpha();
final valuesB =
end is RgbColor ? end.toPreciseListWithAlpha() : end.toListWithAlpha();
return withValues(List<num>.generate(valuesA.length,
return fromValues(List<num>.generate(valuesA.length,
(index) => _interpolateValue(valuesA[index], valuesB[index], step)));
}

Expand Down Expand Up @@ -131,7 +131,7 @@ abstract class ColorModel {
for (var j = 0; j < valuesA.length; j++) {
values.add(_interpolateValue(valuesA[j], valuesB[j], step));
}
colors.add(colorA.withValues(values));
colors.add(colorA.fromValues(values));
}

if (!excludeOriginalColors) {
Expand Down Expand Up @@ -198,7 +198,7 @@ abstract class ColorModel {
///
/// [values] should contain one value for each parameter of the color space;
/// the alpha value is optional.
ColorModel withValues(List<num> values);
ColorModel fromValues(List<num> values);

/// Returns a copy of this color modified with the provided values.
ColorModel copyWith({int? alpha});
Expand Down
16 changes: 8 additions & 8 deletions color_models/lib/src/helpers/color_converter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -508,8 +508,8 @@ class ColorConverter {
/// Converts a XYZ color to a LAB color.
static XyzColor labToXyz(LabColor labColor) {
final lightness = labColor.lightness;
final a = labColor.a;
final b = labColor.b;
final a = labColor.chromaticityA;
final b = labColor.chromaticityB;

var y = (lightness + 16) / 116;
var x = (a / 500) + y;
Expand Down Expand Up @@ -578,16 +578,16 @@ class ColorConverter {
}

final l = (oklabColor.lightness +
(0.3963377774 * oklabColor.a) +
(0.2158037573 * oklabColor.b))
(0.3963377774 * oklabColor.chromaticityA) +
(0.2158037573 * oklabColor.chromaticityB))
.cubed();
final m = (oklabColor.lightness -
(0.1055613458 * oklabColor.a) -
(0.0638541728 * oklabColor.b))
(0.1055613458 * oklabColor.chromaticityA) -
(0.0638541728 * oklabColor.chromaticityB))
.cubed();
final s = (oklabColor.lightness -
(0.0894841775 * oklabColor.a) -
(1.2914855480 * oklabColor.b))
(0.0894841775 * oklabColor.chromaticityA) -
(1.2914855480 * oklabColor.chromaticityB))
.cubed();

return _LinearRgbColor(
Expand Down
2 changes: 1 addition & 1 deletion color_models/lib/src/models/cmyk_color.dart
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ class CmykColor extends ColorModel {
}

@override
CmykColor withValues(List<num> values) {
CmykColor fromValues(List<num> values) {
assert(values.length == 4 || values.length == 5);
assert(values[0] >= 0 && values[0] <= 100);
assert(values[1] >= 0 && values[1] <= 100);
Expand Down
2 changes: 1 addition & 1 deletion color_models/lib/src/models/hsb_color.dart
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ class HsbColor extends ColorModel {
}

@override
HsbColor withValues(List<num> values) {
HsbColor fromValues(List<num> values) {
assert(values.length == 3 || values.length == 4);
assert(values[0] >= 0 && values[0] <= 360);
assert(values[1] >= 0 && values[1] <= 100);
Expand Down
2 changes: 1 addition & 1 deletion color_models/lib/src/models/hsi_color.dart
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ class HsiColor extends ColorModel {
}

@override
HsiColor withValues(List<num> values) {
HsiColor fromValues(List<num> values) {
assert(values.length == 3 || values.length == 4);
assert(values[0] >= 0 && values[0] <= 360);
assert(values[1] >= 0 && values[1] <= 100);
Expand Down
2 changes: 1 addition & 1 deletion color_models/lib/src/models/hsl_color.dart
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ class HslColor extends ColorModel {
}

@override
HslColor withValues(List<num> values) {
HslColor fromValues(List<num> values) {
assert(values.length == 3 || values.length == 4);
assert(values[0] >= 0 && values[0] <= 360);
assert(values[1] >= 0 && values[1] <= 100);
Expand Down
2 changes: 1 addition & 1 deletion color_models/lib/src/models/hsp_color.dart
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ class HspColor extends ColorModel {
}

@override
HspColor withValues(List<num> values) {
HspColor fromValues(List<num> values) {
assert(values.length == 3 || values.length == 4);
assert(values[0] >= 0 && values[0] <= 360);
assert(values[1] >= 0 && values[1] <= 100);
Expand Down
50 changes: 25 additions & 25 deletions color_models/lib/src/models/lab_color.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,19 @@ class LabColor extends ColorModel {
///
/// [lightness] must be `>= 0` and `<= 100`.
///
/// [a] and [b] must both be `>= -128` and `<= 127`.
/// [chromaticityA] and [b] must both be `>= -128` and `<= 127`.
///
/// [alpha] must be `>= 0` and `<= 255`.
///
/// {@endtemplate}
const LabColor(
this.lightness,
this.a,
this.b, [
this.chromaticityA,
this.chromaticityB, [
int alpha = 255,
]) : assert(lightness >= 0 && lightness <= 100),
assert(a >= -128 && a <= 127),
assert(b >= -128 && b <= 127),
assert(chromaticityA >= -128 && chromaticityA <= 127),
assert(chromaticityB >= -128 && chromaticityB <= 127),
assert(alpha >= 0 && alpha <= 255),
super(alpha: alpha);

Expand All @@ -47,30 +47,30 @@ class LabColor extends ColorModel {
/// Green is represented in the negative value range (`-128` to `0`)
///
/// Red is represented in the positive value range (`0` to `127`)
final num a;
final num chromaticityA;

/// The yellow to blue opponent color value.
///
/// Yellow is represented int he negative value range (`-128` to `0`)
///
/// Blue is represented in the positive value range (`0` to `127`)
final num b;
final num chromaticityB;

@override
bool get isBlack =>
ColorMath.round(lightness) == 0 &&
ColorMath.round(a) == 0 &&
ColorMath.round(b) == 0;
ColorMath.round(chromaticityA) == 0 &&
ColorMath.round(chromaticityB) == 0;

@override
bool get isWhite =>
ColorMath.round(lightness) == 1 &&
ColorMath.round(a) == 0 &&
ColorMath.round(b) == 0;
ColorMath.round(chromaticityA) == 0 &&
ColorMath.round(chromaticityB) == 0;

@override
bool get isMonochromatic =>
ColorMath.round(a) == 0 && ColorMath.round(b) == 0;
ColorMath.round(chromaticityA) == 0 && ColorMath.round(chromaticityB) == 0;

@override
LabColor interpolate(ColorModel end, double step) {
Expand All @@ -95,7 +95,7 @@ class LabColor extends ColorModel {

@override
LabColor get inverted => LabColor(
100 - lightness, 255 - (a + 128) - 128, 255 - (b + 128) - 128, alpha);
100 - lightness, 255 - (chromaticityA + 128) - 128, 255 - (chromaticityB + 128) - 128, alpha);

@override
LabColor get opposite => rotateHue(180);
Expand Down Expand Up @@ -138,7 +138,7 @@ class LabColor extends ColorModel {
@override
LabColor withAlpha(int alpha) {
assert(alpha >= 0 && alpha <= 255);
return LabColor(lightness, a, b, alpha);
return LabColor(lightness, chromaticityA, chromaticityB, alpha);
}

@override
Expand All @@ -148,7 +148,7 @@ class LabColor extends ColorModel {
}

@override
LabColor withValues(List<num> values) {
LabColor fromValues(List<num> values) {
assert(values.length == 3 || values.length == 4);
assert(values[0] >= 0 && values[0] <= 100);
assert(values[1] >= -128 && values[1] <= 127);
Expand All @@ -165,8 +165,8 @@ class LabColor extends ColorModel {
assert(alpha == null || (alpha >= 0 && alpha <= 255));
return LabColor(
lightness ?? this.lightness,
a ?? this.a,
b ?? this.b,
a ?? this.chromaticityA,
b ?? this.chromaticityB,
alpha ?? this.alpha,
);
}
Expand All @@ -183,13 +183,13 @@ class LabColor extends ColorModel {
/// Returns a fixed-length list containing the [lightness],
/// [a], and [b] values, in that order.
@override
List<num> toList() => List<num>.from(<num>[lightness, a, b], growable: false);
List<num> toList() => List<num>.from(<num>[lightness, chromaticityA, chromaticityB], growable: false);

/// Returns a fixed-length list containing the [lightness],
/// [a], [b], and [alpha] values, in that order.
@override
List<num> toListWithAlpha() =>
List<num>.from(<num>[lightness, a, b, alpha], growable: false);
List<num>.from(<num>[lightness, chromaticityA, chromaticityB, alpha], growable: false);

/// {@template color_models.LabColor.from}
///
Expand Down Expand Up @@ -259,9 +259,9 @@ class LabColor extends ColorModel {
/// [minLightness] and [maxLightness] constrain the generated [lightness]
/// value.
///
/// [minA] and [maxA] constrain the generated [a] value.
/// [minA] and [maxA] constrain the generated [chromaticityA] value.
///
/// [minB] and [maxB] constrain the generated [b] value.
/// [minB] and [maxB] constrain the generated [chromaticityB] value.
///
/// All min and max values must be `min <= max && max >= min`, must
/// be in the range of `>= 0 && <= 100`, and must not be `null`.
Expand Down Expand Up @@ -293,17 +293,17 @@ class LabColor extends ColorModel {
LabColor convert(ColorModel other) => other.toLabColor();

@override
String toString() => 'LabColor($lightness, $a, $b, $alpha)';
String toString() => 'LabColor($lightness, $chromaticityA, $chromaticityB, $alpha)';

@override
bool operator ==(Object other) =>
other is LabColor &&
ColorMath.round(lightness) == ColorMath.round(other.lightness) &&
ColorMath.round(a) == ColorMath.round(other.a) &&
ColorMath.round(b) == ColorMath.round(other.b) &&
ColorMath.round(chromaticityA) == ColorMath.round(other.chromaticityA) &&
ColorMath.round(chromaticityB) == ColorMath.round(other.chromaticityB) &&
alpha == other.alpha;

@override
int get hashCode =>
lightness.hashCode ^ a.hashCode ^ b.hashCode ^ alpha.hashCode;
lightness.hashCode ^ chromaticityA.hashCode ^ chromaticityB.hashCode ^ alpha.hashCode;
}
46 changes: 23 additions & 23 deletions color_models/lib/src/models/oklab_color.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class OklabColor extends ColorModel {
///
/// A color in the Oklab color space.
///
/// [lightness], [a], and [b]'s normal range is `0.0` to `1.0`,
/// [lightness], [chromaticityA], and [b]'s normal range is `0.0` to `1.0`,
/// but some colors may fall slightly outside of it.
///
/// [alpha] must be `>= 0` and `<= 255`.
Expand All @@ -32,8 +32,8 @@ class OklabColor extends ColorModel {
/// {@endtemplate}
const OklabColor(
this.lightness,
this.a,
this.b, [
this.chromaticityA,
this.chromaticityB, [
int alpha = 255,
]) : assert(alpha >= 0 && alpha <= 255),
super(alpha: alpha);
Expand All @@ -46,28 +46,28 @@ class OklabColor extends ColorModel {
/// The red to green opponent color value.
///
/// The value ranges from red at `0.0` to green at `1.0`.
final double a;
final double chromaticityA;

/// The yellow to blue opponent color value.
///
/// The value ranges from yellow at `0.0` to blue at `1.0`.
final double b;
final double chromaticityB;

@override
bool get isBlack =>
ColorMath.round(lightness) <= 0 &&
ColorMath.round(a) <= 0 &&
ColorMath.round(b) <= 0;
ColorMath.round(chromaticityA) <= 0 &&
ColorMath.round(chromaticityB) <= 0;

@override
bool get isWhite =>
ColorMath.round(lightness) >= 1 &&
ColorMath.round(a) <= 0 &&
ColorMath.round(b) <= 0;
ColorMath.round(chromaticityA) <= 0 &&
ColorMath.round(chromaticityB) <= 0;

@override
bool get isMonochromatic =>
ColorMath.round(a) == 0 && ColorMath.round(b) == 0;
ColorMath.round(chromaticityA) == 0 && ColorMath.round(chromaticityB) == 0;

@override
OklabColor interpolate(ColorModel end, double step) {
Expand All @@ -92,7 +92,7 @@ class OklabColor extends ColorModel {

@override
OklabColor get inverted =>
OklabColor(1.0 - lightness, 1.0 - a, 1.0 - b, alpha);
OklabColor(1.0 - lightness, 1.0 - chromaticityA, 1.0 - chromaticityB, alpha);

@override
OklabColor get opposite => rotateHue(180);
Expand Down Expand Up @@ -139,7 +139,7 @@ class OklabColor extends ColorModel {
@override
OklabColor withAlpha(int alpha) {
assert(alpha >= 0 && alpha <= 255);
return OklabColor(lightness, a, b, alpha);
return OklabColor(lightness, chromaticityA, chromaticityB, alpha);
}

@override
Expand All @@ -149,7 +149,7 @@ class OklabColor extends ColorModel {
}

@override
OklabColor withValues(List<num> values) {
OklabColor fromValues(List<num> values) {
assert(values.length == 3 || values.length == 4);
if (values.length == 4) assert(values[3] >= 0 && values[3] <= 255);
return OklabColor.fromList(values);
Expand All @@ -163,13 +163,13 @@ class OklabColor extends ColorModel {
int? alpha,
}) {
assert(lightness == null || (lightness >= 0 && lightness <= 1.0));
assert(a == null || (a >= 0 && a <= 1.0));
assert(b == null || (b >= 0 && b <= 1.0));
assert(a == null || (chromaticityA >= 0 && chromaticityA <= 1.0));
assert(b == null || (chromaticityB >= 0 && chromaticityB <= 1.0));
assert(alpha == null || (alpha >= 0 && alpha <= 255));
return OklabColor(
lightness ?? this.lightness,
a ?? this.a,
b ?? this.b,
a ?? this.chromaticityA,
b ?? this.chromaticityB,
alpha ?? this.alpha,
);
}
Expand All @@ -184,13 +184,13 @@ class OklabColor extends ColorModel {
/// [a], and [b] values, in that order.
@override
List<double> toList() =>
List<double>.from(<double>[lightness, a, b], growable: false);
List<double>.from(<double>[lightness, chromaticityA, chromaticityB], growable: false);

/// Returns a fixed-length list containing the [lightness],
/// [a], [b], and [alpha] values, in that order.
@override
List<num> toListWithAlpha() =>
List<num>.from(<num>[lightness, a, b, alpha], growable: false);
List<num>.from(<num>[lightness, chromaticityA, chromaticityB, alpha], growable: false);

/// {@template color_models.OklabColor.from}
///
Expand Down Expand Up @@ -262,17 +262,17 @@ class OklabColor extends ColorModel {
OklabColor convert(ColorModel other) => other.toOklabColor();

@override
String toString() => 'OklabColor($lightness, $a, $b, $alpha)';
String toString() => 'OklabColor($lightness, $chromaticityA, $chromaticityB, $alpha)';

@override
bool operator ==(Object other) =>
other is OklabColor &&
ColorMath.round(lightness) == ColorMath.round(other.lightness) &&
ColorMath.round(a) == ColorMath.round(other.a) &&
ColorMath.round(b) == ColorMath.round(other.b) &&
ColorMath.round(chromaticityA) == ColorMath.round(other.chromaticityA) &&
ColorMath.round(chromaticityA) == ColorMath.round(other.chromaticityB) &&
alpha == other.alpha;

@override
int get hashCode =>
lightness.hashCode ^ a.hashCode ^ b.hashCode ^ alpha.hashCode;
lightness.hashCode ^ chromaticityA.hashCode ^ chromaticityB.hashCode ^ alpha.hashCode;
}
Loading