Point class

A utility class for representing two-dimensional positions.

```class Point {
final num x;
final num y;

const Point([num x = 0, num y = 0]): x = x, y = y;

String toString() => '(\$x, \$y)';

bool operator ==(other) {
if (other is !Point) return false;
return x == other.x && y == other.y;
}

Point operator +(Point other) {
return new Point(x + other.x, y + other.y);
}

Point operator -(Point other) {
return new Point(x - other.x, y - other.y);
}

Point operator *(num factor) {
return new Point(x * factor, y * factor);
}

/**
* Returns the distance between two points.
*/
double distanceTo(Point other) {
var dx = x - other.x;
var dy = y - other.y;
return sqrt(dx * dx + dy * dy);
}

/**
* Returns the squared distance between two points.
*
* Squared distances can be used for comparisons when the actual value is not
* required.
*/
num squaredDistanceTo(Point other) {
var dx = x - other.x;
var dy = y - other.y;
return dx * dx + dy * dy;
}

Point ceil() => new Point(x.ceil(), y.ceil());
Point floor() => new Point(x.floor(), y.floor());
Point round() => new Point(x.round(), y.round());

/**
* Truncates x and y to integers and returns the result as a new point.
*/
Point toInt() => new Point(x.toInt(), y.toInt());
}
```

Constructors

const Point([num x = 0, num y = 0]) #

```const Point([num x = 0, num y = 0]): x = x, y = y;
```

Properties

final numx#

```final num x
```

final numy#

```final num y
```

Operators

Pointoperator +(Point other) #

```Point operator +(Point other) {
return new Point(x + other.x, y + other.y);
}
```

Pointoperator -(Point other) #

```Point operator -(Point other) {
return new Point(x - other.x, y - other.y);
}
```

Pointoperator *(num factor) #

```Point operator *(num factor) {
return new Point(x * factor, y * factor);
}
```

booloperator ==(other) #

The equality operator.

The default behavior for all `Object`s is to return true if and only if `this` and other are the same object.

If a subclass overrides the equality operator it should override the `hashCode` method as well to maintain consistency.

docs inherited from Object
```bool operator ==(other) {
if (other is !Point) return false;
return x == other.x && y == other.y;
}
```

Methods

Pointceil() #

```Point ceil() => new Point(x.ceil(), y.ceil());
```

doubledistanceTo(Point other) #

Returns the distance between two points.

```double distanceTo(Point other) {
var dx = x - other.x;
var dy = y - other.y;
return sqrt(dx * dx + dy * dy);
}
```

Pointfloor() #

```Point floor() => new Point(x.floor(), y.floor());
```

Pointround() #

```Point round() => new Point(x.round(), y.round());
```

numsquaredDistanceTo(Point other) #

Returns the squared distance between two points.

Squared distances can be used for comparisons when the actual value is not required.

```num squaredDistanceTo(Point other) {
var dx = x - other.x;
var dy = y - other.y;
return dx * dx + dy * dy;
}
```

PointtoInt() #

Truncates x and y to integers and returns the result as a new point.

```Point toInt() => new Point(x.toInt(), y.toInt());
```

StringtoString() #

Returns a string representation of this object.

docs inherited from Object
```String toString() => '(\$x, \$y)';
```