Loading...
Searching...
No Matches
GeometryUtilsExample.m
Go to the documentation of this file.
2
7@implementation GeometryUtilsExample
8
9- (instancetype)init {
10 self = [super init];
11 if (self) {
13 }
14 return self;
15}
16
21 NSLog(@"=== GeometryUtils Methods ===");
22
23 [self demonstratePointOperations];
24 [self demonstrateGlobalPointOperations];
25 [self demonstrateBoundingBoxOperations];
26 [self demonstrateSegmentOperations];
27 [self demonstratePolygonOperations];
28 [self demonstrateLineOperations];
29 [self demonstrateAdvancedGeometryOperations];
30}
31
35- (void)demonstratePointOperations {
36 NSLog(@"--- Point Operations ---");
37
38 // [objc_Point_constructor]
39 // Create points with x, y coordinates
40 NCPoint *point1 = [[NCPoint alloc] initWithX:10.0 y:20.0];
41 NCPoint *point2 = [[NCPoint alloc] initWithX:30.0 y:40.0];
42 NCPoint *point3 = [[NCPoint alloc] initWithX:50.0 y:60.0];
43 NSLog(@"Created points: P1(%.1f, %.1f), P2(%.1f, %.1f), P3(%.1f, %.1f)",
44 point1.x, point1.y, point2.x, point2.y, point3.x, point3.y);
45 // [objc_Point_constructor]
46
47 // [objc_Point_getX]
48 // Get X coordinate
49 double x1 = point1.x;
50 NSLog(@"Point1 X coordinate: %.1f", x1);
51 // [objc_Point_getX]
52
53 // [objc_Point_getY]
54 // Get Y coordinate
55 double y1 = point1.y;
56 NSLog(@"Point1 Y coordinate: %.1f", y1);
57 // [objc_Point_getY]
58
59 // [objc_GeometryUtils_distanceBetweenPoints]
60 // Calculate distance between points
61 double distance = [NCGeometryUtils distanceBetweenPointsWithFrom:point1 to:point2];
62 NSLog(@"Distance between P1 and P2: %.2f meters", distance);
63 // [objc_GeometryUtils_distanceBetweenPoints]
64
65 // Create more points for testing
66 NSArray<NCPoint *> *testPoints = @[
67 [[NCPoint alloc] initWithX:0.0 y:0.0],
68 [[NCPoint alloc] initWithX:10.0 y:0.0],
69 [[NCPoint alloc] initWithX:10.0 y:10.0],
70 [[NCPoint alloc] initWithX:0.0 y:10.0],
71 [[NCPoint alloc] initWithX:5.0 y:5.0]
72 ];
73
74 NSLog(@"Test points created for further calculations");
75}
76
80- (void)demonstrateBoundingBoxOperations {
81 NSLog(@"--- BoundingBox Operations ---");
82
83 NCPoint *bottomLeft = [[NCPoint alloc] initWithX:0.0 y:0.0];
84 NCPoint *topRight = [[NCPoint alloc] initWithX:10.0 y:20.0];
85
86 // [objc_BoundingBox_constructor]
87 NCBoundingBox *boundingBox = [[NCBoundingBox alloc] initWithBottomLeft:bottomLeft topRight:topRight];
88 NSLog(@"Created bounding box: bottomLeft(%.1f, %.1f), topRight(%.1f, %.1f)",
89 boundingBox.bottomLeft.x, boundingBox.bottomLeft.y,
90 boundingBox.topRight.x, boundingBox.topRight.y);
91 // [objc_BoundingBox_constructor]
92
93 // [objc_BoundingBox_getBottomLeft]
94 NCPoint *leftCorner = boundingBox.bottomLeft;
95 NSLog(@"Bottom-left corner: (%.1f, %.1f)", leftCorner.x, leftCorner.y);
96 // [objc_BoundingBox_getBottomLeft]
97
98 // [objc_BoundingBox_getTopRight]
99 NCPoint *rightCorner = boundingBox.topRight;
100 NSLog(@"Top-right corner: (%.1f, %.1f)", rightCorner.x, rightCorner.y);
101 // [objc_BoundingBox_getTopRight]
102}
103
107- (void)demonstrateGlobalPointOperations {
108 NSLog(@"--- GlobalPoint Operations ---");
109
110 // [objc_GlobalPoint_constructor]
111 // Create global points with latitude, longitude
112 NCGlobalPoint *globalPoint1 = [[NCGlobalPoint alloc] initWithLatitude:55.7558 longitude:37.6176]; // Moscow
113 NCGlobalPoint *globalPoint2 = [[NCGlobalPoint alloc] initWithLatitude:59.9311 longitude:30.3609]; // St. Petersburg
114 NCGlobalPoint *globalPoint3 = [[NCGlobalPoint alloc] initWithLatitude:55.7522 longitude:37.6156]; // Moscow center
115 NSLog(@"Created global points: GP1(%.4f, %.4f), GP2(%.4f, %.4f)",
116 globalPoint1.latitude, globalPoint1.longitude, globalPoint2.latitude, globalPoint2.longitude);
117 // [objc_GlobalPoint_constructor]
118
119 // [objc_GlobalPoint_getLatitude]
120 // Get latitude
121 double lat1 = globalPoint1.latitude;
122 NSLog(@"GlobalPoint1 latitude: %.4f", lat1);
123 // [objc_GlobalPoint_getLatitude]
124
125 // [objc_GlobalPoint_getLongitude]
126 // Get longitude
127 double lon1 = globalPoint1.longitude;
128 NSLog(@"GlobalPoint1 longitude: %.4f", lon1);
129 // [objc_GlobalPoint_getLongitude]
130
131 // [objc_GeometryUtils_distanceBetweenGlobalPoints]
132 // Calculate distance between global points
133 double globalDistance = [NCGeometryUtils distanceBetweenGlobalPointsWithFrom:globalPoint1 to:globalPoint2];
134 NSLog(@"Distance between Moscow and St. Petersburg: %.2f meters", globalDistance);
135 // [objc_GeometryUtils_distanceBetweenGlobalPoints]
136
137 // Calculate distance between nearby points
138 double nearbyDistance = [NCGeometryUtils distanceBetweenGlobalPointsWithFrom:globalPoint1 to:globalPoint3];
139 NSLog(@"Distance between Moscow points: %.2f meters", nearbyDistance);
140}
141
145- (void)demonstrateSegmentOperations {
146 NSLog(@"--- Segment Operations ---");
147
148 // Create points for segments
149 NCPoint *start1 = [[NCPoint alloc] initWithX:0.0 y:0.0];
150 NCPoint *end1 = [[NCPoint alloc] initWithX:10.0 y:10.0];
151 NCPoint *start2 = [[NCPoint alloc] initWithX:0.0 y:10.0];
152 NCPoint *end2 = [[NCPoint alloc] initWithX:10.0 y:0.0];
153 NCPoint *testPoint = [[NCPoint alloc] initWithX:5.0 y:5.0];
154
155 // [objc_Segment_constructor]
156 // Create segments
157 NCSegment *segment1 = [[NCSegment alloc] initWithStart:start1 end:end1];
158 NCSegment *segment2 = [[NCSegment alloc] initWithStart:start2 end:end2];
159 NSLog(@"Created segments: S1((%.1f, %.1f) -> (%.1f, %.1f)), S2((%.1f, %.1f) -> (%.1f, %.1f))",
160 segment1.start.x, segment1.start.y, segment1.end.x, segment1.end.y,
161 segment2.start.x, segment2.start.y, segment2.end.x, segment2.end.y);
162 // [objc_Segment_constructor]
163
164 // [objc_Segment_getStart]
165 // Get start point
166 NCPoint *segment1Start = segment1.start;
167 NSLog(@"Segment1 start point: (%.1f, %.1f)", segment1Start.x, segment1Start.y);
168 // [objc_Segment_getStart]
169
170 // [objc_Segment_getEnd]
171 // Get end point
172 NCPoint *segment1End = segment1.end;
173 NSLog(@"Segment1 end point: (%.1f, %.1f)", segment1End.x, segment1End.y);
174 // [objc_Segment_getEnd]
175
176 // [objc_GeometryUtils_segmentLength]
177 // Calculate segment length
178 double length1 = [NCGeometryUtils segmentLengthWithSegment:segment1];
179 double length2 = [NCGeometryUtils segmentLengthWithSegment:segment2];
180 NSLog(@"Segment1 length: %.2f meters", length1);
181 NSLog(@"Segment2 length: %.2f meters", length2);
182 // [objc_GeometryUtils_segmentLength]
183
184 // [objc_GeometryUtils_segmentPointDistance]
185 // Calculate distance from segment to point
186 double distanceToPoint = [NCGeometryUtils segmentPointDistanceWithSegment:segment1 point:testPoint];
187 NSLog(@"Distance from segment1 to test point: %.2f meters", distanceToPoint);
188 // [objc_GeometryUtils_segmentPointDistance]
189
190 // [objc_GeometryUtils_segmentIntersectsSegment]
191 // Check if segments intersect
192 BOOL intersects = [NCGeometryUtils segmentIntersectsSegmentWithSegment1:segment1 segment2:segment2];
193 NSLog(@"Segments intersect: %@", intersects ? @"YES" : @"NO");
194 // [objc_GeometryUtils_segmentIntersectsSegment]
195
196 // [objc_GeometryUtils_segmentIntersectionSegment]
197 // Calculate intersection point
198 NCPoint *intersection = [NCGeometryUtils segmentIntersectionSegmentWithSegment1:segment1 segment2:segment2];
199 NSLog(@"Intersection point: (%.2f, %.2f)", intersection.x, intersection.y);
200 // [objc_GeometryUtils_segmentIntersectionSegment]
201
202 // [objc_GeometryUtils_divisionRatioBySegment]
203 // Calculate division ratio
204 double divisionRatio = [NCGeometryUtils divisionRatioBySegmentWithSegment1:segment1 segment2:segment2];
205 NSLog(@"Division ratio: %.2f", divisionRatio);
206 // [objc_GeometryUtils_divisionRatioBySegment]
207
208 // [objc_GeometryUtils_getRatioPoint]
209 // Get point at specific ratio
210 double ratio = 0.5;
211 NCPoint *ratioPoint = [NCGeometryUtils getRatioPointWithSegment:segment1 r:ratio];
212 NSLog(@"Point at ratio %.1f: (%.2f, %.2f)", ratio, ratioPoint.x, ratioPoint.y);
213 // [objc_GeometryUtils_getRatioPoint]
214
215 // [objc_GeometryUtils_getProjectionRatio]
216 // Calculate projection ratio
217 double projectionRatio = [NCGeometryUtils getProjectionRatioWithSegment:segment1 point:testPoint];
218 NSLog(@"Projection ratio: %.2f", projectionRatio);
219 // [objc_GeometryUtils_getProjectionRatio]
220}
221
225- (void)demonstratePolygonOperations {
226 NSLog(@"--- Polygon Operations ---");
227
228 // Create points for polygon
229 NSArray<NCPoint *> *polygonPoints = @[
230 [[NCPoint alloc] initWithX:0.0 y:0.0],
231 [[NCPoint alloc] initWithX:10.0 y:0.0],
232 [[NCPoint alloc] initWithX:10.0 y:10.0],
233 [[NCPoint alloc] initWithX:0.0 y:10.0]
234 ];
235
236 // [objc_Polygon_constructor]
237 // Create polygon
238 NCPolygon *polygon = [[NCPolygon alloc] initWithPoints:polygonPoints];
239 NSLog(@"Created polygon with %lu points", (unsigned long)polygon.points.count);
240 // [objc_Polygon_constructor]
241
242 // [objc_Polygon_getPoints]
243 // Get polygon points
244 NSArray<NCPoint *> *points = polygon.points;
245 NSMutableString *pointsString = [NSMutableString string];
246 for (NCPoint *point in points) {
247 if (pointsString.length > 0) {
248 [pointsString appendString:@", "];
249 }
250 [pointsString appendFormat:@"(%.1f, %.1f)", point.x, point.y];
251 }
252 NSLog(@"Polygon points: %@", pointsString);
253 // [objc_Polygon_getPoints]
254
255 // [objc_GeometryUtils_polygonArea]
256 // Calculate polygon area
257 double area = [NCGeometryUtils polygonAreaWithPolygon:polygon];
258 NSLog(@"Polygon area: %.2f square meters", area);
259 // [objc_GeometryUtils_polygonArea]
260
261 // [objc_GeometryUtils_polygonCenter]
262 // Calculate polygon center
263 NCPoint *center = [NCGeometryUtils polygonCenterWithPolygon:polygon];
264 NSLog(@"Polygon center: (%.2f, %.2f)", center.x, center.y);
265 // [objc_GeometryUtils_polygonCenter]
266
267 // [objc_GeometryUtils_polygonContainsPoint]
268 // Check if polygon contains point
269 NCPoint *insidePoint = [[NCPoint alloc] initWithX:5.0 y:5.0];
270 NCPoint *outsidePoint = [[NCPoint alloc] initWithX:15.0 y:15.0];
271
272 BOOL containsInside = [NCGeometryUtils polygonContainsPointWithPolygon:polygon point:insidePoint];
273 BOOL containsOutside = [NCGeometryUtils polygonContainsPointWithPolygon:polygon point:outsidePoint];
274
275 NSLog(@"Polygon contains inside point: %@", containsInside ? @"YES" : @"NO");
276 NSLog(@"Polygon contains outside point: %@", containsOutside ? @"YES" : @"NO");
277 // [objc_GeometryUtils_polygonContainsPoint]
278
279 // Create complex polygon
280 NSArray<NCPoint *> *complexPolygonPoints = @[
281 [[NCPoint alloc] initWithX:0.0 y:0.0],
282 [[NCPoint alloc] initWithX:20.0 y:0.0],
283 [[NCPoint alloc] initWithX:20.0 y:20.0],
284 [[NCPoint alloc] initWithX:10.0 y:10.0],
285 [[NCPoint alloc] initWithX:0.0 y:20.0]
286 ];
287 NCPolygon *complexPolygon = [[NCPolygon alloc] initWithPoints:complexPolygonPoints];
288
289 double complexArea = [NCGeometryUtils polygonAreaWithPolygon:complexPolygon];
290 NCPoint *complexCenter = [NCGeometryUtils polygonCenterWithPolygon:complexPolygon];
291
292 NSLog(@"Complex polygon area: %.2f square meters", complexArea);
293 NSLog(@"Complex polygon center: (%.2f, %.2f)", complexCenter.x, complexCenter.y);
294}
295
299- (void)demonstrateLineOperations {
300 NSLog(@"--- Line Operations ---");
301
302 // Create segments for line
303 NSArray<NCSegment *> *lineSegments = @[
304 [[NCSegment alloc] initWithStart:[[NCPoint alloc] initWithX:0.0 y:0.0]
305 end:[[NCPoint alloc] initWithX:10.0 y:10.0]],
306 [[NCSegment alloc] initWithStart:[[NCPoint alloc] initWithX:10.0 y:10.0]
307 end:[[NCPoint alloc] initWithX:20.0 y:5.0]],
308 [[NCSegment alloc] initWithStart:[[NCPoint alloc] initWithX:20.0 y:5.0]
309 end:[[NCPoint alloc] initWithX:30.0 y:15.0]]
310 ];
311
312 // [objc_Line_constructor]
313 // Create line
314 NCLine *line = [[NCLine alloc] initWithSegments:lineSegments];
315 NSLog(@"Created line with %lu segments", (unsigned long)line.segments.count);
316 // [objc_Line_constructor]
317
318 // [objc_Line_getSegments]
319 // Get line segments
320 NSArray<NCSegment *> *segments = line.segments;
321 NSLog(@"Line segments: %lu segments", (unsigned long)segments.count);
322 // [objc_Line_getSegments]
323
324 // Calculate total length of line
325 double totalLength = 0.0;
326 for (NCSegment *segment in segments) {
327 totalLength += [NCGeometryUtils segmentLengthWithSegment:segment];
328 }
329 NSLog(@"Total line length: %.2f meters", totalLength);
330
331 // Create complex line
332 NSArray<NCSegment *> *complexLineSegments = @[
333 [[NCSegment alloc] initWithStart:[[NCPoint alloc] initWithX:0.0 y:0.0]
334 end:[[NCPoint alloc] initWithX:5.0 y:5.0]],
335 [[NCSegment alloc] initWithStart:[[NCPoint alloc] initWithX:5.0 y:5.0]
336 end:[[NCPoint alloc] initWithX:10.0 y:0.0]],
337 [[NCSegment alloc] initWithStart:[[NCPoint alloc] initWithX:10.0 y:0.0]
338 end:[[NCPoint alloc] initWithX:15.0 y:10.0]],
339 [[NCSegment alloc] initWithStart:[[NCPoint alloc] initWithX:15.0 y:10.0]
340 end:[[NCPoint alloc] initWithX:20.0 y:5.0]]
341 ];
342 NCLine *complexLine = [[NCLine alloc] initWithSegments:complexLineSegments];
343
344 double complexTotalLength = 0.0;
345 for (NCSegment *segment in complexLine.segments) {
346 complexTotalLength += [NCGeometryUtils segmentLengthWithSegment:segment];
347 }
348 NSLog(@"Complex line total length: %.2f meters", complexTotalLength);
349}
350
354- (void)demonstrateAdvancedGeometryOperations {
355 NSLog(@"--- Advanced Geometry Operations ---");
356
357 // Test distance calculations with various scenarios
358 [self demonstrateDistanceCalculations];
359
360 // Test intersection scenarios
361 [self demonstrateIntersectionScenarios];
362
363 // Test polygon operations with different shapes
364 [self demonstratePolygonScenarios];
365
366 // Test projection and ratio calculations
367 [self demonstrateProjectionCalculations];
368}
369
373- (void)demonstrateDistanceCalculations {
374 NSLog(@"--- Distance Calculations ---");
375
376 // Test point distances
377 NCPoint *origin = [[NCPoint alloc] initWithX:0.0 y:0.0];
378 NSArray<NCPoint *> *testPoints = @[
379 [[NCPoint alloc] initWithX:3.0 y:4.0], // Should be 5.0 distance
380 [[NCPoint alloc] initWithX:6.0 y:8.0], // Should be 10.0 distance
381 [[NCPoint alloc] initWithX:1.0 y:1.0] // Should be sqrt(2) distance
382 ];
383
384 for (NCPoint *testPoint in testPoints) {
385 double distance = [NCGeometryUtils distanceBetweenPointsWithFrom:origin to:testPoint];
386 NSLog(@"Distance from origin to (%.1f, %.1f): %.2f meters", testPoint.x, testPoint.y, distance);
387 }
388
389 // Test global point distances
390 NCGlobalPoint *moscow = [[NCGlobalPoint alloc] initWithLatitude:55.7558 longitude:37.6176];
391 NCGlobalPoint *london = [[NCGlobalPoint alloc] initWithLatitude:51.5074 longitude:-0.1278];
392 NCGlobalPoint *tokyo = [[NCGlobalPoint alloc] initWithLatitude:35.6762 longitude:139.6503];
393
394 double moscowLondon = [NCGeometryUtils distanceBetweenGlobalPointsWithFrom:moscow to:london];
395 double moscowTokyo = [NCGeometryUtils distanceBetweenGlobalPointsWithFrom:moscow to:tokyo];
396
397 NSLog(@"Moscow to London: %.2f km", moscowLondon / 1000);
398 NSLog(@"Moscow to Tokyo: %.2f km", moscowTokyo / 1000);
399}
400
404- (void)demonstrateIntersectionScenarios {
405 NSLog(@"--- Intersection Scenarios ---");
406
407 // Parallel segments (should not intersect)
408 NCSegment *parallel1 = [[NCSegment alloc] initWithStart:[[NCPoint alloc] initWithX:0.0 y:0.0]
409 end:[[NCPoint alloc] initWithX:10.0 y:0.0]];
410 NCSegment *parallel2 = [[NCSegment alloc] initWithStart:[[NCPoint alloc] initWithX:0.0 y:5.0]
411 end:[[NCPoint alloc] initWithX:10.0 y:5.0]];
412
413 BOOL parallelIntersects = [NCGeometryUtils segmentIntersectsSegmentWithSegment1:parallel1 segment2:parallel2];
414 NSLog(@"Parallel segments intersect: %@", parallelIntersects ? @"YES" : @"NO");
415
416 // Perpendicular segments (should intersect)
417 NCSegment *perpendicular1 = [[NCSegment alloc] initWithStart:[[NCPoint alloc] initWithX:0.0 y:0.0]
418 end:[[NCPoint alloc] initWithX:10.0 y:0.0]];
419 NCSegment *perpendicular2 = [[NCSegment alloc] initWithStart:[[NCPoint alloc] initWithX:5.0 y:-5.0]
420 end:[[NCPoint alloc] initWithX:5.0 y:5.0]];
421
422 BOOL perpendicularIntersects = [NCGeometryUtils segmentIntersectsSegmentWithSegment1:perpendicular1 segment2:perpendicular2];
423 NSLog(@"Perpendicular segments intersect: %@", perpendicularIntersects ? @"YES" : @"NO");
424
425 if (perpendicularIntersects) {
426 NCPoint *intersection = [NCGeometryUtils segmentIntersectionSegmentWithSegment1:perpendicular1 segment2:perpendicular2];
427 NSLog(@"Intersection point: (%.2f, %.2f)", intersection.x, intersection.y);
428 }
429
430 // Overlapping segments
431 NCSegment *overlap1 = [[NCSegment alloc] initWithStart:[[NCPoint alloc] initWithX:0.0 y:0.0]
432 end:[[NCPoint alloc] initWithX:10.0 y:0.0]];
433 NCSegment *overlap2 = [[NCSegment alloc] initWithStart:[[NCPoint alloc] initWithX:5.0 y:0.0]
434 end:[[NCPoint alloc] initWithX:15.0 y:0.0]];
435
436 BOOL overlapIntersects = [NCGeometryUtils segmentIntersectsSegmentWithSegment1:overlap1 segment2:overlap2];
437 NSLog(@"Overlapping segments intersect: %@", overlapIntersects ? @"YES" : @"NO");
438}
439
443- (void)demonstratePolygonScenarios {
444 NSLog(@"--- Polygon Scenarios ---");
445
446 // Regular square
447 NSArray<NCPoint *> *square = @[
448 [[NCPoint alloc] initWithX:0.0 y:0.0],
449 [[NCPoint alloc] initWithX:10.0 y:0.0],
450 [[NCPoint alloc] initWithX:10.0 y:10.0],
451 [[NCPoint alloc] initWithX:0.0 y:10.0]
452 ];
453 NCPolygon *squarePolygon = [[NCPolygon alloc] initWithPoints:square];
454
455 double squareArea = [NCGeometryUtils polygonAreaWithPolygon:squarePolygon];
456 NCPoint *squareCenter = [NCGeometryUtils polygonCenterWithPolygon:squarePolygon];
457
458 NSLog(@"Square area: %.2f square meters", squareArea);
459 NSLog(@"Square center: (%.2f, %.2f)", squareCenter.x, squareCenter.y);
460
461 // Triangle
462 NSArray<NCPoint *> *triangle = @[
463 [[NCPoint alloc] initWithX:0.0 y:0.0],
464 [[NCPoint alloc] initWithX:10.0 y:0.0],
465 [[NCPoint alloc] initWithX:5.0 y:10.0]
466 ];
467 NCPolygon *trianglePolygon = [[NCPolygon alloc] initWithPoints:triangle];
468
469 double triangleArea = [NCGeometryUtils polygonAreaWithPolygon:trianglePolygon];
470 NCPoint *triangleCenter = [NCGeometryUtils polygonCenterWithPolygon:trianglePolygon];
471
472 NSLog(@"Triangle area: %.2f square meters", triangleArea);
473 NSLog(@"Triangle center: (%.2f, %.2f)", triangleCenter.x, triangleCenter.y);
474
475 // Test point containment
476 NCPoint *insideSquare = [[NCPoint alloc] initWithX:5.0 y:5.0];
477 NCPoint *outsideSquare = [[NCPoint alloc] initWithX:15.0 y:15.0];
478
479 BOOL containsInside = [NCGeometryUtils polygonContainsPointWithPolygon:squarePolygon point:insideSquare];
480 BOOL containsOutside = [NCGeometryUtils polygonContainsPointWithPolygon:squarePolygon point:outsideSquare];
481
482 NSLog(@"Square contains (5,5): %@", containsInside ? @"YES" : @"NO");
483 NSLog(@"Square contains (15,15): %@", containsOutside ? @"YES" : @"NO");
484}
485
489- (void)demonstrateProjectionCalculations {
490 NSLog(@"--- Projection Calculations ---");
491
492 NCSegment *segment = [[NCSegment alloc] initWithStart:[[NCPoint alloc] initWithX:0.0 y:0.0]
493 end:[[NCPoint alloc] initWithX:10.0 y:10.0]];
494
495 // Test different ratio points
496 NSArray<NSNumber *> *ratios = @[@0.0, @0.25, @0.5, @0.75, @1.0];
497
498 for (NSNumber *ratioNumber in ratios) {
499 double ratio = ratioNumber.doubleValue;
500 NCPoint *ratioPoint = [NCGeometryUtils getRatioPointWithSegment:segment r:ratio];
501 NSLog(@"Ratio %.2f: (%.2f, %.2f)", ratio, ratioPoint.x, ratioPoint.y);
502 }
503
504 // Test projection ratio calculation
505 NCPoint *testPoint = [[NCPoint alloc] initWithX:5.0 y:5.0];
506 double projectionRatio = [NCGeometryUtils getProjectionRatioWithSegment:segment point:testPoint];
507 NSLog(@"Projection ratio for point (5,5): %.2f", projectionRatio);
508
509 // Test distance from segment to point
510 NCPoint *offSegmentPoint = [[NCPoint alloc] initWithX:5.0 y:0.0];
511 double distanceToOffPoint = [NCGeometryUtils segmentPointDistanceWithSegment:segment point:offSegmentPoint];
512 NSLog(@"Distance from segment to point (5,0): %.2f meters", distanceToOffPoint);
513}
514
518- (void)runExample {
519 NSLog(@"=== GeometryUtils Example ===");
520
521 // Wait a bit for processing
522 dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
523 NSLog(@"=== Example completed ===");
524 });
525}
526
527@end
528
532int main(int argc, const char * argv[]) {
533 @autoreleasepool {
534 GeometryUtilsExample *example = [[GeometryUtilsExample alloc] init];
535 [example runExample];
536
537 // Keep the app running for a while to see the output
538 [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:10.0]];
539 }
540 return 0;
541}