| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868 |
- /* global QUnit */
- import { Color } from '../../../../src/math/Color.js';
- import { ColorManagement } from '../../../../src/math/ColorManagement.js';
- import { eps } from '../../utils/math-constants.js';
- import { CONSOLE_LEVEL } from '../../utils/console-wrapper.js';
- import { SRGBColorSpace } from '../../../../src/constants.js';
- export default QUnit.module( 'Maths', () => {
- QUnit.module( 'Color', () => {
- const colorManagementEnabled = ColorManagement.enabled;
- QUnit.testDone( () => {
- ColorManagement.enabled = colorManagementEnabled;
- } );
- // INSTANCING
- QUnit.test( 'Instancing', ( assert ) => {
- ColorManagement.enabled = false; // TODO: Update and enable.
- // default ctor
- let c = new Color();
- assert.ok( c.r, 'Red: ' + c.r );
- assert.ok( c.g, 'Green: ' + c.g );
- assert.ok( c.b, 'Blue: ' + c.b );
- // rgb ctor
- c = new Color( 1, 1, 1 );
- assert.ok( c.r == 1, 'Passed' );
- assert.ok( c.g == 1, 'Passed' );
- assert.ok( c.b == 1, 'Passed' );
- } );
- // EXPOSED CONSTANTS
- QUnit.test( 'Color.NAMES', ( assert ) => {
- ColorManagement.enabled = false; // TODO: Update and enable.
- assert.ok( Color.NAMES.aliceblue == 0xF0F8FF, 'Exposed Color.NAMES' );
- } );
- // PUBLIC STUFF
- QUnit.test( 'isColor', ( assert ) => {
- ColorManagement.enabled = false; // TODO: Update and enable.
- const a = new Color();
- assert.ok( a.isColor === true, 'Passed!' );
- const b = new Object();
- assert.ok( ! b.isColor, 'Passed!' );
- } );
- QUnit.test( 'set', ( assert ) => {
- ColorManagement.enabled = false; // TODO: Update and enable.
- const a = new Color();
- const b = new Color( 0.5, 0, 0 );
- const c = new Color( 0xFF0000 );
- const d = new Color( 0, 1.0, 0 );
- const e = new Color( 0.5, 0.5, 0.5 );
- a.set( b );
- assert.ok( a.equals( b ), 'Set with Color instance' );
- a.set( 0xFF0000 );
- assert.ok( a.equals( c ), 'Set with number' );
- a.set( 'rgb(0,255,0)' );
- assert.ok( a.equals( d ), 'Set with style' );
- a.set( 0.5, 0.5, 0.5 );
- assert.ok( a.equals( e ), 'Set with r,g,b components' );
- } );
- QUnit.test( 'setScalar', ( assert ) => {
- ColorManagement.enabled = false; // TODO: Update and enable.
- const c = new Color();
- c.setScalar( 0.5 );
- assert.ok( c.r == 0.5, 'Red: ' + c.r );
- assert.ok( c.g == 0.5, 'Green: ' + c.g );
- assert.ok( c.b == 0.5, 'Blue: ' + c.b );
- } );
- QUnit.test( 'setHex', ( assert ) => {
- ColorManagement.enabled = false; // TODO: Update and enable.
- const c = new Color();
- c.setHex( 0xFA8072 );
- assert.ok( c.getHex() == 0xFA8072, 'Hex: ' + c.getHex() );
- assert.ok( c.r == 0xFA / 0xFF, 'Red: ' + c.r );
- assert.ok( c.g == 0x80 / 0xFF, 'Green: ' + c.g );
- assert.ok( c.b == 0x72 / 0xFF, 'Blue: ' + c.b );
- } );
- QUnit.test( 'setRGB', ( assert ) => {
- ColorManagement.enabled = true;
- const c = new Color();
- c.setRGB( 0.3, 0.5, 0.7 );
- assert.equal( c.r, 0.3, 'Red: ' + c.r + ' (srgb-linear)' );
- assert.equal( c.g, 0.5, 'Green: ' + c.g + ' (srgb-linear)' );
- assert.equal( c.b, 0.7, 'Blue: ' + c.b + ' (srgb-linear)' );
- c.setRGB( 0.3, 0.5, 0.7, SRGBColorSpace );
- assert.equal( c.r.toFixed( 3 ), 0.073, 'Red: ' + c.r + ' (srgb)' );
- assert.equal( c.g.toFixed( 3 ), 0.214, 'Green: ' + c.g + ' (srgb)' );
- assert.equal( c.b.toFixed( 3 ), 0.448, 'Blue: ' + c.b + ' (srgb)' );
- } );
- QUnit.test( 'setHSL', ( assert ) => {
- ColorManagement.enabled = false; // TODO: Update and enable.
- const c = new Color();
- const hsl = { h: 0, s: 0, l: 0 };
- c.setHSL( 0.75, 1.0, 0.25 );
- c.getHSL( hsl );
- assert.ok( hsl.h == 0.75, 'hue: ' + hsl.h );
- assert.ok( hsl.s == 1.00, 'saturation: ' + hsl.s );
- assert.ok( hsl.l == 0.25, 'lightness: ' + hsl.l );
- } );
- QUnit.test( 'setStyle', ( assert ) => {
- ColorManagement.enabled = false; // TODO: Update and enable.
- const a = new Color();
- let b = new Color( 8 / 255, 25 / 255, 178 / 255 );
- a.setStyle( 'rgb(8,25,178)' );
- assert.ok( a.equals( b ), 'Passed' );
- b = new Color( 8 / 255, 25 / 255, 178 / 255 );
- a.setStyle( 'rgba(8,25,178,200)' );
- assert.ok( a.equals( b ), 'Passed' );
- let hsl = { h: 0, s: 0, l: 0 };
- a.setStyle( 'hsl(270,50%,75%)' );
- a.getHSL( hsl );
- assert.ok( hsl.h == 0.75, 'hue: ' + hsl.h );
- assert.ok( hsl.s == 0.5, 'saturation: ' + hsl.s );
- assert.ok( hsl.l == 0.75, 'lightness: ' + hsl.l );
- hsl = { h: 0, s: 0, l: 0 };
- a.setStyle( 'hsl(270,50%,75%)' );
- a.getHSL( hsl );
- assert.ok( hsl.h == 0.75, 'hue: ' + hsl.h );
- assert.ok( hsl.s == 0.5, 'saturation: ' + hsl.s );
- assert.ok( hsl.l == 0.75, 'lightness: ' + hsl.l );
- a.setStyle( '#F8A' );
- assert.ok( a.r == 0xFF / 255, 'Red: ' + a.r );
- assert.ok( a.g == 0x88 / 255, 'Green: ' + a.g );
- assert.ok( a.b == 0xAA / 255, 'Blue: ' + a.b );
- a.setStyle( '#F8ABC1' );
- assert.ok( a.r == 0xF8 / 255, 'Red: ' + a.r );
- assert.ok( a.g == 0xAB / 255, 'Green: ' + a.g );
- assert.ok( a.b == 0xC1 / 255, 'Blue: ' + a.b );
- a.setStyle( 'aliceblue' );
- assert.ok( a.r == 0xF0 / 255, 'Red: ' + a.r );
- assert.ok( a.g == 0xF8 / 255, 'Green: ' + a.g );
- assert.ok( a.b == 0xFF / 255, 'Blue: ' + a.b );
- } );
- QUnit.test( 'setColorName', ( assert ) => {
- ColorManagement.enabled = false; // TODO: Update and enable.
- const c = new Color();
- const res = c.setColorName( 'aliceblue' );
- assert.ok( c.getHex() == 0xF0F8FF, 'Hex: ' + c.getHex() );
- assert.ok( c == res, 'Returns Self' );
- } );
- QUnit.test( 'clone', ( assert ) => {
- ColorManagement.enabled = false; // TODO: Update and enable.
- const c = new Color( 'teal' );
- const c2 = c.clone();
- assert.ok( c2.getHex() == 0x008080, 'Hex c2: ' + c2.getHex() );
- } );
- QUnit.test( 'copy', ( assert ) => {
- ColorManagement.enabled = false; // TODO: Update and enable.
- const a = new Color( 'teal' );
- const b = new Color();
- b.copy( a );
- assert.ok( b.r == 0x00 / 255, 'Red: ' + b.r );
- assert.ok( b.g == 0x80 / 255, 'Green: ' + b.g );
- assert.ok( b.b == 0x80 / 255, 'Blue: ' + b.b );
- } );
- QUnit.test( 'copySRGBToLinear', ( assert ) => {
- ColorManagement.enabled = false; // TODO: Update and enable.
- const c = new Color();
- const c2 = new Color();
- c2.setRGB( 0.3, 0.5, 0.9 );
- c.copySRGBToLinear( c2 );
- assert.numEqual( c.r, 0.09, 'Red c: ' + c.r + ' Red c2: ' + c2.r );
- assert.numEqual( c.g, 0.25, 'Green c: ' + c.g + ' Green c2: ' + c2.g );
- assert.numEqual( c.b, 0.81, 'Blue c: ' + c.b + ' Blue c2: ' + c2.b );
- } );
- QUnit.test( 'copyLinearToSRGB', ( assert ) => {
- ColorManagement.enabled = false; // TODO: Update and enable.
- const c = new Color();
- const c2 = new Color();
- c2.setRGB( 0.09, 0.25, 0.81 );
- c.copyLinearToSRGB( c2 );
- assert.numEqual( c.r, 0.3, 'Red c: ' + c.r + ' Red c2: ' + c2.r );
- assert.numEqual( c.g, 0.5, 'Green c: ' + c.g + ' Green c2: ' + c2.g );
- assert.numEqual( c.b, 0.9, 'Blue c: ' + c.b + ' Blue c2: ' + c2.b );
- } );
- QUnit.test( 'convertSRGBToLinear', ( assert ) => {
- ColorManagement.enabled = false; // TODO: Update and enable.
- const c = new Color();
- c.setRGB( 0.3, 0.5, 0.9 );
- c.convertSRGBToLinear();
- assert.numEqual( c.r, 0.09, 'Red: ' + c.r );
- assert.numEqual( c.g, 0.25, 'Green: ' + c.g );
- assert.numEqual( c.b, 0.81, 'Blue: ' + c.b );
- } );
- QUnit.test( 'convertLinearToSRGB', ( assert ) => {
- ColorManagement.enabled = false; // TODO: Update and enable.
- const c = new Color();
- c.setRGB( 4, 9, 16 );
- c.convertLinearToSRGB();
- assert.numEqual( c.r, 1.82, 'Red: ' + c.r );
- assert.numEqual( c.g, 2.58, 'Green: ' + c.g );
- assert.numEqual( c.b, 3.29, 'Blue: ' + c.b );
- } );
- QUnit.test( 'getHex', ( assert ) => {
- ColorManagement.enabled = false; // TODO: Update and enable.
- const c = new Color( 'red' );
- const res = c.getHex();
- assert.ok( res == 0xFF0000, 'Hex: ' + res );
- } );
- QUnit.test( 'getHexString', ( assert ) => {
- ColorManagement.enabled = false; // TODO: Update and enable.
- const c = new Color( 'tomato' );
- const res = c.getHexString();
- assert.ok( res == 'ff6347', 'Hex: ' + res );
- } );
- QUnit.test( 'getHSL', ( assert ) => {
- ColorManagement.enabled = false; // TODO: Update and enable.
- const c = new Color( 0x80ffff );
- const hsl = { h: 0, s: 0, l: 0 };
- c.getHSL( hsl );
- assert.ok( hsl.h == 0.5, 'hue: ' + hsl.h );
- assert.ok( hsl.s == 1.0, 'saturation: ' + hsl.s );
- assert.ok( ( Math.round( parseFloat( hsl.l ) * 100 ) / 100 ) == 0.75, 'lightness: ' + hsl.l );
- } );
- QUnit.test( 'getRGB', ( assert ) => {
- ColorManagement.enabled = true;
- const c = new Color( 'plum' );
- const t = { r: 0, g: 0, b: 0 };
- c.getRGB( t );
- assert.equal( t.r.toFixed( 3 ), 0.723, 'r (srgb-linear)' );
- assert.equal( t.g.toFixed( 3 ), 0.352, 'g (srgb-linear)' );
- assert.equal( t.b.toFixed( 3 ), 0.723, 'b (srgb-linear)' );
- c.getRGB( t, SRGBColorSpace );
- assert.equal( t.r.toFixed( 3 ), ( 221 / 255 ).toFixed( 3 ), 'r (srgb)' );
- assert.equal( t.g.toFixed( 3 ), ( 160 / 255 ).toFixed( 3 ), 'g (srgb)' );
- assert.equal( t.b.toFixed( 3 ), ( 221 / 255 ).toFixed( 3 ), 'b (srgb)' );
- } );
- QUnit.test( 'getStyle', ( assert ) => {
- ColorManagement.enabled = true;
- const c = new Color( 'plum' );
- assert.equal( c.getStyle(), 'rgb(221,160,221)', 'style: srgb' );
- } );
- QUnit.test( 'offsetHSL', ( assert ) => {
- ColorManagement.enabled = false; // TODO: Update and enable.
- const a = new Color( 'hsl(120,50%,50%)' );
- const b = new Color( 0.36, 0.84, 0.648 );
- a.offsetHSL( 0.1, 0.1, 0.1 );
- assert.ok( Math.abs( a.r - b.r ) <= eps, 'Check r' );
- assert.ok( Math.abs( a.g - b.g ) <= eps, 'Check g' );
- assert.ok( Math.abs( a.b - b.b ) <= eps, 'Check b' );
- } );
- QUnit.test( 'add', ( assert ) => {
- ColorManagement.enabled = false; // TODO: Update and enable.
- const a = new Color( 0x0000FF );
- const b = new Color( 0xFF0000 );
- const c = new Color( 0xFF00FF );
- a.add( b );
- assert.ok( a.equals( c ), 'Check new value' );
- } );
- QUnit.test( 'addColors', ( assert ) => {
- ColorManagement.enabled = false; // TODO: Update and enable.
- const a = new Color( 0x0000FF );
- const b = new Color( 0xFF0000 );
- const c = new Color( 0xFF00FF );
- const d = new Color();
- d.addColors( a, b );
- assert.ok( d.equals( c ), 'Passed' );
- } );
- QUnit.test( 'addScalar', ( assert ) => {
- ColorManagement.enabled = false; // TODO: Update and enable.
- const a = new Color( 0.1, 0.0, 0.0 );
- const b = new Color( 0.6, 0.5, 0.5 );
- a.addScalar( 0.5 );
- assert.ok( a.equals( b ), 'Check new value' );
- } );
- QUnit.test( 'sub', ( assert ) => {
- ColorManagement.enabled = false; // TODO: Update and enable.
- const a = new Color( 0x0000CC );
- const b = new Color( 0xFF0000 );
- const c = new Color( 0x0000AA );
- a.sub( b );
- assert.strictEqual( a.getHex(), 0xCC, 'Difference too large' );
- a.sub( c );
- assert.strictEqual( a.getHex(), 0x22, 'Difference fine' );
- } );
- QUnit.test( 'multiply', ( assert ) => {
- ColorManagement.enabled = false; // TODO: Update and enable.
- const a = new Color( 1, 0, 0.5 );
- const b = new Color( 0.5, 1, 0.5 );
- const c = new Color( 0.5, 0, 0.25 );
- a.multiply( b );
- assert.ok( a.equals( c ), 'Check new value' );
- } );
- QUnit.test( 'multiplyScalar', ( assert ) => {
- ColorManagement.enabled = false; // TODO: Update and enable.
- const a = new Color( 0.25, 0, 0.5 );
- const b = new Color( 0.5, 0, 1 );
- a.multiplyScalar( 2 );
- assert.ok( a.equals( b ), 'Check new value' );
- } );
- QUnit.test( 'lerp', ( assert ) => {
- ColorManagement.enabled = false; // TODO: Update and enable.
- const c = new Color();
- const c2 = new Color();
- c.setRGB( 0, 0, 0 );
- c.lerp( c2, 0.2 );
- assert.ok( c.r == 0.2, 'Red: ' + c.r );
- assert.ok( c.g == 0.2, 'Green: ' + c.g );
- assert.ok( c.b == 0.2, 'Blue: ' + c.b );
- } );
- QUnit.todo( 'lerpColors', ( assert ) => {
- // lerpColors( color1, color2, alpha )
- assert.ok( false, 'everything\'s gonna be alright' );
- } );
- QUnit.todo( 'lerpHSL', ( assert ) => {
- // lerpHSL( color, alpha )
- assert.ok( false, 'everything\'s gonna be alright' );
- } );
- QUnit.test( 'equals', ( assert ) => {
- ColorManagement.enabled = false; // TODO: Update and enable.
- const a = new Color( 0.5, 0.0, 1.0 );
- const b = new Color( 0.5, 1.0, 0.0 );
- assert.strictEqual( a.r, b.r, 'Components: r is equal' );
- assert.notStrictEqual( a.g, b.g, 'Components: g is not equal' );
- assert.notStrictEqual( a.b, b.b, 'Components: b is not equal' );
- assert.notOk( a.equals( b ), 'equals(): a not equal b' );
- assert.notOk( b.equals( a ), 'equals(): b not equal a' );
- a.copy( b );
- assert.strictEqual( a.r, b.r, 'Components after copy(): r is equal' );
- assert.strictEqual( a.g, b.g, 'Components after copy(): g is equal' );
- assert.strictEqual( a.b, b.b, 'Components after copy(): b is equal' );
- assert.ok( a.equals( b ), 'equals() after copy(): a equals b' );
- assert.ok( b.equals( a ), 'equals() after copy(): b equals a' );
- } );
- QUnit.test( 'fromArray', ( assert ) => {
- ColorManagement.enabled = false; // TODO: Update and enable.
- const a = new Color();
- const array = [ 0.5, 0.6, 0.7, 0, 1, 0 ];
- a.fromArray( array );
- assert.strictEqual( a.r, 0.5, 'No offset: check r' );
- assert.strictEqual( a.g, 0.6, 'No offset: check g' );
- assert.strictEqual( a.b, 0.7, 'No offset: check b' );
- a.fromArray( array, 3 );
- assert.strictEqual( a.r, 0, 'With offset: check r' );
- assert.strictEqual( a.g, 1, 'With offset: check g' );
- assert.strictEqual( a.b, 0, 'With offset: check b' );
- } );
- QUnit.test( 'toArray', ( assert ) => {
- ColorManagement.enabled = false; // TODO: Update and enable.
- const r = 0.5, g = 1.0, b = 0.0;
- const a = new Color( r, g, b );
- let array = a.toArray();
- assert.strictEqual( array[ 0 ], r, 'No array, no offset: check r' );
- assert.strictEqual( array[ 1 ], g, 'No array, no offset: check g' );
- assert.strictEqual( array[ 2 ], b, 'No array, no offset: check b' );
- array = [];
- a.toArray( array );
- assert.strictEqual( array[ 0 ], r, 'With array, no offset: check r' );
- assert.strictEqual( array[ 1 ], g, 'With array, no offset: check g' );
- assert.strictEqual( array[ 2 ], b, 'With array, no offset: check b' );
- array = [];
- a.toArray( array, 1 );
- assert.strictEqual( array[ 0 ], undefined, 'With array and offset: check [0]' );
- assert.strictEqual( array[ 1 ], r, 'With array and offset: check r' );
- assert.strictEqual( array[ 2 ], g, 'With array and offset: check g' );
- assert.strictEqual( array[ 3 ], b, 'With array and offset: check b' );
- } );
- QUnit.todo( 'fromBufferAttribute', ( assert ) => {
- // fromBufferAttribute( attribute, index )
- assert.ok( false, 'everything\'s gonna be alright' );
- } );
- QUnit.test( 'toJSON', ( assert ) => {
- ColorManagement.enabled = false; // TODO: Update and enable.
- const a = new Color( 0.0, 0.0, 0.0 );
- const b = new Color( 0.0, 0.5, 0.0 );
- const c = new Color( 1.0, 0.0, 0.0 );
- const d = new Color( 1.0, 1.0, 1.0 );
- assert.strictEqual( a.toJSON(), 0x000000, 'Check black' );
- assert.strictEqual( b.toJSON(), 0x008000, 'Check half-blue' );
- assert.strictEqual( c.toJSON(), 0xFF0000, 'Check red' );
- assert.strictEqual( d.toJSON(), 0xFFFFFF, 'Check white' );
- } );
- // OTHERS - FUNCTIONAL
- QUnit.test( 'copyHex', ( assert ) => {
- ColorManagement.enabled = false; // TODO: Update and enable.
- const c = new Color();
- const c2 = new Color( 0xF5FFFA );
- c.copy( c2 );
- assert.ok( c.getHex() == c2.getHex(), 'Hex c: ' + c.getHex() + ' Hex c2: ' + c2.getHex() );
- } );
- QUnit.test( 'copyColorString', ( assert ) => {
- ColorManagement.enabled = false; // TODO: Update and enable.
- const c = new Color();
- const c2 = new Color( 'ivory' );
- c.copy( c2 );
- assert.ok( c.getHex() == c2.getHex(), 'Hex c: ' + c.getHex() + ' Hex c2: ' + c2.getHex() );
- } );
- QUnit.test( 'setWithNum', ( assert ) => {
- ColorManagement.enabled = false; // TODO: Update and enable.
- const c = new Color();
- c.set( 0xFF0000 );
- assert.ok( c.r == 1, 'Red: ' + c.r );
- assert.ok( c.g === 0, 'Green: ' + c.g );
- assert.ok( c.b === 0, 'Blue: ' + c.b );
- } );
- QUnit.test( 'setWithString', ( assert ) => {
- ColorManagement.enabled = false; // TODO: Update and enable.
- const c = new Color();
- c.set( 'silver' );
- assert.ok( c.getHex() == 0xC0C0C0, 'Hex c: ' + c.getHex() );
- } );
- QUnit.test( 'setStyleRGBRed', ( assert ) => {
- ColorManagement.enabled = false; // TODO: Update and enable.
- const c = new Color();
- c.setStyle( 'rgb(255,0,0)' );
- assert.ok( c.r == 1, 'Red: ' + c.r );
- assert.ok( c.g === 0, 'Green: ' + c.g );
- assert.ok( c.b === 0, 'Blue: ' + c.b );
- } );
- QUnit.test( 'setStyleRGBARed', ( assert ) => {
- ColorManagement.enabled = false; // TODO: Update and enable.
- const c = new Color();
- console.level = CONSOLE_LEVEL.ERROR;
- c.setStyle( 'rgba(255,0,0,0.5)' );
- console.level = CONSOLE_LEVEL.DEFAULT;
- assert.ok( c.r == 1, 'Red: ' + c.r );
- assert.ok( c.g === 0, 'Green: ' + c.g );
- assert.ok( c.b === 0, 'Blue: ' + c.b );
- } );
- QUnit.test( 'setStyleRGBRedWithSpaces', ( assert ) => {
- ColorManagement.enabled = false; // TODO: Update and enable.
- const c = new Color();
- c.setStyle( 'rgb( 255 , 0, 0 )' );
- assert.ok( c.r == 1, 'Red: ' + c.r );
- assert.ok( c.g === 0, 'Green: ' + c.g );
- assert.ok( c.b === 0, 'Blue: ' + c.b );
- } );
- QUnit.test( 'setStyleRGBARedWithSpaces', ( assert ) => {
- ColorManagement.enabled = false; // TODO: Update and enable.
- const c = new Color();
- c.setStyle( 'rgba( 255, 0, 0 , 1 )' );
- assert.ok( c.r == 1, 'Red: ' + c.r );
- assert.ok( c.g === 0, 'Green: ' + c.g );
- assert.ok( c.b === 0, 'Blue: ' + c.b );
- } );
- QUnit.test( 'setStyleRGBPercent', ( assert ) => {
- ColorManagement.enabled = false; // TODO: Update and enable.
- const c = new Color();
- c.setStyle( 'rgb(100%,50%,10%)' );
- assert.ok( c.r == 1, 'Red: ' + c.r );
- assert.ok( c.g == 0.5, 'Green: ' + c.g );
- assert.ok( c.b == 0.1, 'Blue: ' + c.b );
- } );
- QUnit.test( 'setStyleRGBAPercent', ( assert ) => {
- ColorManagement.enabled = false; // TODO: Update and enable.
- const c = new Color();
- console.level = CONSOLE_LEVEL.ERROR;
- c.setStyle( 'rgba(100%,50%,10%, 0.5)' );
- console.level = CONSOLE_LEVEL.DEFAULT;
- assert.ok( c.r == 1, 'Red: ' + c.r );
- assert.ok( c.g == 0.5, 'Green: ' + c.g );
- assert.ok( c.b == 0.1, 'Blue: ' + c.b );
- } );
- QUnit.test( 'setStyleRGBPercentWithSpaces', ( assert ) => {
- ColorManagement.enabled = false; // TODO: Update and enable.
- const c = new Color();
- c.setStyle( 'rgb( 100% ,50% , 10% )' );
- assert.ok( c.r == 1, 'Red: ' + c.r );
- assert.ok( c.g == 0.5, 'Green: ' + c.g );
- assert.ok( c.b == 0.1, 'Blue: ' + c.b );
- } );
- QUnit.test( 'setStyleRGBAPercentWithSpaces', ( assert ) => {
- ColorManagement.enabled = false; // TODO: Update and enable.
- const c = new Color();
- console.level = CONSOLE_LEVEL.ERROR;
- c.setStyle( 'rgba( 100% ,50% , 10%, 0.5 )' );
- console.level = CONSOLE_LEVEL.DEFAULT;
- assert.ok( c.r == 1, 'Red: ' + c.r );
- assert.ok( c.g == 0.5, 'Green: ' + c.g );
- assert.ok( c.b == 0.1, 'Blue: ' + c.b );
- } );
- QUnit.test( 'setStyleHSLRed', ( assert ) => {
- ColorManagement.enabled = false; // TODO: Update and enable.
- const c = new Color();
- c.setStyle( 'hsl(360,100%,50%)' );
- assert.ok( c.r == 1, 'Red: ' + c.r );
- assert.ok( c.g === 0, 'Green: ' + c.g );
- assert.ok( c.b === 0, 'Blue: ' + c.b );
- } );
- QUnit.test( 'setStyleHSLARed', ( assert ) => {
- ColorManagement.enabled = false; // TODO: Update and enable.
- const c = new Color();
- console.level = CONSOLE_LEVEL.ERROR;
- c.setStyle( 'hsla(360,100%,50%,0.5)' );
- console.level = CONSOLE_LEVEL.DEFAULT;
- assert.ok( c.r == 1, 'Red: ' + c.r );
- assert.ok( c.g === 0, 'Green: ' + c.g );
- assert.ok( c.b === 0, 'Blue: ' + c.b );
- } );
- QUnit.test( 'setStyleHSLRedWithSpaces', ( assert ) => {
- ColorManagement.enabled = false; // TODO: Update and enable.
- const c = new Color();
- c.setStyle( 'hsl(360, 100% , 50% )' );
- assert.ok( c.r == 1, 'Red: ' + c.r );
- assert.ok( c.g === 0, 'Green: ' + c.g );
- assert.ok( c.b === 0, 'Blue: ' + c.b );
- } );
- QUnit.test( 'setStyleHSLARedWithSpaces', ( assert ) => {
- ColorManagement.enabled = false; // TODO: Update and enable.
- const c = new Color();
- console.level = CONSOLE_LEVEL.ERROR;
- c.setStyle( 'hsla( 360, 100% , 50%, 0.5 )' );
- console.level = CONSOLE_LEVEL.DEFAULT;
- assert.ok( c.r == 1, 'Red: ' + c.r );
- assert.ok( c.g === 0, 'Green: ' + c.g );
- assert.ok( c.b === 0, 'Blue: ' + c.b );
- } );
- QUnit.test( 'setStyleHSLRedWithDecimals', ( assert ) => {
- ColorManagement.enabled = false; // TODO: Update and enable.
- const c = new Color();
- c.setStyle( 'hsl(360,100.0%,50.0%)' );
- assert.ok( c.r == 1, 'Red: ' + c.r );
- assert.ok( c.g === 0, 'Green: ' + c.g );
- assert.ok( c.b === 0, 'Blue: ' + c.b );
- } );
- QUnit.test( 'setStyleHSLARedWithDecimals', ( assert ) => {
- ColorManagement.enabled = false; // TODO: Update and enable.
- const c = new Color();
- console.level = CONSOLE_LEVEL.ERROR;
- c.setStyle( 'hsla(360,100.0%,50.0%,0.5)' );
- console.level = CONSOLE_LEVEL.DEFAULT;
- assert.ok( c.r == 1, 'Red: ' + c.r );
- assert.ok( c.g === 0, 'Green: ' + c.g );
- assert.ok( c.b === 0, 'Blue: ' + c.b );
- } );
- QUnit.test( 'setStyleHexSkyBlue', ( assert ) => {
- ColorManagement.enabled = false; // TODO: Update and enable.
- const c = new Color();
- c.setStyle( '#87CEEB' );
- assert.ok( c.getHex() == 0x87CEEB, 'Hex c: ' + c.getHex() );
- } );
- QUnit.test( 'setStyleHexSkyBlueMixed', ( assert ) => {
- ColorManagement.enabled = false; // TODO: Update and enable.
- const c = new Color();
- c.setStyle( '#87cEeB' );
- assert.ok( c.getHex() == 0x87CEEB, 'Hex c: ' + c.getHex() );
- } );
- QUnit.test( 'setStyleHex2Olive', ( assert ) => {
- ColorManagement.enabled = false; // TODO: Update and enable.
- const c = new Color();
- c.setStyle( '#F00' );
- assert.ok( c.getHex() == 0xFF0000, 'Hex c: ' + c.getHex() );
- } );
- QUnit.test( 'setStyleHex2OliveMixed', ( assert ) => {
- ColorManagement.enabled = false; // TODO: Update and enable.
- const c = new Color();
- c.setStyle( '#f00' );
- assert.ok( c.getHex() == 0xFF0000, 'Hex c: ' + c.getHex() );
- } );
- QUnit.test( 'setStyleColorName', ( assert ) => {
- ColorManagement.enabled = false; // TODO: Update and enable.
- const c = new Color();
- c.setStyle( 'powderblue' );
- assert.ok( c.getHex() == 0xB0E0E6, 'Hex c: ' + c.getHex() );
- } );
- QUnit.test( 'iterable', ( assert ) => {
- ColorManagement.enabled = false; // TODO: Update and enable.
- const c = new Color( 0.5, 0.75, 1 );
- const array = [ ...c ];
- assert.strictEqual( array[ 0 ], 0.5, 'Color is iterable.' );
- assert.strictEqual( array[ 1 ], 0.75, 'Color is iterable.' );
- assert.strictEqual( array[ 2 ], 1, 'Color is iterable.' );
- } );
- } );
- } );
|