From 3af1533e03cf34082ad8f8a5d45f73ee9f88100f Mon Sep 17 00:00:00 2001 From: Ian Hickson Date: Fri, 15 Sep 2017 14:52:38 -0700 Subject: [PATCH] Add operators to Radius (flutter/engine#4117) This will make it easier to implement BorderRadius RTL in a manner consistent with EdgeInsets. --- engine/src/flutter/lib/ui/geometry.dart | 52 +++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/engine/src/flutter/lib/ui/geometry.dart b/engine/src/flutter/lib/ui/geometry.dart index 37a544dfca..d90a858a60 100644 --- a/engine/src/flutter/lib/ui/geometry.dart +++ b/engine/src/flutter/lib/ui/geometry.dart @@ -777,6 +777,58 @@ class Radius { /// You can use [Radius.zero] with [RRect] to have right-angle corners. static const Radius zero = const Radius.circular(0.0); + /// Unary negation operator. + /// + /// Returns a Radius with the distances negated. + /// + /// Radiuses with negative values aren't geometrically meaningful, but could + /// occur as part of expressions. For example, negating a radius of one pixel + /// and then adding the result to another radius is equivalent to subtracting + /// a radius of one pixel from the other. + Radius operator -() => new Radius.elliptical(-x, -y); + + /// Binary subtraction operator. + /// + /// Returns a radius whose [x] value is the left-hand-side operand's [x] + /// minus the right-hand-side operand's [x] and whose [y] value is the + /// left-hand-side operand's [y] minus the right-hand-side operand's [y]. + Radius operator -(Radius other) => new Radius.elliptical(x - other.x, y - other.y); + + /// Binary addition operator. + /// + /// Returns a radius whose [x] value is the sum of the [x] values of the + /// two operands, and whose [y] value is the sum of the [y] values of the + /// two operands. + Radius operator +(Radius other) => new Radius.elliptical(x + other.x, y + other.y); + + /// Multiplication operator. + /// + /// Returns a radius whose coordinates are the coordinates of the + /// left-hand-side operand (a radius) multiplied by the scalar + /// right-hand-side operand (a double). + Radius operator *(double operand) => new Radius.elliptical(x * operand, y * operand); + + /// Division operator. + /// + /// Returns a radius whose coordinates are the coordinates of the + /// left-hand-side operand (a radius) divided by the scalar right-hand-side + /// operand (a double). + Radius operator /(double operand) => new Radius.elliptical(x / operand, y / operand); + + /// Integer (truncating) division operator. + /// + /// Returns a radius whose coordinates are the coordinates of the + /// left-hand-side operand (a radius) divided by the scalar right-hand-side + /// operand (a double), rounded towards zero. + Radius operator ~/(double operand) => new Radius.elliptical((x ~/ operand).toDouble(), (y ~/ operand).toDouble()); + + /// Modulo (remainder) operator. + /// + /// Returns a radius whose coordinates are the remainder of dividing the + /// coordinates of the left-hand-side operand (a radius) by the scalar + /// right-hand-side operand (a double). + Radius operator %(double operand) => new Radius.elliptical(x % operand, y % operand); + /// Linearly interpolate between two radii. /// /// If either is null, this function substitutes [Radius.zero] instead.