183 {
184
185 if (sh1->typeID() != sh2->typeID())
186 return false;
187
188 if (sh1->type() == "Pgon") {
189 const GeoPgon* pgon1 = static_cast<const GeoPgon*>(sh1);
190 const GeoPgon* pgon2 = static_cast<const GeoPgon*>(sh2);
191 if (!pgon1 || !pgon2)
192 return false;
193
194 if (pgon1->getNPlanes() != pgon2->getNPlanes())
195 return false;
196 if (pgon1->getNSides() != pgon2->getNSides())
197 return false;
198 if (std::abs(pgon1->getSPhi() - pgon2->getSPhi()) > tol)
199 return false;
200 if (std::abs(pgon1->getDPhi() - pgon2->getDPhi()) > tol)
201 return false;
202
203 return true;
204
205 } else if (sh1->type() == "Trd") {
206 const GeoTrd* trd1 = static_cast<const GeoTrd*>(sh1);
207 const GeoTrd* trd2 = static_cast<const GeoTrd*>(sh2);
208
209 if (std::abs(trd1->getXHalfLength1() - trd2->getXHalfLength1()) > tol)
210 return false;
211 if (std::abs(trd1->getXHalfLength2() - trd2->getXHalfLength2()) > tol)
212 return false;
213 if (std::abs(trd1->getYHalfLength1() - trd2->getYHalfLength1()) > tol)
214 return false;
215 if (std::abs(trd1->getYHalfLength2() - trd2->getYHalfLength2()) > tol)
216 return false;
217 if (std::abs(trd1->getZHalfLength() - trd2->getZHalfLength()) > tol)
218 return false;
219
220 return true;
221
222 } else if (sh1->type() == "Box") {
223 const GeoBox* box1 = static_cast<const GeoBox*>(sh1);
224 const GeoBox* box2 = static_cast<const GeoBox*>(sh2);
225
226 if (std::abs(box1->getXHalfLength() - box2->getXHalfLength()) > tol)
227 return false;
228 if (std::abs(box1->getYHalfLength() - box2->getYHalfLength()) > tol)
229 return false;
230 if (std::abs(box1->getZHalfLength() - box2->getZHalfLength()) > tol)
231 return false;
232
233 return true;
234
235 } else if (sh1->type() == "Tube") {
236 const GeoTube* tube1 = static_cast<const GeoTube*>(sh1);
237 const GeoTube* tube2 = static_cast<const GeoTube*>(sh2);
238
239 if (std::abs(tube1->getRMin() - tube2->getRMin()) > tol)
240 return false;
241 if (std::abs(tube1->getRMax() - tube2->getRMax()) > tol)
242 return false;
243 if (std::abs(tube1->getZHalfLength() - tube2->getZHalfLength()) > tol)
244 return false;
245
246 return true;
247
248 } else if (sh1->type() == "Tubs") {
249 const GeoTubs* tubs1 = static_cast<const GeoTubs*>(sh1);
250 const GeoTubs* tubs2 = static_cast<const GeoTubs*>(sh2);
251
252 if (std::abs(tubs1->getRMin() - tubs2->getRMin()) > tol)
253 return false;
254 if (std::abs(tubs1->getRMax() - tubs2->getRMax()) > tol)
255 return false;
256 if (std::abs(tubs1->getZHalfLength() - tubs2->getZHalfLength()) > tol)
257 return false;
258 if (std::abs(tubs1->getSPhi() - tubs2->getSPhi()) > tol)
259 return false;
260 if (std::abs(tubs1->getDPhi() - tubs2->getDPhi()) > tol)
261 return false;
262
263 return true;
264
265 } else if (sh1->type() == "Cons") {
266 const GeoCons* cons1 = static_cast<const GeoCons*>(sh1);
267 const GeoCons* cons2 = static_cast<const GeoCons*>(sh2);
268
269 if (std::abs(cons1->getRMin1() - cons2->getRMin1()) > tol)
270 return false;
271 if (std::abs(cons1->getRMin2() - cons2->getRMin2()) > tol)
272 return false;
273 if (std::abs(cons1->getRMax1() - cons2->getRMax1()) > tol)
274 return false;
275 if (std::abs(cons1->getRMax2() - cons2->getRMax2()) > tol)
276 return false;
277 if (std::abs(cons1->getDZ() - cons2->getDZ()) > tol)
278 return false;
279 if (std::abs(cons1->getSPhi() - cons2->getSPhi()) > tol)
280 return false;
281 if (std::abs(cons1->getDPhi() - cons2->getDPhi()) > tol)
282 return false;
283
284 return true;
285
286 } else if (sh1->type() == "SimplePolygonBrep") {
287 const GeoSimplePolygonBrep* spb1 =
288 static_cast<const GeoSimplePolygonBrep*>(sh1);
289 const GeoSimplePolygonBrep* spb2 =
290 static_cast<const GeoSimplePolygonBrep*>(sh2);
291 if (!spb1 || !spb2)
292 return false;
293
294 unsigned int nv1 = spb1->getNVertices();
295 unsigned int nv2 = spb2->getNVertices();
296 if (nv1 != nv2)
297 return false;
298 if (std::abs(spb1->getDZ() - spb2->getDZ()) > tol)
299 return false;
300
301 for (unsigned int iv = 0; iv < nv1; iv++) {
302
303 if (std::abs(spb1->getXVertex(iv) - spb2->getXVertex(iv)) > tol)
304 return false;
305 if (std::abs(spb1->getYVertex(iv) - spb2->getYVertex(iv)) > tol)
306 return false;
307 }
308
309 return true;
310
311 } else if (sh1->type() == "Pcon") {
312 const GeoPcon* pc1 = static_cast<const GeoPcon*>(sh1);
313 const GeoPcon* pc2 = static_cast<const GeoPcon*>(sh2);
314 if (!pc1 || !pc2)
315 return false;
316
317 if (std::abs(pc1->getSPhi() - pc2->getSPhi()) > tol)
318 return false;
319 if (std::abs(pc1->getDPhi() - pc2->getDPhi()) > tol)
320 return false;
321
322 unsigned int nv1 = pc1->getNPlanes();
323 unsigned int nv2 = pc2->getNPlanes();
324 if (nv1 != nv2)
325 return false;
326
327 for (unsigned int iv = 0; iv < nv1; iv++) {
328
329 if (std::abs(pc1->getZPlane(iv) - pc2->getZPlane(iv)) > tol)
330 return false;
331 if (std::abs(pc1->getRMinPlane(iv) - pc2->getRMinPlane(iv)) > tol)
332 return false;
333 if (std::abs(pc1->getRMaxPlane(iv) - pc2->getRMaxPlane(iv)) > tol)
334 return false;
335 }
336
337 return true;
338
339 } else if (sh1->type() == "Subtraction") {
340 const GeoShapeSubtraction* sub1 =
341 static_cast<const GeoShapeSubtraction*>(sh1);
342 const GeoShapeSubtraction* sub2 =
343 static_cast<const GeoShapeSubtraction*>(sh2);
344
345 if (!sub1 || !sub2)
346 return false;
347
349 return false;
351 return false;
352
353 return true;
354
355 } else if (sh1->type() == "Union") {
356 const GeoShapeUnion* sub1 = static_cast<const GeoShapeUnion*>(sh1);
357 const GeoShapeUnion* sub2 = static_cast<const GeoShapeUnion*>(sh2);
358
359 if (!sub1 || !sub2)
360 return false;
361
363 return false;
365 return false;
366
367 return true;
368
369 } else if (sh1->type() == "Shift") {
370 const GeoShapeShift* shift1 = static_cast<const GeoShapeShift*>(sh1);
371 const GeoShapeShift* shift2 = static_cast<const GeoShapeShift*>(sh2);
372
373 if (!shift1 || !shift2)
374 return false;
375
377 return false;
378
379 const GeoTrf::Transform3D& transf1 = shift1->getX();
380 const GeoTrf::Transform3D& transf2 = shift2->getX();
381
382 if ((transf1.translation() - transf2.translation()).norm() > tol)
383 return false;
384
385
386 if (!
identity_check(transf1.rotation() * transf2.rotation().transpose(),
387 tol))
388 return false;
389
390 return true;
391 }
392
393 std::cout << "unknown shape to compare:" << sh1->type() << std::endl;
394
395 return false;
396}
static bool identity_check(GeoTrf::RotationMatrix3D rotation, double tol)
check of rotation invariance