Closed sdrabb closed 9 years ago
I can compile here without issues for js too. If you can share more info about your process maybe we can find a solution:
haxe -version
)?PolyTools.hx
is in the hxGeomAlgo
folder?hxPixels
lib from https://github.com/azrafe7/hxPixelsIn the meanwhile, try adding --macro include('hxGeomAlgo')
at the end of your command line and see if it works.
thanks for you're answer.
to compile i wrote a file compile.hxml in hxGeomAlgo folder, that containing these 2 line:
-main SnoeyinkKeil -js test.js
and i compile with ubuntu terminal using that commands:
haxe compile.hxml
it's my procedure correct?
it's my procedure correct?
Not exactly...
Put this Main.hx
file (which is a simple test for a star-shaped polygon) in the src folder:
package;
import hxGeomAlgo.HxPoint;
import hxGeomAlgo.SnoeyinkKeil;
using hxGeomAlgo.PolyTools;
class Main {
static function main():Void {
var polyCoords:Array<Float> = [96, 3, 54, 41, 2, 7, 32, 64, 5, 121, 9, 120, 58, 82, 112, 115, 74, 61, 97, 3];
var poly = polyCoords.toPointArray();
var decomposition = SnoeyinkKeil.decomposePoly(poly);
for (p in decomposition) {
trace(p);
#if js
js.Browser.document.writeln('<tt>' + Std.string(p) + '</tt></br>');
#end
}
}
}
Then run: haxe -cp src -main Main -js test.js
Done!
If you're still beginning with haxe this might seem a bit too much (but really you'll find it very simple once you get accustomed to it). So let's start with installing haxe 3.2, and let me know if you get stuck at any point.
i do youre procedure but i get that error:
hxGeomAlgo/SnoeyinkKeil.hx:142: characters 9-59 : Variable initialization must be a constant value hxGeomAlgo/SnoeyinkKeil.hx:144: characters 9-52 : Variable initialization must be a constant value
That's because you're using an old version of the compiler, and you need haxe 3.2 or newer to use the lib.
you're right thank's, how i can delete the old one you know?
It's probably safe to just remove the haxe folder and then run the installer script (which should set up the correct env variables), but I don't know for sure.
Thanks i've another question it's possibile embed You're library with my javascript program?
Il venerdì 9 ottobre 2015, Giuseppe Di Mauro notifications@github.com ha scritto:
It's probably safe to just remove the haxe folder and then run the installer script (which should set up the correct env variables), but I don't know for sure.
— Reply to this email directly or view it on GitHub https://github.com/azrafe7/hxGeomAlgo/issues/8#issuecomment-146982400.
Ok , i'ge got another question i've a javascrip
Il venerdì 9 ottobre 2015, Giuseppe Di Mauro <notifications@github.com javascript:_e(%7B%7D,'cvml','notifications@github.com');> ha scritto:
It's probably safe to just remove the haxe folder and then run the installer script (which should set up the correct env variables), but I don't know for sure.
— Reply to this email directly or view it on GitHub https://github.com/azrafe7/hxGeomAlgo/issues/8#issuecomment-146982400.
Yes, it's definitely possible to use from a pure js side. Let me cook up an example...
Also, I've edited my code snippet above!
That's great You're very kind thanks! i wait You're example
Hey @sdrabb, see this gist (https://gist.github.com/azrafe7/7fc1214cae8c4fb18597). It contains three files
It's very basic, and you'll probably need to inspect the hxGeomAlgo var in the inspector from time to time to better understand how the functions are exposed. But it should give you a rough idea of how to use it.
Let me know if you have any problems.
thank's a lot... i have compiled your library updating haxe to 3.2.0..
now i'll try your example, if i've a problem I will let you know.
at the moment i've tryied your keil algorith on my map editor and it worked great! :+1:
Closing this now, as the original problem has been fixed (older compiler).
Feel free to open another one if you have issues with the lib, or need help.
Ok very kind thank
Il sabato 10 ottobre 2015, Giuseppe Di Mauro notifications@github.com ha scritto:
Closing this now, as the original problem has been fixed (older compiler).
Feel free to open another one if you have issues with the lib, or need help.
— Reply to this email directly or view it on GitHub https://github.com/azrafe7/hxGeomAlgo/issues/8#issuecomment-147125987.
what are the commands to compile alla the library like your example?
Something like:
haxe -cp src -js bin/hxGeomAlgo.js --macro include('hxGeomAlgo')
but notice that currently you need to add @:expose
on top of the classes you want to be visible from the js side (see http://haxe.org/manual/target-javascript-expose.html). For example open SnoeinkKeil.hx and change the class declaration to
@:expose
class SnoeyinkKeil {
(I'm in the middle of adding this, but have not yet figured out how to do it for enums, so have not pushed it yet to github.)
why sometimes when i put the coordinate on decompoly function i get that error?
here my function:
function generateConvexArea(points){
var roomPoints = points.slice();
var polyCoords = [];
for(i=0; i < roomPoints.length ; i++){
polyCoords.push(roomPoints[i].x);
polyCoords.push(roomPoints[i].y);
}
var hxGeomAlgo = window.hxGeomAlgo;
var poly = hxGeomAlgo.PolyTools.toPointArray(polyCoords);
var decomposition = hxGeomAlgo.SnoeyinkKeil.decomposePoly(poly);
return JSON.stringify(decomposition);
}
ehere the error: Uncaught TypeError: Cannot read property 'y' of undefined.
then sometime it work why?
i solve it using https://mpen.ca/406/bayazit
changing my function to :+1:
function generateConvexArea(points){
var roomPoints = points.slice();
var polyCoords = [];
for(i=0; i < roomPoints.length ; i++){
polyCoords.push(roomPoints[i].x);
polyCoords.push(roomPoints[i].y);
}
var hxGeomAlgo = window.hxGeomAlgo;
var poly = hxGeomAlgo.PolyTools.toPointArray(polyCoords);
var decomposition = hxGeomAlgo.Bayazit.decomposePoly(poly);
return JSON.stringify(decomposition);
}
Can you open the console (F12 on Chrome and Firefox) and report where the error is happening?
In general it means that the examined point is null, but I'd need a full reproducible test to investigate further, if you could provide it I will take a look.
Also, if you can share just the coords of the poly which is not working with SnoeyinkKeil, maybe I can reproduce with that.
the line of error is:
hxGeomAlgo.js:1617 Uncaught TypeError: Cannot read property 'y' of undefined
hxGeomAlgo_PolyTools.isLeft = function(p,a,b) {
return (a.x - p.x) * (b.y - p.y) - (b.x - p.x) * (a.y - p.y) > 0; <-------- that line
};
the coords of the polygon are:
[32, 14, 36, 14, 36, 20, 44, 20, 44, 10, 42, 8, 32, 8, 32, 10, 32, 12]
hxGeomAlgo.js:1617 Uncaught TypeError: Cannot read property 'y' of undefined
the same poly with Bayazit work.
And i've got another question: Once i've decomposed my polygon is there a function in the library to get the 'Convex CUT' that the algorithm have generated?
Your poly seems to work fine with haxe, but maybe I'm missing something. Still investigating...
Anyway there could be issues with collinear or duplicate points. You can try running your poly through RamerDouglasPeucker/VisvalingamWhyatt simplification function before decomposing it?
As in:
var poly = hxGeomAlgo.PolyTools.toPointArray(polyCoords);
poly = hxGeomAlgo.RamerDouglasPeucker.simplify(poly);
var decomposition = hxGeomAlgo.SnoeyinkKeil.decomposePoly(poly);
and it should work (hopefully).
Some of the algos in the lib are very picky about the input, so the user has to clean it up before passing it around.
About the convex cut: that's exactly what SnoewyinkKeil/Bayazit decomposition do, return an array of convex polygons (actually Array of Array of HxPoint). So you should be good to go.
Mind to share your use case? (as maybe there's some shortcut I could advice you to take)
with your suggest work thank's!
i'm build a map and i need that's cut and convexArea of the sigle room that in my program is a polygon.
Ah, so it was about collinear points in the end!?
Can you post the coords of that image (including the collinear points)? (I could figure them out - i know -, but if you already have them... ;)
Ok, the poly is more or less [1,2,5,2,5,1,8,1,11,1,11,3,15,3,15,6,8,6,1,6]
(with some scale applied).
But then the convex decomposition could very well be something like
In your specific case I think you need to come up with a way to separate rooms, and then apply the decomposition.
thank's a lot the rooms are separated yet... :+1:
i ask you only if in your library there is a function that return the cut
Sorry I don't fully understand you. What you're meaning with "the cut"?
with cut i mean the 2 point that the algorithm use to divide the polygon in convex area
So you mean splitting a polygon with a line and returning the separated shapes/polys?!
In that case: no, sorry, nothing like that in the lib at the moment (maybe in the future - I don't know). Perhaps you can try to look into nape (http://napephys.com/), which I think is really robust and has a cut function too (along with many poly decomposition methods), or try to roll your own algorithm taking ideas from stackoverflow and the like.
Well, maybe using the Tess2 package and boolean ops would not be too hard to achieve something like that, but it really comes up to your specific use case and if you can work around it without some unnecessary computations.
(Meaning: maybe storing the rooms in a different way would simplify things from the beginning, no?! :stuck_out_tongue_winking_eye:)
Thinking about it, should be pretty easy to cut a polygon by using Tess2.difference()
. The only thing to watch out for is that you have to slightly expand the cutting line making it into a poly.
So if you want to cut using the line [0, 50, 150, 50]
, you actually pass in something like [0, 50, 150, 50, 150, 50.1, 0, 50.1]
.
thank's... there is a via to consider the collinear points with SnoeyinkKeil?
Bayazit consider that points or i mistake?
in short i want that in my convexarea arrays there are the green points that are collinear:
it's possible?
Since collinear points don't contribute to the simplification you can remove them from the input and add them back to the output, no?!
hi i'm trying to convert to javascript you're work but it does'nt work. could you help me please?
here's my error: Invalid commandline class : SnoeyinkKeil should be hxGeomAlgo.SnoeyinkKeil ./SnoeyinkKeil.hx:23: characters 7-27 : Class not found : hxGeomAlgo.PolyTools
anyone could help me to compile the hxGeomAlgo in javascript please?