Skip to content
This repository has been archived by the owner on Dec 2, 2023. It is now read-only.

Commit

Permalink
feat: add documentation to public API
Browse files Browse the repository at this point in the history
  • Loading branch information
adil192 committed Oct 11, 2023
1 parent a0c7b52 commit 152b7ee
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/src/detect_shape.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ import 'package:convex_hull/convex_hull.dart';
import 'package:interactive_shape_recognition/src/shape.dart';
import 'package:interactive_shape_recognition/src/utils.dart';

/// Detects the shape of the given [points].
///
/// Returns a [DetectedShape] object with the detected shape
/// ([DetectedShape.shape]) and some other information.
DetectedShape detectShape(List<Offset> points) {
final hull = convexHull(
points,
Expand Down
30 changes: 30 additions & 0 deletions lib/src/shape.dart
Original file line number Diff line number Diff line change
@@ -1,25 +1,55 @@
import 'dart:ui';

/// The shape of the detected shape.
enum Shape {
/// Detected a circle.
circle,
/// Detected a line.
line,
/// Detected a rectangle.
rectangle,
/// Detected an unknown shape.
unknown,
}

/// The result of the shape detection.
///
/// See [shape] for the detected shape, or check
/// [maybeCircle], [maybeRectangle] and [maybeLine]
/// for cases where the shape is not clear.
class DetectedShape {
/// The detected shape.
final Shape shape;

/// Whether the shape could be a circle.
final bool maybeCircle;
/// Whether the shape could be a rectangle.
final bool maybeRectangle;
/// Whether the shape could be a line.
final bool maybeLine;

/// The enclosing rectangle of the shape.
///
/// This is the smallest rectangle that contains
/// all the points of the shape.
final List<Offset> enclosingRect;
/// The convex hull of the shape.
///
/// This is the smallest convex polygon that contains
/// all the points of the shape.
final List<Offset> convexHull;

/// The ratio between the perimeter of the input vertices
/// and the perimeter of the convex hull.
final double rLenPch;
/// The ratio between the convex hull's
/// square-perimeter and area.
final double rThinness;
/// The ratio between the area of the largest triangle
/// in the convex hull and the area of the convex hull.
final double rAltAch;
/// The ratio between the perimeter of the convex hull
/// and the perimeter of the enclosing rectangle.
final double rPchPer;

DetectedShape({
Expand Down

0 comments on commit 152b7ee

Please sign in to comment.