Geomerative getArea() bug?
in
Contributed Library Questions
•
3 years ago
Hi All
I've been working with the geomerative library and am building a bit of code that relies on calling up the final area of a shape that has a number of different 'difference' functions applied to it over time.
The getArea() function seems to work fine as long as the differences are simple but once the shape fragments into smaller parts they no-longer accurately add up; the total area results seem to get quite anomalous. Am I doing something wrong here? or is there a way round this that anyone knows?
I've prepared a simple bit of code that demonstrates the issue.
Any pointers very much appreciated!
Ta
S
- import geomerative.*;
- RShape shp1;
- RShape shp2;
- RShape shp3;
- RShape shp4;
- RShape cursorShape;
- float A1;
- float A2;
- void setup()
- {
- size(400, 400);
- smooth();
- RG.init(this);
- shp1 = RShape.createRectangle(0, 0, 150.0, 150.0);
- shp2 = RShape.createRing(0, 0, 100,50);
- shp4 = RShape.createRectangle(0, 0, 0, 1);
- }
- void draw()
- {
- background(255);
- translate(width/2,height/2);
- cursorShape = new RShape(shp2);
- cursorShape.translate(mouseX - width/2, mouseY - height/2);
- shp3 = RG.diff( shp1, cursorShape );
- shp4 = RG.intersection( shp1, cursorShape );
- strokeWeight(0.5);
- fill(0,255,0,125);
- stroke(0);
- cursorShape.draw();
- strokeWeight(3);
- fill(255,255,0);
- shp3.draw();
- A1 = shp3.getArea();
- if(shp1.intersects(cursorShape)) A2 = shp4.getArea();
- else A2 = 0;
- print("REMOVED:");
- print(A2);
- print(" REMAINDER:");
- print(A1);
- print(" TOTAL:");
- println(A1+A2);
- }
- void mousePressed(){
- shp1= shp3;
- }
1