Loading...
Searching...
No Matches
GeometryUtils Directory Reference

Directories

 dart
 
 java
 
 kotlin
 
 objc
 
 swift
 

Detailed Description

This directory contains comprehensive examples demonstrating the usage of the Navigine SDK's GeometryUtils across all supported platforms.

Overview

The GeometryUtils provides a comprehensive set of geometric calculation functions for working with points, segments, polygons, and lines. It offers functionality for:

Key Components

GeometryUtils

The main utility class providing geometric calculation methods:

Point

Represents a point in metric coordinates:

GlobalPoint

Represents a point in WGS84 coordinates:

Segment

Represents a line segment between two points:

Polygon

Represents a polygon defined by a list of points:

Line

Represents a polyline composed of multiple segments:

Platform-Specific Files

Dart/Flutter

Java

Kotlin

Objective-C

Swift

Key Documentation Tags

GeometryUtils Methods

Point Properties

GlobalPoint Properties

Segment Properties

Polygon Properties

Line Properties

Common Usage Patterns

1. Distance Calculations

// Calculate distance between metric points
Point point1 = Point(10.0, 20.0);
Point point2 = Point(30.0, 40.0);
double distance = GeometryUtils.distanceBetweenPoints(point1, point2);
// Calculate distance between global coordinates
GlobalPoint moscow = GlobalPoint(55.7558, 37.6176);
GlobalPoint london = GlobalPoint(51.5074, -0.1278);
double globalDistance = GeometryUtils.distanceBetweenGlobalPoints(moscow, london);

2. Segment Operations

// Create and analyze segments
Segment segment = Segment(Point(0.0, 0.0), Point(10.0, 10.0));
double length = GeometryUtils.segmentLength(segment);
// Check intersections
Segment segment2 = Segment(Point(0.0, 10.0), Point(10.0, 0.0));
bool intersects = GeometryUtils.segmentIntersectsSegment(segment, segment2);
Point intersection = GeometryUtils.segmentIntersectionSegment(segment, segment2);
// Calculate projections
Point testPoint = Point(5.0, 5.0);
double distanceToPoint = GeometryUtils.segmentPointDistance(segment, testPoint);
double projectionRatio = GeometryUtils.getProjectionRatio(segment, testPoint);
Point ratioPoint = GeometryUtils.getRatioPoint(segment, 0.5);

3. Polygon Analysis

// Create and analyze polygons
List<Point> polygonPoints = [
Point(0.0, 0.0),
Point(10.0, 0.0),
Point(10.0, 10.0),
Point(0.0, 10.0),
];
Polygon polygon = Polygon(polygonPoints);
double area = GeometryUtils.polygonArea(polygon);
Point center = GeometryUtils.polygonCenter(polygon);
// Check point containment
Point testPoint = Point(5.0, 5.0);
bool contains = GeometryUtils.polygonContainsPoint(polygon, testPoint);

4. Line Processing

// Create multi-segment lines
List<Segment> segments = [
Segment(Point(0.0, 0.0), Point(10.0, 10.0)),
Segment(Point(10.0, 10.0), Point(20.0, 5.0)),
Segment(Point(20.0, 5.0), Point(30.0, 15.0)),
];
Line line = Line(segments);
// Calculate total length
double totalLength = 0.0;
for (Segment segment in line.segments) {
totalLength += GeometryUtils.segmentLength(segment);
}

5. Advanced Geometric Operations

// Test various intersection scenarios
Segment parallel1 = Segment(Point(0.0, 0.0), Point(10.0, 0.0));
Segment parallel2 = Segment(Point(0.0, 5.0), Point(10.0, 5.0));
bool parallelIntersects = GeometryUtils.segmentIntersectsSegment(parallel1, parallel2);
// Test different polygon shapes
List<Point> triangle = [
Point(0.0, 0.0),
Point(10.0, 0.0),
Point(5.0, 10.0),
];
Polygon trianglePolygon = Polygon(triangle);
double triangleArea = GeometryUtils.polygonArea(trianglePolygon);

Running Examples

Dart/Flutter

cd examples/GeometryUtils/dart
dart geometry_utils_example.dart

Java

cd examples/GeometryUtils/java
javac GeometryUtilsExample.java
java GeometryUtilsExample

Kotlin

cd examples/GeometryUtils/kotlin
kotlinc GeometryUtilsExample.kt -include-runtime -d GeometryUtilsExample.jar
java -jar GeometryUtilsExample.jar

Objective-C

cd examples/GeometryUtils/objc
clang -framework Foundation GeometryUtilsExample.m -o GeometryUtilsExample
./GeometryUtilsExample

Swift

cd examples/GeometryUtils/swift
swift GeometryUtilsExample.swift

Advanced Features

Distance Calculation Scenarios

The examples demonstrate various distance calculation scenarios:

// Test known distance values
Point origin = Point(0.0, 0.0);
Point pythagorean = Point(3.0, 4.0); // Should be 5.0 distance
double distance = GeometryUtils.distanceBetweenPoints(origin, pythagorean);
// Test global coordinate distances
GlobalPoint moscow = GlobalPoint(55.7558, 37.6176);
GlobalPoint tokyo = GlobalPoint(35.6762, 139.6503);
double globalDistance = GeometryUtils.distanceBetweenGlobalPoints(moscow, tokyo);

Intersection Analysis

Comprehensive intersection testing:

// Parallel segments (should not intersect)
Segment parallel1 = Segment(Point(0.0, 0.0), Point(10.0, 0.0));
Segment parallel2 = Segment(Point(0.0, 5.0), Point(10.0, 5.0));
bool parallelIntersects = GeometryUtils.segmentIntersectsSegment(parallel1, parallel2);
// Perpendicular segments (should intersect)
Segment perpendicular1 = Segment(Point(0.0, 0.0), Point(10.0, 0.0));
Segment perpendicular2 = Segment(Point(5.0, -5.0), Point(5.0, 5.0));
bool perpendicularIntersects = GeometryUtils.segmentIntersectsSegment(perpendicular1, perpendicular2);

Polygon Shape Analysis

Testing different polygon shapes and properties:

// Regular square
List<Point> square = [
Point(0.0, 0.0), Point(10.0, 0.0),
Point(10.0, 10.0), Point(0.0, 10.0)
];
Polygon squarePolygon = Polygon(square);
double squareArea = GeometryUtils.polygonArea(squarePolygon); // Should be 100.0
// Triangle
List<Point> triangle = [
Point(0.0, 0.0), Point(10.0, 0.0), Point(5.0, 10.0)
];
Polygon trianglePolygon = Polygon(triangle);
double triangleArea = GeometryUtils.polygonArea(trianglePolygon); // Should be 50.0

Projection and Ratio Calculations

Advanced geometric transformations:

Segment segment = Segment(Point(0.0, 0.0), Point(10.0, 10.0));
// Test different ratio points
List<double> ratios = [0.0, 0.25, 0.5, 0.75, 1.0];
for (double ratio in ratios) {
Point ratioPoint = GeometryUtils.getRatioPoint(segment, ratio);
print("Ratio $ratio: (${ratioPoint.x}, ${ratioPoint.y})");
}
// Test projection calculations
Point testPoint = Point(5.0, 5.0);
double projectionRatio = GeometryUtils.getProjectionRatio(segment, testPoint);
double distanceToPoint = GeometryUtils.segmentPointDistance(segment, testPoint);

Performance Considerations

Distance Calculations

Polygon Operations

Segment Operations

Memory Usage

Notes