MCPcopy Create free account
hub / github.com/GilesBathgate/RapCAD / evaluate

Method evaluate

src/module/polygonmodule.cpp:34–99  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

32}
33
34Node* 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();

Callers

nothing calls this directly

Calls 12

getArgumentDeprecatedMethod · 0.80
getInputNodesMethod · 0.80
getPointMethod · 0.80
appendMethod · 0.80
toIntegerMethod · 0.80
createPrimitiveMethod · 0.45
setTypeMethod · 0.45
setSanitizedMethod · 0.45
setChildrenMethod · 0.45
getElementsMethod · 0.45
isEmptyMethod · 0.45
createVertexMethod · 0.45

Tested by

no test coverage detected