| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library dart.typeddata; | 5 library dart.typeddata; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 | 8 |
| 9 /** | 9 /** |
| 10 * A sequence of bytes underlying a typed data object. | 10 * A sequence of bytes underlying a typed data object. |
| (...skipping 663 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 674 * the length of [buffer]. | 674 * the length of [buffer]. |
| 675 * | 675 * |
| 676 * Throws [ArgumentError] if [offsetInBytes] is not a multiple of | 676 * Throws [ArgumentError] if [offsetInBytes] is not a multiple of |
| 677 * BYTES_PER_ELEMENT. | 677 * BYTES_PER_ELEMENT. |
| 678 */ | 678 */ |
| 679 external factory Float64List.view(ByteBuffer buffer, | 679 external factory Float64List.view(ByteBuffer buffer, |
| 680 [int offsetInBytes = 0, int length]); | 680 [int offsetInBytes = 0, int length]); |
| 681 | 681 |
| 682 static const int BYTES_PER_ELEMENT = 8; | 682 static const int BYTES_PER_ELEMENT = 8; |
| 683 } | 683 } |
| 684 |
| 685 |
| 686 /** |
| 687 * A fixed-length list of Float32x4 numbers that is viewable as a |
| 688 * [TypedData]. For long lists, this implementation will be considerably more |
| 689 * space- and time-efficient than the default [List] implementation. |
| 690 */ |
| 691 abstract class Float32x4List implements List<Float32x4>, TypedData { |
| 692 /** |
| 693 * Creates a [Float32x4List] of the specified length (in elements), |
| 694 * all of whose elements are initially zero. |
| 695 */ |
| 696 external factory Float32x4List(int length); |
| 697 |
| 698 /** |
| 699 * Creates a [Float32x4List] _view_ of the specified region in the specified |
| 700 * byte buffer. Changes in the [Float32x4List] will be visible in the byte |
| 701 * buffer and vice versa. If the [offsetInBytes] index of the region is not |
| 702 * specified, it defaults to zero (the first byte in the byte buffer). |
| 703 * If the length is not specified, it defaults to null, which indicates |
| 704 * that the view extends to the end of the byte buffer. |
| 705 * |
| 706 * Throws [RangeError] if [offsetInBytes] or [length] are negative, or |
| 707 * if [offsetInBytes] + ([length] * elementSizeInBytes) is greater than |
| 708 * the length of [buffer]. |
| 709 * |
| 710 * Throws [ArgumentError] if [offsetInBytes] is not a multiple of |
| 711 * BYTES_PER_ELEMENT. |
| 712 */ |
| 713 external factory Float32x4List.view(ByteBuffer buffer, |
| 714 [int offsetInBytes = 0, int length]); |
| 715 |
| 716 static const int BYTES_PER_ELEMENT = 16; |
| 717 } |
| 718 |
| 719 |
| 720 /** |
| 721 * Interface of Dart Float32x4 immutable value type and operations. |
| 722 * Float32x4 stores 4 32-bit floating point values in "lanes". |
| 723 * The lanes are "x", "y", "z", and "w" respectively. |
| 724 */ |
| 725 abstract class Float32x4 { |
| 726 external factory Float32x4(double x, double y, double z, double w); |
| 727 external factory Float32x4.zero(); |
| 728 |
| 729 /// Addition operator. |
| 730 Float32x4 operator+(Float32x4 other); |
| 731 /// Negate operator. |
| 732 Float32x4 operator-(); |
| 733 /// Subtraction operator. |
| 734 Float32x4 operator-(Float32x4 other); |
| 735 /// Multiplication operator. |
| 736 Float32x4 operator*(Float32x4 other); |
| 737 /// Division operator. |
| 738 Float32x4 operator/(Float32x4 other); |
| 739 |
| 740 /// Relational less than. |
| 741 Uint32x4 lessThan(Float32x4 other); |
| 742 /// Relational less than or equal. |
| 743 Uint32x4 lessThanOrEqual(Float32x4 other); |
| 744 /// Relational greater than. |
| 745 Uint32x4 greaterThan(Float32x4 other); |
| 746 /// Relational greater than or equal. |
| 747 Uint32x4 greaterThanOrEqual(Float32x4 other); |
| 748 /// Relational equal. |
| 749 Uint32x4 equal(Float32x4 other); |
| 750 /// Relational not-equal. |
| 751 Uint32x4 notEqual(Float32x4 other); |
| 752 |
| 753 /// Returns a copy of [this] each lane being scaled by [s]. |
| 754 Float32x4 scale(double s); |
| 755 /// Returns the absolute value of this [Float32x4]. |
| 756 Float32x4 abs(); |
| 757 /// Clamps [this] to be in the range [lowerLimit]-[upperLimit]. |
| 758 Float32x4 clamp(Float32x4 lowerLimit, |
| 759 Float32x4 upperLimit); |
| 760 |
| 761 /// Extracted x value. |
| 762 double get x; |
| 763 /// Extracted y value. |
| 764 double get y; |
| 765 /// Extracted z value. |
| 766 double get z; |
| 767 /// Extracted w value. |
| 768 double get w; |
| 769 |
| 770 /// Returns a new [Float32x4] with [this]' x value in all four lanes. |
| 771 Float32x4 get xxxx; |
| 772 /// Returns a new [Float32x4] with [this]' y value in all four lanes. |
| 773 Float32x4 get yyyy; |
| 774 /// Returns a new [Float32x4] with [this]' z value in all four lanes. |
| 775 Float32x4 get zzzz; |
| 776 /// Returns a new [Float32x4] with [this]' w value in all four lanes. |
| 777 Float32x4 get wwww; |
| 778 // TODO(johnmccutchan): Add all 256 possible combinations. |
| 779 |
| 780 /// Returns a new [Float32x4] copied from [this] with a new x value. |
| 781 Float32x4 withX(double x); |
| 782 /// Returns a new [Float32x4] copied from [this] with a new y value. |
| 783 Float32x4 withY(double y); |
| 784 /// Returns a new [Float32x4] copied from [this] with a new z value. |
| 785 Float32x4 withZ(double z); |
| 786 /// Returns a new [Float32x4] copied from [this] with a new w value. |
| 787 Float32x4 withW(double w); |
| 788 |
| 789 /// Returns the lane-wise minimum value in [this] or [other]. |
| 790 Float32x4 min(Float32x4 other); |
| 791 |
| 792 /// Returns the lane-wise maximum value in [this] or [other]. |
| 793 Float32x4 max(Float32x4 other); |
| 794 |
| 795 /// Returns the square root of [this]. |
| 796 Float32x4 sqrt(); |
| 797 |
| 798 /// Returns the reciprocal of [this]. |
| 799 Float32x4 reciprocal(); |
| 800 |
| 801 /// Returns the square root of the reciprocal of [this]. |
| 802 Float32x4 reciprocalSqrt(); |
| 803 |
| 804 /// Returns a bit-wise copy of [this] as a [Uint32x4]. |
| 805 Uint32x4 toUint32x4(); |
| 806 } |
| 807 |
| 808 |
| 809 /** |
| 810 * Interface of Dart Uint32x4 and operations. |
| 811 * Uint32x4 stores 4 32-bit bit-masks in "lanes". |
| 812 * The lanes are "x", "y", "z", and "w" respectively. |
| 813 */ |
| 814 abstract class Uint32x4 { |
| 815 external factory Uint32x4(int x, int y, int z, int w); |
| 816 external factory Uint32x4.bool(bool x, bool y, bool z, bool w); |
| 817 |
| 818 /// The bit-wise or operator. |
| 819 Uint32x4 operator|(Uint32x4 other); |
| 820 /// The bit-wise and operator. |
| 821 Uint32x4 operator&(Uint32x4 other); |
| 822 /// The bit-wise xor operator. |
| 823 Uint32x4 operator^(Uint32x4 other); |
| 824 |
| 825 /// Extract 32-bit mask from x lane. |
| 826 int get x; |
| 827 /// Extract 32-bit mask from y lane. |
| 828 int get y; |
| 829 /// Extract 32-bit mask from z lane. |
| 830 int get z; |
| 831 /// Extract 32-bit mask from w lane. |
| 832 int get w; |
| 833 |
| 834 /// Returns a new [Uint32x4] copied from [this] with a new x value. |
| 835 Uint32x4 withX(int x); |
| 836 /// Returns a new [Uint32x4] copied from [this] with a new y value. |
| 837 Uint32x4 withY(int y); |
| 838 /// Returns a new [Uint32x4] copied from [this] with a new z value. |
| 839 Uint32x4 withZ(int z); |
| 840 /// Returns a new [Uint32x4] copied from [this] with a new w value. |
| 841 Uint32x4 withW(int w); |
| 842 |
| 843 /// Extracted x value. Returns false for 0, true for any other value. |
| 844 bool get flagX; |
| 845 /// Extracted y value. Returns false for 0, true for any other value. |
| 846 bool get flagY; |
| 847 /// Extracted z value. Returns false for 0, true for any other value. |
| 848 bool get flagZ; |
| 849 /// Extracted w value. Returns false for 0, true for any other value. |
| 850 bool get flagW; |
| 851 |
| 852 /// Returns a new [Uint32x4] copied from [this] with a new x value. |
| 853 Uint32x4 withFlagX(bool x); |
| 854 /// Returns a new [Uint32x4] copied from [this] with a new y value. |
| 855 Uint32x4 withFlagY(bool y); |
| 856 /// Returns a new [Uint32x4] copied from [this] with a new z value. |
| 857 Uint32x4 withFlagZ(bool z); |
| 858 /// Returns a new [Uint32x4] copied from [this] with a new w value. |
| 859 Uint32x4 withFlagW(bool w); |
| 860 |
| 861 /// Merge [trueValue] and [falseValue] based on [this]' bit mask: |
| 862 /// Select bit from [trueValue] when bit in [this] is on. |
| 863 /// Select bit from [falseValue] when bit in [this] is off. |
| 864 Float32x4 select(Float32x4 trueValue, Float32x4 falseValue); |
| 865 |
| 866 /// Returns a bit-wise copy of [this] as a [Float32x4]. |
| 867 Float32x4 toFloat32x4(); |
| 868 } |
| OLD | NEW |