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

Method evaluate

src/module/prismmodule.cpp:34–108  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

32}
33
34Node* PrismModule::evaluate(const Context& ctx) const
35{
36 auto* heightVal = dynamic_cast<NumberValue*>(getParameterArgument(ctx,0));
37 decimal h=1.0;
38 if(heightVal)
39 h=heightVal->getNumber();
40
41 int s=3;
42 auto* sidesVal = dynamic_cast<NumberValue*>(getParameterArgument(ctx,1));
43 if(sidesVal)
44 s=sidesVal->toInteger();
45
46 auto* pn=new PrimitiveNode();
47 Primitive* p=pn->createPrimitive();
48 pn->setChildren(ctx.getInputNodes());
49
50 if(h==0.0||s<=0.0)
51 return pn;
52
53 decimal r=1.0;
54 decimal a=1.0;
55 auto* apothemVal = dynamic_cast<NumberValue*>(getParameterArgument(ctx,2));
56 if(apothemVal) {
57 a=apothemVal->getNumber();
58 r=a/r_cos(r_pi()/s);
59 } else {
60 NumberValue* radiusVal = dynamic_cast<NumberValue*>(ctx.getArgument(2,"radius"));
61 if(radiusVal) {
62 r=radiusVal->getNumber();
63 a=r*r_cos(r_pi()/s);
64 }
65 }
66
67 Value* centerVal = getParameterArgument(ctx,3);
68 bool center=false;
69 if(centerVal)
70 center=centerVal->isTrue();
71
72 decimal z1=0.0;
73 decimal z2=h;
74
75 const QList<Point> p1=getPolygon(a,r,s,z1);
76 const QList<Point> p2=getPolygon(a,r,s,z2);
77
78 if(r>0.0) {
79 int n=0;
80 Polygon& pg0=p->createPolygon();
81 for(const auto& pt: p1) {
82 p->createVertex(pt);
83 pg0.append(n++);
84 }
85
86 Polygon& pg1=p->createPolygon();
87 for(const auto& pt: p2) {
88 p->createVertex(pt);
89 pg1.prepend(n++);
90 }
91

Callers

nothing calls this directly

Calls 14

r_cosFunction · 0.85
r_piFunction · 0.85
getNumberMethod · 0.80
toIntegerMethod · 0.80
getInputNodesMethod · 0.80
getArgumentMethod · 0.80
appendMethod · 0.80
prependMethod · 0.80
setCenterVerticalMethod · 0.80
addChildMethod · 0.80
createPrimitiveMethod · 0.45
setChildrenMethod · 0.45

Tested by

no test coverage detected