korlibs-archive / korma Goto Github PK
View Code? Open in Web Editor NEWMathematics library focused on geometry for Multiplatform Kotlin 1.3
Home Page: https://korlibs.soywiz.com/korma/
License: Other
Mathematics library focused on geometry for Multiplatform Kotlin 1.3
Home Page: https://korlibs.soywiz.com/korma/
License: Other
Hello,
I came across a weird bug when making a Shape2d.Rectangle
val points = listOf(Point(x = 1.0, y = 1.0), Point(x = 1.0, y = 2.0), Point(x = 2.0, y = 2.0), Point(x =2.0, y = 1.0))
val t = PointArrayList(points).toShape2d(true)
// t is Shape2d.Polygon instead of Shape2d.Rectangle
val points2 = listOf(Point(x = 2.0, y = 2.0), Point(x = 2.0, y = 1.0), Point(x = 1.0, y = 1.0), Point(x = 1.0, y = 2.0))
val u = PointArrayList(points2).toShape2d(true)
// u is Shape2d.Polygon instead of Shape2d.Rectangle
val points3 = listOf(Point(x = 2.0, y = 1.0), Point(x = 1.0, y = 1.0), Point(x = 1.0, y = 2.0), Point(x = 2.0, y = 2.0))
val w = PointArrayList(points3).toShape2d(true)
// w is Shape2d.Rectange => correct
val points4 = listOf(Point(x = 1.0, y = 1.0), Point(x = 2.0, y = 1.0), Point(x = 2.0, y = 2.0), Point(x = 1.0, y = 2.0))
val x = PointArrayList(points4).toShape2d(true)
// x is Shape2d.Rectange => correct
Shoudn't these all be Shape2d.Rectangle?
Check the number of segments of the two sets and make the outer iteration to use the set with less elements.
This operation is used for clipping.
Hello,
I'm using the collidesWith
function on the Shape2d.Rectangle and I am getting unexpected results:
val rect1 = Shape2d.Rectangle(
x = 15.503612232813342,
y = 29.187611816208875,
width = 9.525771277108397,
height = 8.205535424065108
)
// rect1.right == 25.02938350992174
val rect2 = Shape2d.Rectangle(
x = 25.648207133295152,
y = 28.226381294575567,
width = 14.579502618999763,
height = 12.297989263608322
)
I expect rect1.collideWith(rect2)
to return false but it returns true. They're next to each other but not colliding.
Hi :)
Bintray has been sunset. I see a commit preparing to use central instead. What's the current state of this transition?
The readme still shows Bintray is the way to go, which doesn't seem to work...
Current state seems to have redundant properties:
interface IRectangle {
val _x: Double
val _y: Double
val _width: Double
val _height: Double
}
val IRectangle.x get() = _x
val IRectangle.y get() = _y
val IRectangle.width get() = _width
val IRectangle.height get() = _height
I think it can become like this:
interface IRectangle {
val x: Double
val y: Double
val width: Double
val height: Double
}
As discussed, it can be handy but low-performant on native.
Related issue: korlibs-archive/korim#32
Related commit: korlibs-archive/korim@f88f3ef
Suppose I have a KMM project with Kotlin function in common
containing size: Size
param which becomes Any
in Swift wrapper or id
in ObjC.
Now if I need to call this function and pass size
var - how can I construct Size
to pass it from Swift / ObjC to Kotlin? Do I need to write my own expect
wrapper for CGSize
?
Hello,
Looks like it isn't actual for now:
// Additional funcionality using Clipper and poly2try code (with separate licenses):
// - https://github.com/korlibs/korma/blob/master/korma-shape-ops/LICENSE
// - https://github.com/korlibs/korma/blob/master/korma-triangulate-pathfind/LICENSE
dependencies {
implementation "com.soywiz.korlibs.korma:korma-shape-ops:$kormaVersion"
implementation "com.soywiz.korlibs.korma:korma-triangulate-pathfind:$kormaVersion"
}
Instead of it i used:
dependencies {
implementation "com.soywiz.korlibs.korma:korma-shape:$kormaVersion"
}
Common DSLMarker to avoid issues -> Nico, Mike
Since we are using DSL that mixes vector building with views, we need to have a common dsl annotation that limits the scope. To avoid for example issues with circle (view builder) and circle (vector drawing)
Forgive me if it already exists but I couldn't find it.
It would be very helpful for me, and I assume others, if I could apply a matrix to a point similar to
android.graphics.Matrix. mapPoints()
Hey! I've just found the wrong behavior. Two vector paths are intersecting but KorMA says they don't:
// KorMA version = 1.11.16
suspend fun main() = Korge {
val left = VectorPath(
commands = IntArrayList(0, 3, 3, 3, 3, 4),
data = DoubleArrayList(
13.0, 6.5,
13.0, 2.910149126300001, 10.089850873700001, 8.881784197001252E-16, 6.5, 0.0,
2.910149126300001, 2.220446049250313E-16, 8.881784197001252E-16, 2.9101491263000003, 0.0, 6.499999999999999,
-6.661338147750939E-16, 10.089850873699998, 2.9101491262999994, 13.0, 6.499999999999999, 13.0,
10.089850873699996, 13.0, 12.999999999999998, 10.089850873700001, 13.0, 6.500000000000002
)
)
val leftMatrix = Matrix(a=3.0, b=0.0, c=0.0, d=3.0, tx=103.5, ty=364.65667977653686)
val right = VectorPath(
commands = IntArrayList(0, 1, 1, 1, 4),
data = DoubleArrayList(
0.0, 0.0,
22.0, 0.0,
22.0, 103.0,
0.0, 103.0
)
)
val rightMatrix = Matrix(a=3.0, b=0.0, c=0.0, d=3.0, tx=69.78806430000003, ty=195.0)
println(VectorPath.intersects(left, leftMatrix, right, rightMatrix)) // prints "false"
}
I've also drawn these paths for convenience at about:blank
:
var canvas = document.createElement("CANVAS");
canvas.width = 1000;
canvas.height = 600;
var ctx = canvas.getContext("2d");
document.body.appendChild(canvas);
ctx.setTransform(3.0, 0.0, 0.0, 3.0, 69.78806430000003, 195.0);
ctx.beginPath();
ctx.moveTo(0, 0);
ctx.lineTo(22, 0);
ctx.lineTo(22, 103);
ctx.lineTo(0, 103);
ctx.closePath();
ctx.stroke();
ctx.setTransform(3.0, 0.0, 0.0, 3.0, 103.5, 364.65667977653686);
ctx.beginPath();
ctx.moveTo(13,6.5);
ctx.bezierCurveTo(13,2.910149126300001,10.089850873700001,0,6.5,0);
ctx.bezierCurveTo(2.910149126300001,0,0,2.9101491263000003,0,6.499999999999999);
ctx.bezierCurveTo(0,10.089850873699998,2.9101491262999994,13,6.499999999999999,13);
ctx.bezierCurveTo(10.089850873699996,13,12.999999999999998,10.089850873700001,13,6.500000000000002);
ctx.closePath();
ctx.stroke();
I think because of this Views collisions work not properly in KorGE:
I upgraded from 2.0.9 to the latest and get the following errors on my unsigned variables: Please make sure you have the required dependencies for unsigned types in the classpath. When I lower back down to 2.0.9 it works just fine.
Hi! I see LF eol in .editorconfig
:
https://github.com/korlibs/korma/blob/7d233a0f63b9d41c1891c7f5ca44ab50d753e3a1/.editorconfig#L3
However, some files have CRLF eol, for example, https://github.com/korlibs/korma/blob/7d233a0f63b9d41c1891c7f5ca44ab50d753e3a1/korma/src/commonMain/kotlin/com/soywiz/korma/geom/shape/Shape2d.kt.
Maybe it's worth to update all files in the repo to match editorconfig.
Number
are deprecated and Double
casts to Float
in the end.
The following two lines seem to intersect, but Line.intersects()
does not return true
val line1 = Line(Point(284, 158), Point(246, 158))
val line2 = Line(Point(303.89273932825165, 198.88732201874024), Point(257.05152496464524, 155.2765362319343))
Napier.d("Test line intersect: ${line1.intersects(line2)}") // use whatever printing option you'd like here
Now that KorMA includes the scanline for polygons, replaces korlibs-archive/korim#30
We have to create a structure that split the lines in buckets. We can create buckets that are variable size. Every top and bottom Y points can define the size of each bucket. Then we can populate those buckets and perform a binary search to locate the bucket and just iterate the points on that bucket per scanline
Checking if any of the points is inside the other shape (since it is symmetric we can determine which one iterate to reduce complexity)
Hi there,
I'm currently using the library to evaluate the coordinates between shapes so let's say I have a
VectorPath with the following coordinates:
(10, 10), (60, 10), (60, 0) (80, 0), (80, 90), and (10, 90)
And I have a Shape2d with the following coordinates:
(10, 80), (25, 80), (25, 90), and (10, 90)
I'd expect that VectorPath.containsPoint(25, 90) would return true because the point is on the line between (10,90) and (80,90). It seems containsPoint is exclusive for the upperBound. Is there another method to include it?
Hi.
Trying to use triangulate functionality and on some set of points I receive
java.lang.Error: Point2d not in triangle
at com.soywiz.korma.geom.triangle.TriangleKt.getPointIndexOffset(Triangle.kt:158)
at com.soywiz.korma.geom.triangle.TriangleKt.pointCCW(Triangle.kt:163)
at com.soywiz.korma.triangle.internal.Sweep.edgeEventByPoints(Poly2Tri.kt:260)
at com.soywiz.korma.triangle.internal.Sweep.edgeEventByEdge(Poly2Tri.kt:254)
at com.soywiz.korma.triangle.internal.Sweep.sweepPoints(Poly2Tri.kt:205)
at com.soywiz.korma.triangle.internal.Sweep.triangulate(Poly2Tri.kt:195)
at com.soywiz.korma.triangle.triangulate.TriangulateKt.triangulate(Triangulate.kt:12)
Example set:
-371.182, 307.381
-365.909, 310.721
-369.425, 318.455
-373.468, 317.048
-375.401, 315.818
-376.28, 314.588
-376.28, 313.357
-375.753, 311.599
-373.643, 307.733
-372.764, 307.029
-372.061, 307.029
I've tried to close polyline (by adding first point to the end of list) and reverse points order - error still happenes.
Tried to use one of another Poly2Tri java implementation and it works
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.