More accurate check of point inside closed contour.

Discussions around the CAM Add-On of QCAD.

Moderator: andrew

Forum rules

Always indicate your operating system and QCAD version.

Indicate the post processor used.

Attach drawing files and screenshots.

Post one question per topic.

Post Reply
User avatar
srl
Full Member
Posts: 65
Joined: Tue Aug 09, 2011 4:40 am

More accurate check of point inside closed contour.

Post by srl » Sun Oct 05, 2014 5:39 am

Here is some code I added to the exportContour function.
This will help me to reverse the direction of closed contours inside each other for offset cutting.

Code: Select all

 // point not inside contour
                // (more accurate check than bounding box, but still needs fixing):
                //if (!contour.contains(point)) {
                    //return;
                //}


		//Start of my Code. SRL
			
		var ispa = [];
		var ve = new RVector(bbox.getMinimum().x-1.22, bbox.getMinimum().y-1.11);
		var lline = new RLine(point,ve);// A line from the inside contour to just outside the outer contour. 
		for (k=0; k<contour.entityIds.length; k++) {// Go arround each of the contour entities. 
                	var centity = contour.queryEntity(contour.entityIds[k]);
                	var isp = lline.getIntersectionPoints(centity.getData().castToShape());
			for (var i = 0; i < isp.length; ++i) {// Put all the intersecting points into a array.
				ispa.push(isp[i]); 			
			}
            	}
		var ipoints = ispa.length; 
		if(ipoints & 1); // Crossed over odd number of entities so its OK. 
		else{
			if (contour.isClosed(this.getTolerance())){return;}
		}// Crossed over no or even No of entities in closed outer contour. Return.
		// End of my code. SRL
Its added in where you see Andrews comments in the function.

srl

User avatar
srl
Full Member
Posts: 65
Joined: Tue Aug 09, 2011 4:40 am

Re: More accurate check of point inside closed contour.

Post by srl » Tue Oct 14, 2014 7:26 am

Hi Andrew.
Would It be possible in the next release to have contour.contains(point) called and have the function commented out to just return "true" instead. That way we can write our own.
Because exportContour calls itself I have to include code in the middle of it.
DSC08044.JPG
DSC08044.JPG (69.78 KiB) Viewed 8225 times
srl

User avatar
andrew
Site Admin
Posts: 9037
Joined: Fri Mar 30, 2007 6:07 am

Re: More accurate check of point inside closed contour.

Post by andrew » Tue Oct 14, 2014 10:03 am

OK, I've refactored accordingly, so exporters can reimplement
CamExporter.prototype.contourContains = function(contour, point) {
    return true;
}

Post Reply

Return to “QCAD/CAM”