| 32 | } |
| 33 | |
| 34 | Node* PolygonModule::evaluate(const Context& ctx) const |
| 35 | { |
| 36 | auto* pointsVec=dynamic_cast<VectorValue*>(getParameterArgument(ctx,0)); |
| 37 | VectorValue* linesVec=dynamic_cast<VectorValue*>(ctx.getArgumentDeprecated(1,"lines","paths",reporter)); |
| 38 | |
| 39 | auto* pn=new PrimitiveNode(); |
| 40 | Primitive* p=pn->createPrimitive(); |
| 41 | p->setType(type); |
| 42 | p->setSanitized(false); |
| 43 | pn->setChildren(ctx.getInputNodes()); |
| 44 | |
| 45 | if(!pointsVec) |
| 46 | return pn; |
| 47 | |
| 48 | const QList<Value*> points=pointsVec->getElements(); |
| 49 | if(points.isEmpty()) |
| 50 | return pn; |
| 51 | |
| 52 | int count=0; |
| 53 | for(Value* point: points) { |
| 54 | auto* pointVec=dynamic_cast<VectorValue*>(point); |
| 55 | if(!pointVec) continue; |
| 56 | Point pt = pointVec->getPoint(); |
| 57 | p->createVertex(pt); |
| 58 | ++count; |
| 59 | } |
| 60 | |
| 61 | /* If we are just given a single argument of points |
| 62 | * build a polygon from that. */ |
| 63 | if(!linesVec) { |
| 64 | Polygon& pg=p->createPolygon(); |
| 65 | for(auto i=0; i<count; ++i) |
| 66 | pg.append(i); |
| 67 | return pn; |
| 68 | } |
| 69 | |
| 70 | /* Otherwise use the lines argument to describe the multiple |
| 71 | * polygons */ |
| 72 | QList<Value*> lines=linesVec->getElements(); |
| 73 | |
| 74 | //This is to remove the need for duplicate vector syntax in the lines argument |
| 75 | // e.g. lines=[[0,1,2,3]] can just be writtern as lines=[0,1,2,3] |
| 76 | if(!lines.isEmpty()) { |
| 77 | auto* single=dynamic_cast<VectorValue*>(lines.at(0)); |
| 78 | if(!single) { |
| 79 | lines.clear(); |
| 80 | lines.append(linesVec); |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | for(Value* line: qAsConst(lines)) { |
| 85 | auto* lineVec=dynamic_cast<VectorValue*>(line); |
| 86 | if(!lineVec) continue; |
| 87 | Polygon& pg=p->createPolygon(); |
| 88 | for(Value* indexVal: lineVec->getElements()) { |
| 89 | auto* indexNum=dynamic_cast<NumberValue*>(indexVal); |
| 90 | if(!indexNum) continue; |
| 91 | int index = indexNum->toInteger(); |
nothing calls this directly
no test coverage detected