num_pair 0.0.1+1 copy "num_pair: ^0.0.1+1" to clipboard
num_pair: ^0.0.1+1 copied to clipboard

Revolutionize your Flutter projects with seamless number pair conversions and powerful matrix/vector operations!

NumPair #

Logo

NumPair is an essential Dart package that revolutionizes how you handle numerical values in Flutter! Convert any pair of numbers into a versatile NumPair class and perform an array of powerful matrix and vector operations effortlessly. Designed to supercharge your Flutter projects, NumPair offers seamless conversions and a robust, intuitive API that simplifies your code and boosts your productivity.

🚀 Features #

  • Unified Number Pair Class: Transform any numerical values into a common NumPair class.
  • Matrix/Vector Operations: Execute complex operations like dot products, addition, subtraction, multiplication, division, and scalar operations with ease.
  • Utility Methods: Access utilities for rounding, flipping, absolute values, and more.
  • Element-Wise Operations: Perform element-wise maximum and minimum operations.
  • Seamless Conversions: Effortlessly convert to and from standard Flutter objects like Alignment, Offset, and Size.
  • Simple and Intuitive API: Easily integrate into your Flutter projects and streamline your numerical handling.

🏁 Getting Started #

To start using NumPair, add it as a dependency in your pubspec.yaml file:

dependencies:
  num_pair: ^1.0.0
copied to clipboard

Then run flutter pub get to fetch the package.

🌟 Usage #

Here's a quick example of how to use NumPair in your Flutter project:

import 'package:num_pair/num_pair.dart';

void main() {
  var pair1 = NumPair(3, 4);
  var pair2 = NumPair(5, 6);

  var additionResult = pair1 + pair2;
  var dotProduct = pair1 * pair2;
  var scalarMultiplication = pair1 * 10;
  var roundedPair = pair1.round();
  var absolutePair = pair1.abs();
  var flippedPair = pair1.flip();
  var elementWiseMax = NumPair.elementWiseMax(pair1, pair2);

  print('Addition: $additionResult'); // Output: NumPair(8, 10)
  print('Dot Product: $dotProduct'); // Output: NumPair(15, 24)
  print('Scalar Multiplication: $scalarMultiplication'); // Output: NumPair(30, 40)
  print('Rounded Pair: $roundedPair'); // Output: NumPair(3, 4)
  print('Absolute Pair: $absolutePair'); // Output: NumPair(3, 4)
  print('Flipped Pair: $flippedPair'); // Output: NumPair(4, 3)
  print('Element-Wise Max: $elementWiseMax'); // Output: NumPair(5, 6)
}
copied to clipboard

🌈 Extensions for Seamless Conversions #

NumPair makes converting standard Flutter objects a breeze! Check out these powerful extensions:

import 'package:flutter/material.dart';
import 'package:num_pair/num_pair.dart';

void main() {
  var alignment = Alignment(0.5, 0.5);
  var offset = Offset(100, 200);
  var size = Size(50, 100);
  var tuple = (10, 20);

  var npFromAlignment = alignment.np;
  var npFromOffset = offset.np;
  var npFromSize = size.np;
  var npFromTuple = tuple.np;
  var npFromNum = 5.np;

  print('NumPair from Alignment: $npFromAlignment'); // Output: NumPair(0.5, 0.5)
  print('NumPair from Offset: $npFromOffset'); // Output: NumPair(100, 200)
  print('NumPair from Size: $npFromSize'); // Output: NumPair(50, 100)
  print('NumPair from Tuple: $npFromTuple'); // Output: NumPair(10, 20)
  print('NumPair from Num: $npFromNum'); // Output: NumPair(5, 5)
}
copied to clipboard

📚 Class Details #

NumPair Class #

  • Constructors:

    • NumPair(num x, num y): Creates a NumPair with the specified values.
    • NumPair.fromPair((int, int) values): Creates a NumPair from a tuple of integers.
  • Operators:

    • *: Multiplies NumPair with another NumPair or a scalar value.
    • +: Adds two NumPair objects.
    • -: Subtracts one NumPair from another or negates a NumPair.
    • /: Divides NumPair by another NumPair or a scalar value.
    • []: Accesses elements by index.
  • Methods:

    • flip(): Returns a NumPair with its elements swapped.
    • round(): Returns a NumPair with its elements rounded.
    • abs(): Returns a NumPair with its elements as absolute values.
    • sum(): Returns the sum of the elements.
    • elementWiseMax(): Returns the element-wise maximum of two NumPair objects.
    • elementWiseMin(): Returns the element-wise minimum of two NumPair objects.

🔍 Additional Information #

For more details, visit our documentation. If you encounter any issues or have feature requests, please file them on our issue tracker. We welcome contributions! Check out our contributing guide to get started.

Follow us on Twitter and LinkedIn for the latest updates and news.

Happy coding with NumPair! 🎉

1
likes
110
points
25
downloads

Publisher

verified publishervishnuworld.com

Weekly Downloads

2024.09.06 - 2025.03.21

Revolutionize your Flutter projects with seamless number pair conversions and powerful matrix/vector operations!

Repository (GitHub)

Documentation

API reference

License

unknown (license)

Dependencies

flutter

More

Packages that depend on num_pair