1 /* 2 * Copyright (C) 2024 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package androidx.ink.geometry 18 19 import androidx.ink.nativeloader.NativeLoader 20 import androidx.ink.nativeloader.UsedByNative 21 22 /** 23 * Contains functions for intersection of ink geometry classes. For Kotlin callers, these are 24 * available as extension functions on the geometry classes themselves. 25 */ 26 public object Intersection { 27 28 init { 29 NativeLoader.load() 30 } 31 32 /** 33 * Returns true if the point (a [Vec]), intersects [other]; this only occurs when the two points 34 * are equal. 35 */ intersectsnull36 @JvmStatic public fun Vec.intersects(other: Vec): Boolean = (this == other) 37 38 /** 39 * Returns true when the point (a [Vec]) intersects with a [Segment]. All points on the segment, 40 * including endpoints, intersect with the segment. 41 */ 42 @JvmStatic 43 public fun Vec.intersects(segment: Segment): Boolean { 44 return nativeVecSegmentIntersects( 45 vecX = this.x, 46 vecY = this.y, 47 segmentStartX = segment.start.x, 48 segmentStartY = segment.start.y, 49 segmentEndX = segment.end.x, 50 segmentEndY = segment.end.y, 51 ) 52 } 53 54 /** 55 * Returns true when the point (a [Vec]) intersects with a [Triangle]. All points on the 56 * boundary of the triangle (including its vertices) and in the interior of the triangle 57 * intersect with it. 58 */ 59 @JvmStatic intersectsnull60 public fun Vec.intersects(triangle: Triangle): Boolean { 61 return nativeVecTriangleIntersects( 62 vecX = this.x, 63 vecY = this.y, 64 triangleP0X = triangle.p0.x, 65 triangleP0Y = triangle.p0.y, 66 triangleP1X = triangle.p1.x, 67 triangleP1Y = triangle.p1.y, 68 triangleP2X = triangle.p2.x, 69 triangleP2Y = triangle.p2.y, 70 ) 71 } 72 73 /** 74 * Returns true when the point (a [Vec]) intersects with a [Parallelogram]. All points on the 75 * boundary of the parallelogram (including its vertices) and in the interior of the 76 * parallelogram intersect with it. 77 */ 78 @JvmStatic intersectsnull79 public fun Vec.intersects(parallelogram: Parallelogram): Boolean { 80 return nativeVecParallelogramIntersects( 81 vecX = this.x, 82 vecY = this.y, 83 parallelogramCenterX = parallelogram.center.x, 84 parallelogramCenterY = parallelogram.center.y, 85 parallelogramWidth = parallelogram.width, 86 parallelogramHeight = parallelogram.height, 87 parallelogramAngleInRadian = parallelogram.rotation, 88 parallelogramShearFactor = parallelogram.shearFactor, 89 ) 90 } 91 92 /** 93 * Returns true when the point (a [Vec]) intersects with a [Box]. All points on the boundary of 94 * the box (including its vertices) and in the interior of the box intersect with it. 95 */ 96 @JvmStatic intersectsnull97 public fun Vec.intersects(box: Box): Boolean { 98 return nativeVecBoxIntersects( 99 vecX = this.x, 100 vecY = this.y, 101 boxXMin = box.xMin, 102 boxYMin = box.yMin, 103 boxXMax = box.xMax, 104 boxYMax = box.yMax, 105 ) 106 } 107 108 /** 109 * Returns true when the point (a [Vec]) intersects with [mesh]. [meshToPoint] transforms the 110 * coordinate space of [mesh] to the coordinate space that the intersection should be checked in 111 * (that of the point). All points along the boundary of the [mesh] and the [mesh]s interior are 112 * considered for intersection. 113 * 114 * Performance note: it is expensive to apply a transform to a mesh. To avoid unnecessary 115 * calculations, the inverse of [meshToPoint] is used to perform the mathematically equivalent 116 * intersection of the point in [mesh]’s object coordinates. 117 */ 118 @JvmStatic intersectsnull119 public fun Vec.intersects(mesh: PartitionedMesh, meshToPoint: AffineTransform): Boolean { 120 return nativeMeshVecIntersects( 121 nativeMeshAddress = mesh.nativePointer, 122 vecX = this.x, 123 vecY = this.y, 124 meshToVecA = meshToPoint.m00, 125 meshToVecB = meshToPoint.m10, 126 meshToVecC = meshToPoint.m20, 127 meshToVecD = meshToPoint.m01, 128 meshToVecE = meshToPoint.m11, 129 meshToVecF = meshToPoint.m21, 130 ) 131 } 132 133 /** 134 * Returns true when a [Segment] intersects with another [Segment] --- when this segment has at 135 * least one point (including the [start] and [end] points) in common with another [Segment]. 136 */ 137 @JvmStatic intersectsnull138 public fun Segment.intersects(other: Segment): Boolean { 139 // Return true without calling the native code when this [Segment] and [other] are equal --- 140 // i.e. have same endpoints. 141 if (this == other) return true 142 return nativeSegmentSegmentIntersects( 143 segment1StartX = this.start.x, 144 segment1StartY = this.start.y, 145 segment1EndX = this.end.x, 146 segment1EndY = this.end.y, 147 segment2StartX = other.start.x, 148 segment2StartY = other.start.y, 149 segment2EndX = other.end.x, 150 segment2EndY = other.end.y, 151 ) 152 } 153 154 /** 155 * Returns true when a [Segment] intersects with a [Triangle] --- when this segment has at least 156 * one point in common with the [Triangle]'s interior, edges, or vertices. 157 */ 158 @JvmStatic intersectsnull159 public fun Segment.intersects(triangle: Triangle): Boolean { 160 return nativeSegmentTriangleIntersects( 161 segmentStartX = this.start.x, 162 segmentStartY = this.start.y, 163 segmentEndX = this.end.x, 164 segmentEndY = this.end.y, 165 triangleP0X = triangle.p0.x, 166 triangleP0Y = triangle.p0.y, 167 triangleP1X = triangle.p1.x, 168 triangleP1Y = triangle.p1.y, 169 triangleP2X = triangle.p2.x, 170 triangleP2Y = triangle.p2.y, 171 ) 172 } 173 174 /** 175 * Returns true when a [Segment] intersects with a [Box] --- when this segment has at least one 176 * point in common with the [Box]'s interior, edges, or vertices 177 */ 178 @JvmStatic intersectsnull179 public fun Segment.intersects(box: Box): Boolean { 180 return nativeSegmentBoxIntersects( 181 segmentStartX = this.start.x, 182 segmentStartY = this.start.y, 183 segmentEndX = this.end.x, 184 segmentEndY = this.end.y, 185 boxXMin = box.xMin, 186 boxYMin = box.yMin, 187 boxXMax = box.xMax, 188 boxYMax = box.yMax, 189 ) 190 } 191 192 /** 193 * Returns true when a [Segment] intersects with a [Parallelogram] --- when this segment has at 194 * least one point in common with the [Parallelogram]'s interior, edges, or vertices. 195 */ 196 @JvmStatic intersectsnull197 public fun Segment.intersects(parallelogram: Parallelogram): Boolean { 198 return nativeSegmentParallelogramIntersects( 199 segmentStartX = this.start.x, 200 segmentStartY = this.start.y, 201 segmentEndX = this.end.x, 202 segmentEndY = this.end.y, 203 parallelogramCenterX = parallelogram.center.x, 204 parallelogramCenterY = parallelogram.center.y, 205 parallelogramWidth = parallelogram.width, 206 parallelogramHeight = parallelogram.height, 207 parallelogramAngleInRadian = parallelogram.rotation, 208 parallelogramShearFactor = parallelogram.shearFactor, 209 ) 210 } 211 212 /** 213 * Returns true when a [Segment] intersects with a [PartitionedMesh]. 214 * 215 * Note that, because it is expensive to apply a transform to a mesh, this method takes a 216 * [meshToSegment] transform as an argument. This transform maps from the [PartitionedMesh]'s 217 * coordinate space to the coordinate space that the intersection should be checked in. 218 */ 219 @JvmStatic intersectsnull220 public fun Segment.intersects(mesh: PartitionedMesh, meshToSegment: AffineTransform): Boolean { 221 return nativeMeshSegmentIntersects( 222 nativeMeshAddress = mesh.nativePointer, 223 segmentStartX = this.start.x, 224 segmentStartY = this.start.y, 225 segmentEndX = this.end.x, 226 segmentEndY = this.end.y, 227 meshToSegmentA = meshToSegment.m00, 228 meshToSegmentB = meshToSegment.m10, 229 meshToSegmentC = meshToSegment.m20, 230 meshToSegmentD = meshToSegment.m01, 231 meshToSegmentE = meshToSegment.m11, 232 meshToSegmentF = meshToSegment.m21, 233 ) 234 } 235 236 /** 237 * Returns true when a [Triangle] intersects with [other] --- When this triangle has at least 238 * one point in common with [other]'s interior, edges, or vertices. 239 */ 240 @JvmStatic intersectsnull241 public fun Triangle.intersects(other: Triangle): Boolean { 242 // Return true without calling the native code when this [Triangle] and [other] are equal 243 // --- 244 // i.e. have same corners. 245 if (this == other) return true 246 return nativeTriangleTriangleIntersects( 247 triangle1P0X = this.p0.x, 248 triangle1P0Y = this.p0.y, 249 triangle1P1X = this.p1.x, 250 triangle1P1Y = this.p1.y, 251 triangle1P2X = this.p2.x, 252 triangle1P2Y = this.p2.y, 253 triangle2P0X = other.p0.x, 254 triangle2P0Y = other.p0.y, 255 triangle2P1X = other.p1.x, 256 triangle2P1Y = other.p1.y, 257 triangle2P2X = other.p2.x, 258 triangle2P2Y = other.p2.y, 259 ) 260 } 261 262 /** 263 * Returns true when a [Triangle] intersects with a [Box] --- When this triangle has at least 264 * one point in common with the [Box]'s interior, edges, or vertices. 265 */ 266 @JvmStatic intersectsnull267 public fun Triangle.intersects(box: Box): Boolean { 268 return nativeTriangleBoxIntersects( 269 triangleP0X = this.p0.x, 270 triangleP0Y = this.p0.y, 271 triangleP1X = this.p1.x, 272 triangleP1Y = this.p1.y, 273 triangleP2X = this.p2.x, 274 triangleP2Y = this.p2.y, 275 boxXMin = box.xMin, 276 boxYMin = box.yMin, 277 boxXMax = box.xMax, 278 boxYMax = box.yMax, 279 ) 280 } 281 282 /** 283 * Returns true when a [Triangle] intersects with a [Parallelogram] --- When this triangle has 284 * at least one point in common with the [Parallelogram]'s interior, edges, or vertices. 285 */ 286 @JvmStatic intersectsnull287 public fun Triangle.intersects(parallelogram: Parallelogram): Boolean { 288 return nativeTriangleParallelogramIntersects( 289 triangleP0X = this.p0.x, 290 triangleP0Y = this.p0.y, 291 triangleP1X = this.p1.x, 292 triangleP1Y = this.p1.y, 293 triangleP2X = this.p2.x, 294 triangleP2Y = this.p2.y, 295 parallelogramCenterX = parallelogram.center.x, 296 parallelogramCenterY = parallelogram.center.y, 297 parallelogramWidth = parallelogram.width, 298 parallelogramHeight = parallelogram.height, 299 parallelogramAngleInRadian = parallelogram.rotation, 300 parallelogramShearFactor = parallelogram.shearFactor, 301 ) 302 } 303 304 /** 305 * Returns true when a [Triangle] intersects with a [PartitionedMesh]. 306 * 307 * Note that, because it is expensive to apply a transform to a mesh, this method takes a 308 * [meshToTriangle] transform as an argument. This transform maps from the [PartitionedMesh]'s 309 * coordinate space to the coordinate space that the intersection should be checked in. 310 */ 311 @JvmStatic intersectsnull312 public fun Triangle.intersects( 313 mesh: PartitionedMesh, 314 meshToTriangle: AffineTransform 315 ): Boolean { 316 return nativeMeshTriangleIntersects( 317 nativeMeshAddress = mesh.nativePointer, 318 triangleP0X = this.p0.x, 319 triangleP0Y = this.p0.y, 320 triangleP1X = this.p1.x, 321 triangleP1Y = this.p1.y, 322 triangleP2X = this.p2.x, 323 triangleP2Y = this.p2.y, 324 meshToTriangleA = meshToTriangle.m00, 325 meshToTriangleB = meshToTriangle.m10, 326 meshToTriangleC = meshToTriangle.m20, 327 meshToTriangleD = meshToTriangle.m01, 328 meshToTriangleE = meshToTriangle.m11, 329 meshToTriangleF = meshToTriangle.m21, 330 ) 331 } 332 333 /** 334 * Returns true when a [Box] intersects with [other] --- When it has at least one point in 335 * common with [other]'s interior, edges, or vertices. 336 */ 337 @JvmStatic intersectsnull338 public fun Box.intersects(other: Box): Boolean { 339 // Return true without calling the native code when this [Box] and [other] are equal --- 340 // i.e. have same [xMin], [yMin], [xMax] and [yMax]. 341 if (this == other) return true 342 return nativeBoxBoxIntersects( 343 box1XMin = this.xMin, 344 box1YMin = this.yMin, 345 box1XMax = this.xMax, 346 box1YMax = this.yMax, 347 box2XMin = other.xMin, 348 box2YMin = other.yMin, 349 box2XMax = other.xMax, 350 box2YMax = other.yMax, 351 ) 352 } 353 354 /** 355 * Returns true when a [Box] intersects with a [Parallelogram] --- When it has at least one 356 * point in common with the [Parallelogram]'s interior, edges, or vertices. 357 */ 358 @JvmStatic intersectsnull359 public fun Box.intersects(parallelogram: Parallelogram): Boolean { 360 return nativeBoxParallelogramIntersects( 361 boxXMin = this.xMin, 362 boxYMin = this.yMin, 363 boxXMax = this.xMax, 364 boxYMax = this.yMax, 365 parallelogramCenterX = parallelogram.center.x, 366 parallelogramCenterY = parallelogram.center.y, 367 parallelogramWidth = parallelogram.width, 368 parallelogramHeight = parallelogram.height, 369 parallelogramAngleInRadian = parallelogram.rotation, 370 parallelogramShearFactor = parallelogram.shearFactor, 371 ) 372 } 373 374 /** 375 * Returns true when a [Box] intersects with a [PartitionedMesh]. 376 * 377 * Note that, because it is expensive to apply a transform to a mesh, this method takes a 378 * [meshToBox] transform as an argument. This transform maps from the [PartitionedMesh]'s 379 * coordinate space to the coordinate space that the intersection should be checked in. 380 */ 381 @JvmStatic intersectsnull382 public fun Box.intersects(mesh: PartitionedMesh, meshToBox: AffineTransform): Boolean { 383 return nativeMeshBoxIntersects( 384 nativeMeshAddress = mesh.nativePointer, 385 boxXMin = this.xMin, 386 boxYMin = this.yMin, 387 boxXMax = this.xMax, 388 boxYMax = this.yMax, 389 meshToBoxA = meshToBox.m00, 390 meshToBoxB = meshToBox.m10, 391 meshToBoxC = meshToBox.m20, 392 meshToBoxD = meshToBox.m01, 393 meshToBoxE = meshToBox.m11, 394 meshToBoxF = meshToBox.m21, 395 ) 396 } 397 398 /** 399 * Returns true when a [Parallelogram] intersects with [other] --- When it has at least one 400 * point in common with [other]'s interior, edges, or vertices. 401 */ 402 @JvmStatic intersectsnull403 public fun Parallelogram.intersects(other: Parallelogram): Boolean { 404 // Return true without calling the native code when this [Parallelogram] and [other] are 405 // equal 406 // --- i.e. 407 // when they have same parameters like [center], [width], [height], [rotation] and 408 // [shearFactor]. 409 if (this == other) return true 410 return nativeParallelogramParallelogramIntersects( 411 parallelogram1CenterX = this.center.x, 412 parallelogram1CenterY = this.center.y, 413 parallelogram1Width = this.width, 414 parallelogram1Height = this.height, 415 parallelogram1AngleInRadian = this.rotation, 416 parallelogram1ShearFactor = this.shearFactor, 417 parallelogram2CenterX = other.center.x, 418 parallelogram2CenterY = other.center.y, 419 parallelogram2Width = other.width, 420 parallelogram2Height = other.height, 421 parallelogram2AngleInRadian = other.rotation, 422 parallelogram2ShearFactor = other.shearFactor, 423 ) 424 } 425 426 /** 427 * RReturns true when a [Parallelogram] intersects with a [PartitionedMesh]. 428 * 429 * Note that, because it is expensive to apply a transform to a mesh, this method takes a 430 * [meshToParallelogram] transform as an argument. This transform maps from the 431 * [PartitionedMesh]'s coordinate space to the coordinate space that the intersection should be 432 * checked in. 433 */ 434 @JvmStatic intersectsnull435 public fun Parallelogram.intersects( 436 mesh: PartitionedMesh, 437 meshToParallelogram: AffineTransform, 438 ): Boolean { 439 return nativeMeshParallelogramIntersects( 440 nativeMeshAddress = mesh.nativePointer, 441 parallelogramCenterX = this.center.x, 442 parallelogramCenterY = this.center.y, 443 parallelogramWidth = this.width, 444 parallelogramHeight = this.height, 445 parallelogramAngleInRadian = this.rotation, 446 parallelogramShearFactor = this.shearFactor, 447 meshToParallelogramA = meshToParallelogram.m00, 448 meshToParallelogramB = meshToParallelogram.m10, 449 meshToParallelogramC = meshToParallelogram.m20, 450 meshToParallelogramD = meshToParallelogram.m01, 451 meshToParallelogramE = meshToParallelogram.m11, 452 meshToParallelogramF = meshToParallelogram.m21, 453 ) 454 } 455 456 /** 457 * Returns true when a [PartitionedMesh] intersects with a [PartitionedMesh]. 458 * 459 * Note that, because it is expensive to apply a transform to a mesh, this method takes two 460 * [AffineTransform] objects: [thisToCommonTransForm] and [otherToCommonTransform]. These 461 * transforms map from the respective [PartitionedMesh]s' coordinate spaces to the common 462 * coordinate space that the intersection should be checked in. 463 */ 464 @JvmStatic intersectsnull465 public fun PartitionedMesh.intersects( 466 other: PartitionedMesh, 467 thisToCommonTransForm: AffineTransform, 468 otherToCommonTransform: AffineTransform, 469 ): Boolean { 470 return nativeMeshPartitionedMeshIntersects( 471 thisPartitionedMeshAddress = this.nativePointer, 472 otherPartitionedMeshAddress = other.nativePointer, 473 thisToCommonTransformA = thisToCommonTransForm.m00, 474 thisToCommonTransformB = thisToCommonTransForm.m10, 475 thisToCommonTransformC = thisToCommonTransForm.m20, 476 thisToCommonTransformD = thisToCommonTransForm.m01, 477 thisToCommonTransformE = thisToCommonTransForm.m11, 478 thisToCommonTransformF = thisToCommonTransForm.m21, 479 otherToCommonTransformA = otherToCommonTransform.m00, 480 otherToCommonTransformB = otherToCommonTransform.m10, 481 otherToCommonTransformC = otherToCommonTransform.m20, 482 otherToCommonTransformD = otherToCommonTransform.m01, 483 otherToCommonTransformE = otherToCommonTransform.m11, 484 otherToCommonTransformF = otherToCommonTransform.m21, 485 ) 486 } 487 488 /** 489 * Returns true when the [Segment] intersects with a point (a [Vec]). All points on the segment, 490 * including endpoints, intersect with the segment. 491 */ intersectsnull492 @JvmStatic public fun Segment.intersects(point: Vec): Boolean = point.intersects(this) 493 494 /** 495 * Returns true when the [Triangle] intersects with a point (a [Vec]). All points on the 496 * boundary of the triangle (including its vertices) and in the interior of the triangle 497 * intersect with it. 498 */ 499 @JvmStatic public fun Triangle.intersects(point: Vec): Boolean = point.intersects(this) 500 501 /** 502 * Returns true when a [Triangle] intersects with a [Segment] --- when the [segment] has at 503 * least one point in common with the [Triangle]'s interior, edges, or vertices. 504 */ 505 @JvmStatic public fun Triangle.intersects(segment: Segment): Boolean = segment.intersects(this) 506 507 /** 508 * Returns true when the [Parallelogram] intersects with a point (a [Vec]). All points on the 509 * boundary of the parallelogram (including its vertices) and in the interior of the 510 * parallelogram intersect with it. 511 */ 512 @JvmStatic public fun Parallelogram.intersects(point: Vec): Boolean = point.intersects(this) 513 514 /** 515 * Returns true when a [Parallelogram] intersects with a [Segment] --- when the [segment] has at 516 * least one point in common with the [Parallelogram]'s interior, edges, or vertices. 517 */ 518 @JvmStatic 519 public fun Parallelogram.intersects(segment: Segment): Boolean = segment.intersects(this) 520 521 /** 522 * Returns true when a [Parallelogram] intersects with a [Triangle] --- When the [triangle] has 523 * at least one point in common with the [Parallelogram]'s interior, edges, or vertices. 524 */ 525 @JvmStatic 526 public fun Parallelogram.intersects(triangle: Triangle): Boolean = triangle.intersects(this) 527 528 /** 529 * Returns true when a [Parallelogram] intersects with a [Box] --- When the [box] has at least 530 * one point in common with the [Parallelogram]'s interior, edges, or vertices. 531 */ 532 @JvmStatic public fun Parallelogram.intersects(box: Box): Boolean = box.intersects(this) 533 534 /** 535 * Returns true when the [Box] intersects with a point (a [Vec]). All points on the boundary of 536 * the box (including its vertices) and in the interior of the box intersect with it. 537 */ 538 @JvmStatic public fun Box.intersects(point: Vec): Boolean = point.intersects(this) 539 540 /** 541 * Returns true when a [Box] intersects with a [Segment] --- when the [segment] has at least one 542 * point in common with the [Box]'s interior, edges, or vertices 543 */ 544 @JvmStatic public fun Box.intersects(segment: Segment): Boolean = segment.intersects(this) 545 546 /** 547 * Returns true when a [Box] intersects with a [Triangle] --- When the [triangle] has at least 548 * one point in common with the [Box]'s interior, edges, or vertices. 549 */ 550 @JvmStatic public fun Box.intersects(triangle: Triangle): Boolean = triangle.intersects(this) 551 552 /** 553 * Returns true when the [PartitionedMesh] intersects with [point]. [meshToPoint] transforms the 554 * coordinate space of [mesh] to the coordinate space that the intersection should be checked in 555 * (that of the [point]). All points along the boundary of the [mesh] and the [mesh]s interior 556 * are considered for intersection. 557 * 558 * Performance note: it is expensive to apply a transform to a mesh. To avoid unnecessary 559 * calculations, the inverse of [meshToPoint] is used to perform the mathematically equivalent 560 * intersection of the point in [mesh]’s object coordinates. 561 */ 562 @JvmStatic 563 public fun PartitionedMesh.intersects(point: Vec, meshToPoint: AffineTransform): Boolean = 564 point.intersects(this, meshToPoint) 565 566 /** 567 * Returns true when a [PartitionedMesh] intersects with a [Segment]. 568 * 569 * Note that, because it is expensive to apply a transform to a mesh, this method takes a 570 * [meshToSegment] transform as an argument. This transform maps from the [PartitionedMesh]'s 571 * coordinate space to the coordinate space that the intersection should be checked in. 572 */ 573 @JvmStatic 574 public fun PartitionedMesh.intersects( 575 segment: Segment, 576 meshToSegment: AffineTransform 577 ): Boolean = segment.intersects(this, meshToSegment) 578 579 /** 580 * Returns true when a [PartitionedMesh] intersects with a [Triangle]. 581 * 582 * Note that, because it is expensive to apply a transform to a mesh, this method takes a 583 * [meshToTriangle] transform as an argument. This transform maps from the [PartitionedMesh]'s 584 * coordinate space to the coordinate space that the intersection should be checked in. 585 */ 586 @JvmStatic 587 public fun PartitionedMesh.intersects( 588 triangle: Triangle, 589 meshToTriangle: AffineTransform, 590 ): Boolean = triangle.intersects(this, meshToTriangle) 591 592 /** 593 * Returns true when a [PartitionedMesh] intersects with a [Box]. 594 * 595 * Note that, because it is expensive to apply a transform to a mesh, this method takes a 596 * [meshToBox] transform as an argument. This transform maps from the [PartitionedMesh]'s 597 * coordinate space to the coordinate space that the intersection should be checked in. 598 */ 599 @JvmStatic 600 public fun PartitionedMesh.intersects(box: Box, meshToBox: AffineTransform): Boolean = 601 box.intersects(this, meshToBox) 602 603 /** 604 * Returns true when a [PartitionedMesh] intersects with a [Parallelogram]. 605 * 606 * Note that, because it is expensive to apply a transform to a mesh, this method takes a 607 * [meshToParallelogram] transform as an argument. This transform maps from the 608 * [PartitionedMesh]'s coordinate space to the coordinate space that the intersection should be 609 * checked in. 610 */ 611 @JvmStatic 612 public fun PartitionedMesh.intersects( 613 parallelogram: Parallelogram, 614 meshToParallelogram: AffineTransform, 615 ): Boolean = parallelogram.intersects(this, meshToParallelogram) 616 617 @UsedByNative 618 private external fun nativeVecSegmentIntersects( 619 vecX: Float, 620 vecY: Float, 621 segmentStartX: Float, 622 segmentStartY: Float, 623 segmentEndX: Float, 624 segmentEndY: Float, 625 ): Boolean 626 627 @UsedByNative 628 private external fun nativeVecTriangleIntersects( 629 vecX: Float, 630 vecY: Float, 631 triangleP0X: Float, 632 triangleP0Y: Float, 633 triangleP1X: Float, 634 triangleP1Y: Float, 635 triangleP2X: Float, 636 triangleP2Y: Float, 637 ): Boolean 638 639 @UsedByNative 640 private external fun nativeVecParallelogramIntersects( 641 vecX: Float, 642 vecY: Float, 643 parallelogramCenterX: Float, 644 parallelogramCenterY: Float, 645 parallelogramWidth: Float, 646 parallelogramHeight: Float, 647 parallelogramAngleInRadian: Float, 648 parallelogramShearFactor: Float, 649 ): Boolean 650 651 @UsedByNative 652 private external fun nativeVecBoxIntersects( 653 vecX: Float, 654 vecY: Float, 655 boxXMin: Float, 656 boxYMin: Float, 657 boxXMax: Float, 658 boxYMax: Float, 659 ): Boolean 660 661 @UsedByNative 662 private external fun nativeSegmentSegmentIntersects( 663 segment1StartX: Float, 664 segment1StartY: Float, 665 segment1EndX: Float, 666 segment1EndY: Float, 667 segment2StartX: Float, 668 segment2StartY: Float, 669 segment2EndX: Float, 670 segment2EndY: Float, 671 ): Boolean 672 673 @UsedByNative 674 private external fun nativeSegmentTriangleIntersects( 675 segmentStartX: Float, 676 segmentStartY: Float, 677 segmentEndX: Float, 678 segmentEndY: Float, 679 triangleP0X: Float, 680 triangleP0Y: Float, 681 triangleP1X: Float, 682 triangleP1Y: Float, 683 triangleP2X: Float, 684 triangleP2Y: Float, 685 ): Boolean 686 687 @UsedByNative 688 private external fun nativeSegmentBoxIntersects( 689 segmentStartX: Float, 690 segmentStartY: Float, 691 segmentEndX: Float, 692 segmentEndY: Float, 693 boxXMin: Float, 694 boxYMin: Float, 695 boxXMax: Float, 696 boxYMax: Float, 697 ): Boolean 698 699 @UsedByNative 700 private external fun nativeSegmentParallelogramIntersects( 701 segmentStartX: Float, 702 segmentStartY: Float, 703 segmentEndX: Float, 704 segmentEndY: Float, 705 parallelogramCenterX: Float, 706 parallelogramCenterY: Float, 707 parallelogramWidth: Float, 708 parallelogramHeight: Float, 709 parallelogramAngleInRadian: Float, 710 parallelogramShearFactor: Float, 711 ): Boolean 712 713 @UsedByNative 714 private external fun nativeTriangleTriangleIntersects( 715 triangle1P0X: Float, 716 triangle1P0Y: Float, 717 triangle1P1X: Float, 718 triangle1P1Y: Float, 719 triangle1P2X: Float, 720 triangle1P2Y: Float, 721 triangle2P0X: Float, 722 triangle2P0Y: Float, 723 triangle2P1X: Float, 724 triangle2P1Y: Float, 725 triangle2P2X: Float, 726 triangle2P2Y: Float, 727 ): Boolean 728 729 @UsedByNative 730 private external fun nativeTriangleBoxIntersects( 731 triangleP0X: Float, 732 triangleP0Y: Float, 733 triangleP1X: Float, 734 triangleP1Y: Float, 735 triangleP2X: Float, 736 triangleP2Y: Float, 737 boxXMin: Float, 738 boxYMin: Float, 739 boxXMax: Float, 740 boxYMax: Float, 741 ): Boolean 742 743 @UsedByNative 744 private external fun nativeTriangleParallelogramIntersects( 745 triangleP0X: Float, 746 triangleP0Y: Float, 747 triangleP1X: Float, 748 triangleP1Y: Float, 749 triangleP2X: Float, 750 triangleP2Y: Float, 751 parallelogramCenterX: Float, 752 parallelogramCenterY: Float, 753 parallelogramWidth: Float, 754 parallelogramHeight: Float, 755 parallelogramAngleInRadian: Float, 756 parallelogramShearFactor: Float, 757 ): Boolean 758 759 @UsedByNative 760 private external fun nativeBoxBoxIntersects( 761 box1XMin: Float, 762 box1YMin: Float, 763 box1XMax: Float, 764 box1YMax: Float, 765 box2XMin: Float, 766 box2YMin: Float, 767 box2XMax: Float, 768 box2YMax: Float, 769 ): Boolean 770 771 @UsedByNative 772 private external fun nativeBoxParallelogramIntersects( 773 boxXMin: Float, 774 boxYMin: Float, 775 boxXMax: Float, 776 boxYMax: Float, 777 parallelogramCenterX: Float, 778 parallelogramCenterY: Float, 779 parallelogramWidth: Float, 780 parallelogramHeight: Float, 781 parallelogramAngleInRadian: Float, 782 parallelogramShearFactor: Float, 783 ): Boolean 784 785 @UsedByNative 786 private external fun nativeParallelogramParallelogramIntersects( 787 parallelogram1CenterX: Float, 788 parallelogram1CenterY: Float, 789 parallelogram1Width: Float, 790 parallelogram1Height: Float, 791 parallelogram1AngleInRadian: Float, 792 parallelogram1ShearFactor: Float, 793 parallelogram2CenterX: Float, 794 parallelogram2CenterY: Float, 795 parallelogram2Width: Float, 796 parallelogram2Height: Float, 797 parallelogram2AngleInRadian: Float, 798 parallelogram2ShearFactor: Float, 799 ): Boolean 800 801 @UsedByNative 802 private external fun nativeMeshVecIntersects( 803 nativeMeshAddress: Long, 804 vecX: Float, 805 vecY: Float, 806 meshToVecA: Float, 807 meshToVecB: Float, 808 meshToVecC: Float, 809 meshToVecD: Float, 810 meshToVecE: Float, 811 meshToVecF: Float, 812 ): Boolean 813 814 @UsedByNative 815 private external fun nativeMeshSegmentIntersects( 816 nativeMeshAddress: Long, 817 segmentStartX: Float, 818 segmentStartY: Float, 819 segmentEndX: Float, 820 segmentEndY: Float, 821 meshToSegmentA: Float, 822 meshToSegmentB: Float, 823 meshToSegmentC: Float, 824 meshToSegmentD: Float, 825 meshToSegmentE: Float, 826 meshToSegmentF: Float, 827 ): Boolean 828 829 @UsedByNative 830 private external fun nativeMeshTriangleIntersects( 831 nativeMeshAddress: Long, 832 triangleP0X: Float, 833 triangleP0Y: Float, 834 triangleP1X: Float, 835 triangleP1Y: Float, 836 triangleP2X: Float, 837 triangleP2Y: Float, 838 meshToTriangleA: Float, 839 meshToTriangleB: Float, 840 meshToTriangleC: Float, 841 meshToTriangleD: Float, 842 meshToTriangleE: Float, 843 meshToTriangleF: Float, 844 ): Boolean 845 846 @UsedByNative 847 private external fun nativeMeshBoxIntersects( 848 nativeMeshAddress: Long, 849 boxXMin: Float, 850 boxYMin: Float, 851 boxXMax: Float, 852 boxYMax: Float, 853 meshToBoxA: Float, 854 meshToBoxB: Float, 855 meshToBoxC: Float, 856 meshToBoxD: Float, 857 meshToBoxE: Float, 858 meshToBoxF: Float, 859 ): Boolean 860 861 @UsedByNative 862 private external fun nativeMeshParallelogramIntersects( 863 nativeMeshAddress: Long, 864 parallelogramCenterX: Float, 865 parallelogramCenterY: Float, 866 parallelogramWidth: Float, 867 parallelogramHeight: Float, 868 parallelogramAngleInRadian: Float, 869 parallelogramShearFactor: Float, 870 meshToParallelogramA: Float, 871 meshToParallelogramB: Float, 872 meshToParallelogramC: Float, 873 meshToParallelogramD: Float, 874 meshToParallelogramE: Float, 875 meshToParallelogramF: Float, 876 ): Boolean 877 878 @UsedByNative 879 private external fun nativeMeshPartitionedMeshIntersects( 880 thisPartitionedMeshAddress: Long, 881 otherPartitionedMeshAddress: Long, 882 thisToCommonTransformA: Float, 883 thisToCommonTransformB: Float, 884 thisToCommonTransformC: Float, 885 thisToCommonTransformD: Float, 886 thisToCommonTransformE: Float, 887 thisToCommonTransformF: Float, 888 otherToCommonTransformA: Float, 889 otherToCommonTransformB: Float, 890 otherToCommonTransformC: Float, 891 otherToCommonTransformD: Float, 892 otherToCommonTransformE: Float, 893 otherToCommonTransformF: Float, 894 ): Boolean 895 } 896