Difference between revisions of "Cabal Common Library Doc 2DCollision"
m (New doc for CCL1.5.1) |
Cholmondely (talk | contribs) m (Retagged!) |
||
(4 intermediate revisions by one other user not shown) | |||
Line 1: | Line 1: | ||
== Overview == | == Overview == | ||
− | This is the main class for the 2D helpers with its members. Scripts can instantiate a copy, e.g. | + | This is the main class for the 2D helpers with its members and part of the [[Cabal_Common_Library]]. Scripts can instantiate a copy, e.g. |
− | + | this.myHelper = new worldScripts.Cabal_Common_Functions.Cabal_Common_2DCollision(); | |
+ | Versions before v1.6 have used <code>this.myHelper = new Cabal_Common_2DCollision();</code> | ||
+ | |||
== Properties == | == Properties == | ||
=== internalVersion === | === internalVersion === | ||
Number. Property to give OXPs a chance to check the required lib min. version easily. This number will be raised with every release. | Number. Property to give OXPs a chance to check the required lib min. version easily. This number will be raised with every release. | ||
− | + | var a = this.myHelper.internalVersion; | |
− | + | ||
+ | Current version is {{CodeEx|codeex={{CCL_Int}}}} | ||
+ | |||
== Methods == | == Methods == | ||
Line 14: | Line 18: | ||
=== boundingBox() === | === boundingBox() === | ||
{{CodeEx|codeex=boundingBox: function( minmax, pos )}} | {{CodeEx|codeex=boundingBox: function( minmax, pos )}} | ||
+ | {{CodeExTime|native=0.000042|extension=0.000013|js=0.000136}} | ||
Checks if point is inside the bounding box. | Checks if point is inside the bounding box. | ||
Line 26: | Line 31: | ||
=== pointInPoly() === | === pointInPoly() === | ||
{{CodeEx|codeex=pointInPoly: function( nvert, vertx, verty, pos, con )}} | {{CodeEx|codeex=pointInPoly: function( nvert, vertx, verty, pos, con )}} | ||
+ | {{CodeExTime|native=0.000042|extension=0.000012|js=0.000101}} | ||
Checks if a point is inside a polygon. | Checks if a point is inside a polygon. | ||
Line 40: | Line 46: | ||
=== pointOnLine() === | === pointOnLine() === | ||
{{CodeEx|codeex=pointOnLine: function( pa, pb, pos )}} | {{CodeEx|codeex=pointOnLine: function( pa, pb, pos )}} | ||
+ | {{CodeExTime|native=0.000240|extension=0.000123|js=0.000252}} | ||
Checks if point is on a specified line with a tolerance of 0.4. | Checks if point is on a specified line with a tolerance of 0.4. | ||
This method has a problem with vertical lines. If it needs to be more accurate use .pointOnLineB(). | This method has a problem with vertical lines. If it needs to be more accurate use .pointOnLineB(). | ||
Line 54: | Line 61: | ||
=== pointOnLineB() === | === pointOnLineB() === | ||
{{CodeEx|codeex=pointOnLineB: function( p1,p2,p3,tol )}} | {{CodeEx|codeex=pointOnLineB: function( p1,p2,p3,tol )}} | ||
+ | {{CodeExTime|native=0.000272|extension=0.000141|js=0.000303}} | ||
Checks if point is on a specified line. | Checks if point is on a specified line. | ||
Based on Paul Bourkes explanation ([http://paulbourke.net/geometry/pointline/]). | Based on Paul Bourkes explanation ([http://paulbourke.net/geometry/pointline/]). | ||
Line 67: | Line 75: | ||
− | [[Category: | + | [[Category:OXP API's]] |
Latest revision as of 14:14, 20 September 2023
Contents
Overview
This is the main class for the 2D helpers with its members and part of the Cabal_Common_Library. Scripts can instantiate a copy, e.g.
this.myHelper = new worldScripts.Cabal_Common_Functions.Cabal_Common_2DCollision();
Versions before v1.6 have used this.myHelper = new Cabal_Common_2DCollision();
Properties
internalVersion
Number. Property to give OXPs a chance to check the required lib min. version easily. This number will be raised with every release.
var a = this.myHelper.internalVersion;
Current version is
15 |
Methods
All methods are ignoring the z-coordinate .-)
boundingBox()
boundingBox: function( minmax, pos ) |
Profiler | |
---|---|
Native | 0.000042s |
Extension | 0.000013s |
JS | 0.000136s |
Checks if point is inside the bounding box.
Parameters:
- minmax
- Array. 4 positions in a.x,a.y,b.x,b.y
- pos
- Vector. Position to be checked.
Returns:
- inside
- Boolean. True if inside.
pointInPoly()
pointInPoly: function( nvert, vertx, verty, pos, con ) |
Profiler | |
---|---|
Native | 0.000042s |
Extension | 0.000012s |
JS | 0.000101s |
Checks if a point is inside a polygon.
Parameters:
- nvert
- Number of vertices in the polygon.
- vertx, verty
- Arrays containing the x- and y-coordinates of the polygon's vertices.
- pos
- Vector. x- and y-coordinate of the test point.
- con
- Boolean. Concave shapes may need to set it.
Returns:
- inside
- Boolean. True if inside.
pointOnLine()
pointOnLine: function( pa, pb, pos ) |
Profiler | |
---|---|
Native | 0.000240s |
Extension | 0.000123s |
JS | 0.000252s |
Checks if point is on a specified line with a tolerance of 0.4. This method has a problem with vertical lines. If it needs to be more accurate use .pointOnLineB().
Parameters:
- pa
- Vector. Starting point of the line.
- pb
- Vector. End point of the line.
- pos
- Vector. Position to be checked.
Returns:
- online
- Boolean. True if on line (within tolerance).
pointOnLineB()
pointOnLineB: function( p1,p2,p3,tol ) |
Profiler | |
---|---|
Native | 0.000272s |
Extension | 0.000141s |
JS | 0.000303s |
Checks if point is on a specified line. Based on Paul Bourkes explanation ([1]).
Parameters:
- p1
- Vector. Starting point of the line.
- p2
- Vector. End point of the line.
- p3
- Vector. Position to be checked.
- tol
- Number. Tolerance. Default 0.01.
Returns:
- online
- Boolean. True if on line (within tolerance).