Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Too high simplification of solution #6

Open
romka-chev opened this issue Dec 21, 2015 · 3 comments
Open

Too high simplification of solution #6

romka-chev opened this issue Dec 21, 2015 · 3 comments

Comments

@romka-chev
Copy link

Hello!

I've try to clip some polygons but result is too simplificated. Here is the screenshots:

Original geometry

  • Light-yellow is the subj

original

Solution geometry

  • Red polygon is the clip
  • Yellow polygon is the intersection
  • Blue polygons is the diffs

solution

All of this is result of execution of this code:

var express = require('express');
var Clipper = require('jsclipper/jsclipper-adapter');
var _ = require('lodash');
var router = express.Router();

router.get('/clip', function (req, res) {
    res.header("Access-Control-Allow-Origin", "*");
    res.header("Access-Control-Allow-Headers", "X-Requested-With");

    var reqSubj = req.query['subj'];
    var reqClip = req.query['clip'];

    var result = {
        intersections: [],
        diffs: []
    };

    _.each(reqSubj, function (subject) {
        //region Ensure of array types instead of objects
        var subjShape = _.toArray(subject.slice(0, 1)[0]);
        var subjHoles = _.map(subject.slice(1), function(value){return _.toArray(value)});

        var clipShape = _.toArray(reqClip.slice(0, 1)[0]);
        var clipHoles = _.map(reqClip.slice(1), function(value){return _.toArray(value)});
        //endregion

        var subj = new Clipper.Polygon(subjShape, subjHoles);
        var clip = new Clipper.Polygon(clipShape, clipHoles);

        var intersectSolutions = subj.intersect(clip);
        var diffSolutions = subj.diff(clip);

        _.each(intersectSolutions, function (solution) {
            result.intersections.push(solution.getPaths())
        });
        _.each(diffSolutions, function (solution) {
            result.diffs.push(solution.getPaths())
        });
    });

    res.type('application/json');
    res.send(result);
});

module.exports = router;

So here is the question: how can i reduce or even disable polygons simplifacation?

@romka-chev
Copy link
Author

Acuuracy becomse good after I increases this value https://github.com/platener/jsclipper/blob/master/jsclipper-adapter.js#L5

// var DEFAULT_SCALE = Math.pow(10, 3)
var DEFAULT_SCALE = Math.pow(10, 12)

@mischkew
Copy link
Contributor

ah good point! we are working with 3d models in mm-scale in scope of 3d-printing. so a thousandth of a mm is enough precision for us.
do you have a proposal how to make this configurable?

@romka-chev
Copy link
Author

I'll make PR for this today

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants