Giter Club home page Giter Club logo

clipper2-java's Introduction

I like creative coding and have taken a fancy to producing tooling for it.

Libraries & Tools for Processing

Library Description
Processing Geometry Suite All things computational geometry
PeasyGradients๐Ÿšง Render 11 types of 2D gradient spectrums in 14 color spaces
PThreading A framework for multithreaded drawing in Processing
PText๐Ÿšง Vector-based geometric text manipulation
processing-skia Eases Skija (Skia for Java) interoperability with Processing
ScrollMonitor๐Ÿšง Aesthetic horizontally-scrolling line graph GUI element
Spliner Piecewise best-fit curves for Processing
DistanceField๐Ÿšง Distance fields for 2D shapes

Geometry

Library Description
JOpenVoronoi+ An extended and improved jOpenVoronoi
JMedialAxis๐Ÿšง Computes and models medial axes of geometric shapes
balaban-intersection Balaban's algorithm for finding intersecting segment pairs from a set of line segments
TrapMap Trapezoidal Map โ€” a data structure for fast point location queries
Polygon Morphing A solution to the Vertex Correspondence Problem in 2D Polygon Morphing
Dubins-Curves Path generation for the Dubin's car
Hobby-Curves John Hobbyโ€™s algorithm for producing a smooth curve through a given set of points
Clipper2-Java Java port of Clipper2, a Polygon Clipping and Offsetting Library
BetterBeziers High-precision utils for 2D Cubic Bezier Curves
SRPG Super Random Polygon Generator

Assorted

Library Description
UniformNoise Uniformly distributed Perlin noise
jSimplex Fast parallel calculation of simplex noise using the GPU

Mavenised Forks

Various repo mirrors that are hosted as Maven dependencies from Github via Jitpack

Library Author Artifact
Processing 3 Processing 3.5.4
Processing 4 Processing 4.1.1
controlP5 controlP5 2.2.7-SNAPSHOT
Handy giCentre 1.0.0
gicentreutils giCentre 1.0.0
HE_Mesh wblut 1.0.0
JMP Lib University of Oviedo 1.1.1
FixPointCS XMunkki 0.3
AULib Andrew Glassner 2.2.1

micycle's github stats

clipper2-java's People

Contributors

claasjg avatar frq-asgard-sere avatar frq-asgard-shared avatar micycle1 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

clipper2-java's Issues

How to use `ClipperOffset` with Double coordinates, and get the right solution in Double?

Hi, it is nice to see this library on java... thanks!
I am trying to find out how to use OFFSET --> clipper2.offset.ClipperOffset()
So far I can see there is support for Long 64bit integers and some kind of "normalized" Double variables.
I have made some brutal modifications to source in order to get some results for my project... luckily it seems work with some polygon overlapping, deleted points issues due to some kind of precision reduction along the data path, but I guess there are better and safer ways to do this in Double coordinates.
All points should have Double precision coordinates and this has to remain in the solution apparently.

this is a simple example "ported" from v1 of c# but I am not sure if this is the right way to get a right result/solution.
This seem to work for me (specific use, not tested other ways) with a lot of brutal hacks in source replacing path64 references with pathD. This is obviously wrong but it works for now. The question is, is there an example that can use Double coordinates, and get a right solution apparently in Double?

this code is just for reference, will not work as it is

 static public clipper2.core.PathD doOffsetMethodClipper2 (clipper2.core.PathD p, double offset_nm)
  {
     System.out.println("INSIDE DO OFFSET IN CLIPPER 2 !");
// what is p
// we will feed -->  PathD p with raw point Double precision coordinates
      // Offset
      clipper2.core.PathsD solution = new clipper2.core.PathsD(); // how to get the solution?
     clipper2.offset.ClipperOffset co = new clipper2.offset.ClipperOffset();


      co.AddPath(p, JoinType.Miter, EndType.Polygon);   // add pathD

// see if we have at least 3 valid points for polygons
      System.out.println("See POINT 0 DoOffset X --> "+p.get(0).getX()); // added getter-setter in source
      System.out.println("See POINT 0 DoOffset Y --> "+p.get(0).getY());      
      System.out.println("See POINT 1 DoOffset X --> "+p.get(1).getX());
      System.out.println("See POINT 1 DoOffset Y --> "+p.get(1).getY());        
      System.out.println("See POINT 2 DoOffset X --> "+p.get(2).getX());
      System.out.println("See POINT 2 DoOffset Y --> "+p.get(2).getY());

.
    //  co.setReverseSolution(true);     // parameters   
     // co.setArcTolerance(0.1);     // parameters   
     // co.Execute( offset_nm);

      co.ExecuteD( offset_nm); // brutal lot of modifications in several places in order to get PathD support (how to use Long normalization?)
//co.execute(solutions, offset_nm); // the old v1 execute

// SOMETHING LIKE clipper2.Clipper.InflatePaths HERE? solution = clipper2.Clipper.InflatePaths ...
      clipper2.core.PathsD pths = new clipper2.core.PathsD();
      pths.add(p);

     solution = clipper2.Clipper.InflatePaths(pths, offset_nm, JoinType.Miter, EndType.Polygon);   // new for v2
     return   solution.get(0); // to a loop in order to construct path2D shapes

     } 

So, if there is an example in the right way this "offset" is supposed to be used, that would be useful...

ClipperOffset returning empty solution

I've got a problem that I imagine is due to some mistake on my part, but I've been unsuccessful in identifying the exact cause. I am trying to offset a polyline that is composed of line segments with xyz coordinates. Since the clipper2 library only uses xy coordinates, I'm basically trying to make PointD/PathD objects that have the original polyline's x/y values, inflate them to get the offset x/y values, and then update the original polyline to use those new offset x/y values. However, when I call InflatePaths(), the solution set is empty. The if(solution.isNotEmpty()) block never evaluates to true.

So I tried testing just some arbitrary points and even THIS gives an empty "testSolution":

val testPath = PathD(listOf(PointD(10, 20), PointD(25, 45), PointD(80, 155)))
val testPathsList = PathsD(listOf(testPath))
val testSolution = Clipper.InflatePaths(testPathsList, 5.0, JoinType.Round, EndType.Round)
Log.d("test", "Test solution: ${testSolution}") // Prints out "Test solution: "

The full problematic code:

private fun offsetPolyline(originalPolyline: ArrayList<Point3D>, offsetDistance: Double, closed:Boolean): ArrayList<Point3D> {
        val pathForClipper = PathD()

        for (point in originalPolyline) {
            // Scale the x/y values for Clipper and add them to a path
            pathForClipper.add(PointD(point.x, point.y))
        }
        // Add the path to a paths object so we can inflate
        val paths = PathsD()
        paths.add(pathForClipper)

        // Use ClipperOffset to offset the path
        val solution = Clipper.InflatePaths(paths, offsetDistance, JoinType.Round, if (closed) EndType.Polygon else EndType.Round) // again, consider the scaling
        // Convert the resulting path(s) back to ArrayList<Point3D>
        val offsetPolyline = ArrayList(originalPolyline)
        if (solution.isNotEmpty()) {
            for (i in solution[0].indices) { // take the first path, consider others?
                offsetPolyline[i].x = solution[0][i].x
                offsetPolyline[i].y = solution[0][i].y
            }
        } else {
            Log.d("test", "Solution empty.")

        }
        return offsetPolyline
}

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.