Appearance
dart:math
Mathematical constants and functions, plus a random number generator.
To use this library in your code:
dart
import 'dart:math';Random
Random is a generator of bool, int or double values.
dart
var intValue = Random().nextInt(10); // Value is >= 0 and < 10.
var doubleValue = Random().nextDouble(); // Value is >= 0.0 and < 1.0.
var boolValue = Random().nextBool(); // true or false, with equal chance.Point
Point is a utility class for representing two-dimensional positions.
dart
var leftTop = const Point(0, 0);
var rightBottom = const Point(200, 400);Rectangle
Rectangle is a class for representing two-dimensional axis-aligned rectangles whose properties are immutable.
Create a rectangle spanned by the points.
dart
var leftTop = const Point(20, 50);
var rightBottom = const Point(300, 600);
var rectangle = Rectangle.fromPoints(leftTop, rightBottom);
print(rectangle.left); // 20
print(rectangle.top); // 50
print(rectangle.right); // 300
print(rectangle.bottom); // 600Create a rectangle spanned by (left, top) and (left+width, top+height).
dart
var rectangle = const Rectangle(20, 50, 300, 600);
print(rectangle.left); // 20
print(rectangle.top); // 50
print(rectangle.right); // 320
print(rectangle.bottom); // 650MutableRectangle
MutableRectangle is a class for representing two-dimensional axis-aligned rectangles with mutable properties.
Create a mutable rectangle spanned by (left, top) and (left+width, top+height).
dart
var rectangle = MutableRectangle(20, 50, 300, 600);
print(rectangle); // Rectangle (20, 50) 300 x 600
print(rectangle.left); // 20
print(rectangle.top); // 50
print(rectangle.right); // 320
print(rectangle.bottom); // 650
// Change rectangle width and height.
rectangle.width = 200;
rectangle.height = 100;
print(rectangle); // Rectangle (20, 50) 200 x 100
print(rectangle.left); // 20
print(rectangle.top); // 50
print(rectangle.right); // 220
print(rectangle.bottom); // 150Classes
| Class | Description |
|---|---|
| MutableRectangle<T extends num> | A class for representing two-dimensional axis-aligned rectangles with mutable properties. |
| Point<T extends num> | A utility class for representing two-dimensional positions. |
| Random | A generator of random bool, int, or double values. |
| Rectangle<T extends num> | A class for representing two-dimensional rectangles whose properties are immutable. |
Functions
| Function | Description |
|---|---|
| acos | Converts x to a double and returns its arc cosine in radians. |
| asin | Converts x to a double and returns its arc sine in radians. |
| atan | Converts x to a double and returns its arc tangent in radians. |
| atan2 | A variant of atan. |
| cos | Converts radians to a double and returns the cosine of the value. |
| exp | Converts x to a double and returns the natural exponent, e, to the power x. |
| log | Converts x to a double and returns the natural logarithm of the value. |
| max<T extends num> | Returns the larger of two numbers. |
| min<T extends num> | Returns the lesser of two numbers. |
| pow | Returns x to the power of exponent. |
| sin | Converts radians to a double and returns the sine of the value. |
| sqrt | Converts x to a double and returns the positive square root of the value. |
| tan | Converts radians to a double and returns the tangent of the value. |
Constants
| Constant | Description |
|---|---|
| e | Base of the natural logarithms. |
| ln10 | Natural logarithm of 10. |
| ln2 | Natural logarithm of 2. |
| log10e | Base-10 logarithm of e. |
| log2e | Base-2 logarithm of e. |
| pi | The PI constant. |
| sqrt1_2 | Square root of 1/2. |
| sqrt2 | Square root of 2. |