パッケージ、リポジトリ、アプリカテゴリを検索

パッケージ詳細v1.2.0

bezier

2Dベジェ曲線数学ライブラリ。@TheRealPomaxの作業を大きく参考にしています。ライブ例は . で確認できます。

AndroidiOSWebmacOSWindowsLinux
30日間ダウンロード
8820
いいね数
58
Pub ポイント
150

パッケージをインストール

flutter pub add bezier

パッケージ概要

公開情報に基づく選定ガイドです。参考としてご利用ください。

Dart向けの2次元ベジエ曲線の数学ライブラリで、正確な曲線計算および操作を目的として設計されています。@TheRealPomaxの基礎的な作業に基づき、ベジエ曲線の生成、評価、解析に役立つ堅牢なツールを提供します。Flutterアプリケーションにおけるグラフィックス、アニメーション、パス生成に最適です。すべての主要プラットフォームをサポートし、デモ用のライブ例も含まれています。軽量であり、数学的正確性に焦点を当てています。

用途

  • UIでのパスのアニメーション
  • 描画用のスムーズなカーブを生成する
  • グラフィックスでカスタムシェイプを作成する
  • ポイント間の補間
  • ベクターベースのアニメーションの設計
  • カーブベースの運動の実装

主な機能

  • 正確な2Dベジェ数学
  • 複数のカーブタイプのサポート
  • 任意のパラメータ t における評価
  • カーブの分割機能
  • プラットフォームに依存しない実装
  • ライブ例の統合

適している対象

  • アニメーションを使用しているFlutter開発者
  • スムーズなパスを必要とするUIデザイナー
  • グラフィックスとビジュアライゼーションプロジェクト
  • 数学的に重いアプリケーションロジック
  • 曲線理論のための教育ツール
  • カーブした動きを用いたゲーム開発

注意事項

  • 3Dカーブには対応していません
  • ベジェ数学の理解が必要です
  • 基本的なカーブ操作に限定
  • 組み込みのレンダリングサポートなし
  • グラフィックスレイヤーと併用するのが最適です
  • 高度な使用には外部ドキュメントに依存します

元の README

関連するソースリポジトリの README 原文のスナップショットです。最新の内容はリポジトリをご覧ください。

bezier.dart is a simple open-source Dart library for handling 2D Bézier curve math.

The library was developed, documented, and published by Aaron Barrett and Isaac Barrett. It is based heavily on the work of Pomax, including his excellent Primer on Bézier Curves and his original JavaScript library, Bezier.js.

We're trying to design bezier.dart to be both platform independent and context independent. You can run the library anywhere you can run Dart: in a web browser, in a Flutter application, server side, and beyond.

For live examples of the library's API, see the project page at dartographer.com/bezier.

Features

  • Supports both quadratic and cubic two dimensional Bézier curves
  • Calculate the coordinates of a point at any parameter value t along a curve
  • Derivative and normal values at any t parameter value
  • Accurate length approximations (using the Legendre-Gauss quadrature algorithm)
  • Split a curve into equivalent subcurves between any t parameter values
  • Find the extrema of a curve on both the x and y axes
  • Calculate the bounding box for a curve
  • Given any curve, derive a new curve, offset from the original curve along the normals at a given distance
  • Calculate the positions of a curve's intersections with itself, with another curve, or with a line segment
  • Find points evenly spaced along the arc length of a curve
  • Heavily documented and tested
  • Straightforward, readable code

Getting Started

  1. Add the following to your project's pubspec.yaml and run pub get.
dependencies:
  bezier: any
  1. Import bezier.dart from a file in your project. In most cases you will also want to import the vector_math library.
import "package:vector_math/vector_math.dart";
import "package:bezier/bezier.dart";

Examples

  • Instantiate a Bézier curve.
import "package:vector_math/vector_math.dart";
import "package:bezier/bezier.dart";

void main() {
  // bezier.dart supports both quadratic curves...
  final quadraticCurve = QuadraticBezier([
    Vector2(-40.0, -40.0),
    Vector2(30.0, 10.0),
    Vector2(55.0, 25.0)
  ]);

  // ...and cubic curves!
  final cubicCurve = CubicBezier([
    Vector2(10.0, 10.0),
    Vector2(70.0, 95.0),
    Vector2(25.0, 20.0),
    Vector2(15.0, 80.0)
  ]);
}
  • Compute a point along a curve at t of 0.75.
import "package:vector_math/vector_math.dart";
import "package:bezier/bezier.dart";

void main() {
  final curve = QuadraticBezier([
    Vector2(10.0, 10.0),
    Vector2(70.0, 95.0),
    Vector2(15.0, 80.0)
  ]);

  final computedPoint = curve.pointAt(0.75);
}
  • Split a curve between the t parameter values of 0.2 and 0.6.
import "package:vector_math/vector_math.dart";
import "package:bezier/bezier.dart";

void main() {
  final curve = CubicBezier([
    Vector2(10.0, 10.0),
    Vector2(70.0, 95.0),
    Vector2(25.0, 20.0),
    Vector2(15.0, 80.0)
  ]);

  final subcurve = curve.subcurveBetween(0.2, 0.6);
}
  • Find the intersection t values between a curve and a line segment.
import "package:vector_math/vector_math.dart";
import "package:bezier/bezier.dart";

void main() {
  final curve = QuadraticBezier([
    Vector2(10.0, 500.0),
    Vector2(50.0, 0.0),
    Vector2(90.0, 500.0)
  ]);

  final lineStart = Vector2(0.0, 400.0);
  final lineEnd = Vector2(100.0, 410.0);

  final intersections = curve.intersectionsWithLineSegment(lineStart, lineEnd);
}
  • Derive an offset curve (composed of a series of subcurves) at distance 12.0.
import "package:vector_math/vector_math.dart";
import "package:bezier/bezier.dart";

void main() {
  final curve = CubicBezier([
    Vector2(10.0, 10.0),
    Vector2(15.0, 95.0),
    Vector2(20.0, 95.0),
    Vector2(25.0, 10.0)
  ]);

  final subcurves = curve.offsetCurve(12.0);
}

Style, Formatting, Philosophy

We've made our best effort to conform to the recommendations outlined in the Effective Dart guide. Accordingly, this library is formatted using dartfmt.

As fervent believers in the value of clean code, we are constantly seeking to improve the library and make it easier to work with. Please alert us to any issues you notice, no matter how trivial. We wholeheartedly welcome criticism and friendly debate! :nerd_face:

Running Automated Tests

To run the test cases from the terminal, run the following command from the bezier.dart root directory.

pub run test

Most IDEs now provide interfaces for running tests, which are generally easier to work with. In most cases you can simply right click on a test file or directory in the project tree view and select the menu option to run the selected tests.

Submitting bugs, requesting features

Please file feature requests and bugs using the GitHub issues tab.

カテゴリー

依存関係

依存関係一覧 1 件

ソースリポジトリ

このパッケージを使用しているプロジェクト