collision_check 0.1.0

  • Readme
  • Changelog
  • Installing
  • 40

collision_check #

pub package GitHub GitHub stars

一款效率超高的轻量级2D物体碰撞检测插件,纯Dart语言编写,适用于任何Dart/Flutter项目。

An ultra-efficient lightweight 2D object collision detection plugin, written in pure Dart, for any Dart/Flutter project.

效率 #

在计算五角星的碰撞时,如下测试代码100w次检测时间为1050ms,足够在一般的场景中检测大量物体的碰撞。

void main() {
  test("碰撞测试", () {
    // 复杂几何图形(下面是一个⭐️️)
    final complex = CcComplex([
      CcOffset(25, 0),
      CcOffset(31, 18),
      CcOffset(50, 18),
      CcOffset(34, 31),
      CcOffset(40, 50),
      CcOffset(25, 38),
      CcOffset(10, 50),
      CcOffset(14, 31),
      CcOffset(0, 18),
      CcOffset(18, 18),
    ]);

    final complex2 = CcComplex([
      CcOffset(25, 0),
      CcOffset(31, 18),
      CcOffset(50, 18),
      CcOffset(34, 31),
      CcOffset(40, 50),
      CcOffset(25, 38),
      CcOffset(10, 50),
      CcOffset(14, 31),
      CcOffset(0, 18),
      CcOffset(18, 18),
    ]);
    for (var i = 0; i < 1000000; i++) {
      complex.position = CcOffset(1, 1.12312);
      complex2.position = CcOffset(4.12343, 0.2384892349);
      final value6 = CollisionUtil.isCollision(complex, complex2);
      assert(value6 == true);
    }
  });
}

安装 #

pubspec.yaml #

最新版本: pub package

dependencies:
  photo_manager: $latest_version

使用方法 #

1、根据需求在创建2d图形时同时创建对应的CcShape对象(尽量使用final类型):

final shapeA = CcComplex(points, position = initPosition);
final shapeB = CcCircle(radius, position = initPosition);

2、在物体移动时根据移动后的位置调用:

shapeA.position = positionA;
shapeB.position = positionB;

3、调用下面的方法返回两个物体是否碰撞:

final result = CollisionUtil.isCollision(shapeA, shapeB);

详细使用方法可在example中查看,若有疑问,欢迎提Issue。

[0.1.0] - TODO: Add release date.

  • TODO: Describe initial release.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  collision_check: ^0.1.0

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:collision_check/collision_check.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
0
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
50
Overall:
Weighted score of the above. [more]
40
Learn more about scoring.

We analyzed this package on Dec 6, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.6.1
  • pana: 0.12.21
  • Flutter: 1.9.1+hotfix.6

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Maintenance issues and suggestions

The description contains too many non-ASCII characters. (-20 points)

The site uses English as its primary language. The value of the description field in your package's pubspec.yaml field should primarily contain characters used in English.

The package description is too short. (-20 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Maintain an example. (-10 points)

Create a short demo in the example/ directory to show how to use this package.

Common filename patterns include main.dart, example.dart, and collision_check.dart. Packages with multiple examples should provide example/README.md.

For more information see the pub package layout conventions.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.7 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test