Giter VIP home page Giter VIP logo

triangolatte's People

Contributors

dependabot[bot] avatar gitter-badger avatar tchayen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

triangolatte's Issues

Ear cutting may terminate too early?

Thank you for creating this helpful library!
I have just started playing around with it and may have come across a bug. As I'm just coming to grips with it I would appreciate another set of eyes

Here is a reproducing example:

outer = []triangolatte.Point{
    {0.0, 0.0},
    {-10.0, 0.0},
    {-10.0, -10.0},
    {0.0, -10.0},
}

hole = []triangolatte.Point{
    {-1.8813725490196056, -4.059803921568627},
    {-3.663725490196078, -2.0794117647058803},
    {-2.1784313725490176, -3.465686274509803},
    {-2.0794117647058803, -3.5647058823529405},
}

poly, err := triangolatte.JoinHoles([][]triangolatte.Point{outer, hole})
if err != nil {
    panic(fmt.Sprintf("JoinHoles failed: %s", err))
}

fmt.Println("Poly is", poly)
_, err = triangolatte.Polygon(poly)
if err != nil {
    panic(fmt.Sprintf("Polygon failed: %s", err))
}

The above will fail to triangulate the resulting polygon. In my opinion this is because it terminates too early. This proposed change fixes the example above:

diff --git a/polygon.go b/polygon.go
index 1c3fe48..825813c 100644
--- a/polygon.go
+++ b/polygon.go
@@ -292,7 +292,7 @@ func Polygon(points []Point) ([]float64, error) {

                        ear.Remove()
                        ear = ear.Next
-                       stop = stop.Next
+                       stop = ear
                        continue
                }

With the fix applied it does, however, still fail to triangulate the more complete polygon from which I created the above example. The original polygon I was trying to triangulate is reproduced in this gist

Sadly the original example is quite large and I don't have good insights where it fails. I did find that tripy manages to triangulate the original polygon.

I would appreciate any insights on where things break.

Triangulation error

I was looking into using this library for a small side project but I am currently running into an error.

This is a reproducible unit test:

func TestTriangulationError(t *testing.T) {
	vertices := []triangolatte.Point{
		{X: 512.00, Y: 30.00},
		{X: 512.00, Y: 145.04},
		{X: 596.96, Y: 145.04},
		{X: 596.96, Y: 85.05},
		{X: 636.96, Y: 85.05},
		{X: 636.96, Y: 30.00},
		{X: 512.00, Y: 30.00},
	}

	_, err := triangolatte.Polygon(vertices)
	if err != nil {
		t.Fatal(err)
	}
}
=== RUN   TestTriangulationError
--- FAIL: TestTriangulationError (0.00s)
    shape_test.go:22: oops
FAIL

Process finished with exit code 1

I have no experience with doing polygon triangulation so maybe I am doing something stupid? What resources would you recommend to learn more about the algorithm in detail?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.