xaviergonz / js-angusj-clipper

Polygon and line clipping and offsetting library (Javascript) - a port of Angus Johnson's clipper

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Offset error

danparn opened this issue · comments

Hello,
Why this offset returns undefined?

const clipperLib = require("js-angusj-clipper")

async function main() {
const clipper = await clipperLib.loadNativeClipperLibInstanceAsync(
clipperLib.NativeClipperLibRequestedFormat.WasmWithAsmJsFallback
)

const seg = clipper.offsetToPaths({
			delta: 1200,
			offsetInputs: [{
				data: [ { x: 168111846, y: 505873449 },
					{ x: 168111360, y: 505874949 } ],
				joinType: clipperLib.JoinType.Round,
				endType: clipperLib.JoinType.Round
			}]
		})
console.log(seg)

}

main()

endType was wrong.

EndType should be this:

//...
        endType: clipperLib.EndType.ClosedPolygon // EndType used correctly

//...
})

Below is the code that I needed to create simple square offsets for closed polygon:

const offsetResult = clipper.offsetToPaths({
    delta: -50,
    offsetInputs: [{
        data: [
            { x: 87, y: 306 },
            { x: 553, y: 294 },
            { x: 421, y: 8 },
            { x: 285, y: 291 },
            { x: 110, y: 13 },
        ],
        joinType: clipperLib.JoinType.Square,
        endType: clipperLib.EndType.ClosedPolygon
    }]
})