Create an encoder for the {@link ITetrahedralChirality} element.

@param tc          stereo element from an atom container
@param atomToIndex map of atoms to indices
@return a new geometry encoder
420449
private static GeometryEncoder encoder(ITetrahedralChirality tc, Map<IAtom, Integer> atomToIndex) {

        IAtom[] ligands = tc.getLigands();

        int centre = atomToIndex.get(tc.getChiralAtom());
        int[] indices = new int[4];

        int offset = -1;

        for (int i = 0; i < ligands.length; i++) {
            indices[i] = atomToIndex.get(ligands[i]);
            if (indices[i] == centre) offset = i;
        }

        // convert clockwise/anticlockwise to -1/+1
        int parity = tc.getStereo() == CLOCKWISE ? -1 : 1;

        // now if any atom is the centre (indicating an implicit
        // hydrogen) we need to adjust the indicies and the parity
        if (offset >= 0) {

            // remove the 'implicit' central from the first 3 vertices
            for (int i = offset; i < indices.length - 1; i++) {
                indices[i] = indices[i + 1];
            }

            // we now take how many vertices we moved which is
            // 3 (last index) minus the index where we started. if the
            // value is odd we invert the parity (odd number of
            // inversions)
            if (Integer.lowestOneBit(3 - offset) == 0x1) parity *= -1;

            // trim the array to size we don't include the last (implicit)
            // vertex when checking the invariants
            indices = Arrays.copyOf(indices, indices.length - 1);
        }

        return new GeometryEncoder(centre, new BasicPermutationParity(indices), GeometricParity.valueOf(parity));
    }
262512
function(feature) {
        var geometry = feature.geometry;
            geometry = geometry.clone();
        if (this.internalProjection && this.externalProjection) {
            geometry.transform(this.internalProjection, 
                               this.externalProjection);
        }
        if (geometry.CLASS_NAME == "OpenLayers.Geometry.Point") {
            var wpt = this.buildWptNode(geometry);
            this.appendAttributesNode(wpt, feature);
            return wpt;
        } else {
            var trkNode = this.createElementNS(this.namespaces.gpx, "trk");
            this.appendAttributesNode(trkNode, feature);
            var trkSegNodes = this.buildTrkSegNode(geometry);
            trkSegNodes = OpenLayers.Util.isArray(trkSegNodes) ?
                trkSegNodes : [trkSegNodes];
            for (var i = 0, len = trkSegNodes.length; i < len; i++) {
                trkNode.appendChild(trkSegNodes[i]);
            }
            return trkNode;
        }
    }
599877
private static void addExtendedTetrahedralConfiguration(ExtendedTetrahedral et, GraphBuilder gb,
            Map<IAtom, Integer> indices) {

        IAtom[] ligands = et.peripherals();

        int u = indices.get(et.focus());
        int vs[] = new int[]{indices.get(ligands[0]), indices.get(ligands[1]), indices.get(ligands[2]),
                indices.get(ligands[3])};

        gb.extendedTetrahedral(u).lookingFrom(vs[0]).neighbors(vs[1], vs[2], vs[3])
                .winding(et.winding() == CLOCKWISE ? Configuration.CLOCKWISE : Configuration.ANTI_CLOCKWISE).build();
    }
536987
public static Titan1Vertex createVertex(Titan1Graph graph, Vertex source) {

        if (source == null) {
            return null;
        }
        return new Titan1Vertex(graph, source);
    }
217267
private static RTreeIndexCoreExtension getRTreeIndexExtension(
			GeoPackageCore geoPackage) {
		return new RTreeIndexCoreExtension(geoPackage) {
			@Override
			public void createMinYFunction() {
			}

			@Override
			public void createMinXFunction() {
			}

			@Override
			public void createMaxYFunction() {
			}

			@Override
			public void createMaxXFunction() {
			}

			@Override
			public void createIsEmptyFunction() {
			}
		};
	}
56528
public static Model molecule2Model(IAtomContainer molecule) {
        Model model = createCDKModel();
        Resource subject = model.createResource(createIdentifier(model, molecule));
        model.add(subject, RDF.type, CDK.MOLECULE);
        Map<IAtom, Resource> cdkToRDFAtomMap = new HashMap<IAtom, Resource>();
        for (IAtom atom : molecule.atoms()) {
            Resource rdfAtom = model.createResource(createIdentifier(model, atom));
            cdkToRDFAtomMap.put(atom, rdfAtom);
            model.add(subject, CDK.HASATOM, rdfAtom);
            if (atom instanceof IPseudoAtom) {
                model.add(rdfAtom, RDF.type, CDK.PSEUDOATOM);
                serializePseudoAtomFields(model, rdfAtom, (IPseudoAtom) atom);
            } else {
                model.add(rdfAtom, RDF.type, CDK.ATOM);
                serializeAtomFields(model, rdfAtom, atom);
            }
        }
        for (IBond bond : molecule.bonds()) {
            Resource rdfBond = model.createResource(createIdentifier(model, bond));
            model.add(rdfBond, RDF.type, CDK.BOND);
            for (IAtom atom : bond.atoms()) {
                model.add(rdfBond, CDK.BINDSATOM, cdkToRDFAtomMap.get(atom));
            }
            if (bond.getOrder() != null) {
                model.add(rdfBond, CDK.HASORDER, order2Resource(bond.getOrder()));
            }
            model.add(subject, CDK.HASBOND, rdfBond);
            serializeElectronContainerFields(model, rdfBond, bond);
        }
        return model;
    }
71403
@Pure
	public static ShapeElementType toESRI(Class<? extends MapElement> type) {
		if (MapPolyline.class.isAssignableFrom(type)) {
			return ShapeElementType.POLYLINE;
		}
		if (MapPolygon.class.isAssignableFrom(type)) {
			return ShapeElementType.POLYGON;
		}
		if (MapMultiPoint.class.isAssignableFrom(type)) {
			return ShapeElementType.MULTIPOINT;
		}
		if (MapPoint.class.isAssignableFrom(type)) {
			return ShapeElementType.POINT;
		}
		throw new IllegalArgumentException();
	}
743555
private void generateInchiFromCDKAtomContainer(IAtomContainer atomContainer, boolean ignore) throws CDKException {
        this.atomContainer = atomContainer;

        Iterator<IAtom> atoms = atomContainer.atoms().iterator();

        // Check for 3d coordinates
        boolean all3d = true;
        boolean all2d = true;
        while (atoms.hasNext()) {
            IAtom atom = (IAtom) atoms.next();
            if (atom.getPoint3d() == null) {
                all3d = false;
            }
            if (atom.getPoint2d() == null) {
                all2d = false;
            }
        }

        Map<IAtom, JniInchiAtom> atomMap = new HashMap<IAtom, JniInchiAtom>();
        atoms = atomContainer.atoms().iterator();
        while (atoms.hasNext()) {
            IAtom atom = atoms.next();

            // Get coordinates
            // Use 3d if possible, otherwise 2d or none
            double x, y, z;
            if (all3d) {
                Point3d p = atom.getPoint3d();
                x = p.x;
                y = p.y;
                z = p.z;
            } else if (all2d) {
                Point2d p = atom.getPoint2d();
                x = p.x;
                y = p.y;
                z = 0.0;
            } else {
                x = 0.0;
                y = 0.0;
                z = 0.0;
            }

            // Chemical element symbol
            String el = atom.getSymbol();

            // Generate InChI atom
            JniInchiAtom iatom = input.addAtom(new JniInchiAtom(x, y, z, el));
            atomMap.put(atom, iatom);

            // Check if charged
            int charge = atom.getFormalCharge();
            if (charge != 0) {
                iatom.setCharge(charge);
            }

            // Check whether isotopic
            Integer isotopeNumber = atom.getMassNumber();
            if (isotopeNumber != null) {
                iatom.setIsotopicMass(isotopeNumber);
            }

            // Check for implicit hydrogens
            // atom.getHydrogenCount() returns number of implict hydrogens, not
            // total number
            // Ref: Posting to cdk-devel list by Egon Willighagen 2005-09-17
            Integer implicitH = atom.getImplicitHydrogenCount();

            // set implicit hydrogen count, -1 tells the inchi to determine it
            iatom.setImplicitH(implicitH != null ? implicitH : -1);

            // Check if radical
            int count = atomContainer.getConnectedSingleElectronsCount(atom);
            if (count == 0) {
                // TODO - how to check whether singlet or undefined multiplicity
            } else if (count == 1) {
                iatom.setRadical(INCHI_RADICAL.DOUBLET);
            } else if (count == 2) {
                iatom.setRadical(INCHI_RADICAL.TRIPLET);
            } else {
                throw new CDKException("Unrecognised radical type");
            }
        }

        // Process bonds
        for (IBond bond : atomContainer.bonds()) {
            // Assumes 2 centre bond
            JniInchiAtom at0 = (JniInchiAtom) atomMap.get(bond.getBegin());
            JniInchiAtom at1 = (JniInchiAtom) atomMap.get(bond.getEnd());

            // Get bond order
            INCHI_BOND_TYPE order;
            Order           bo = bond.getOrder();
            if (!ignore && bond.getFlag(CDKConstants.ISAROMATIC)) {
                order = INCHI_BOND_TYPE.ALTERN;
            } else if (bo == Order.SINGLE) {
                order = INCHI_BOND_TYPE.SINGLE;
            } else if (bo == Order.DOUBLE) {
                order = INCHI_BOND_TYPE.DOUBLE;
            } else if (bo == Order.TRIPLE) {
                order = INCHI_BOND_TYPE.TRIPLE;
            } else {
                throw new CDKException("Failed to generate InChI: Unsupported bond type");
            }

            // Create InChI bond
            JniInchiBond ibond = new JniInchiBond(at0, at1, order);
            input.addBond(ibond);

            // Check for bond stereo definitions
            IBond.Stereo stereo = bond.getStereo();
            // No stereo definition
            if (stereo == IBond.Stereo.NONE) {
                ibond.setStereoDefinition(INCHI_BOND_STEREO.NONE);
            }
            // Bond ending (fat end of wedge) below the plane
            else if (stereo == IBond.Stereo.DOWN) {
                ibond.setStereoDefinition(INCHI_BOND_STEREO.SINGLE_1DOWN);
            }
            // Bond ending (fat end of wedge) above the plane
            else if (stereo == IBond.Stereo.UP) {
                ibond.setStereoDefinition(INCHI_BOND_STEREO.SINGLE_1UP);
            }
            // Bond starting (pointy end of wedge) below the plane
            else if (stereo == IBond.Stereo.DOWN_INVERTED) {
                ibond.setStereoDefinition(INCHI_BOND_STEREO.SINGLE_2DOWN);
            }
            // Bond starting (pointy end of wedge) above the plane
            else if (stereo == IBond.Stereo.UP_INVERTED) {
                ibond.setStereoDefinition(INCHI_BOND_STEREO.SINGLE_2UP);
            } else if (stereo == IBond.Stereo.E_OR_Z) {
                ibond.setStereoDefinition(INCHI_BOND_STEREO.DOUBLE_EITHER);
            } else if (stereo == IBond.Stereo.UP_OR_DOWN) {
                ibond.setStereoDefinition(INCHI_BOND_STEREO.SINGLE_1EITHER);
            } else if (stereo == IBond.Stereo.UP_OR_DOWN_INVERTED) {
                ibond.setStereoDefinition(INCHI_BOND_STEREO.SINGLE_2EITHER);
            }
            // Bond with undefined stereochemistry
            else if (stereo == CDKConstants.UNSET) {
                if (order == INCHI_BOND_TYPE.SINGLE) {
                    ibond.setStereoDefinition(INCHI_BOND_STEREO.SINGLE_1EITHER);
                } else if (order == INCHI_BOND_TYPE.DOUBLE) {
                    ibond.setStereoDefinition(INCHI_BOND_STEREO.DOUBLE_EITHER);
                }
            }
        }

        // Process tetrahedral stereo elements
        for (IStereoElement stereoElem : atomContainer.stereoElements()) {
            if (stereoElem instanceof ITetrahedralChirality) {
                ITetrahedralChirality chirality = (ITetrahedralChirality) stereoElem;
                IAtom[] surroundingAtoms = chirality.getLigands();
                Stereo stereoType = chirality.getStereo();

                JniInchiAtom atC = (JniInchiAtom) atomMap.get(chirality.getChiralAtom());
                JniInchiAtom at0 = (JniInchiAtom) atomMap.get(surroundingAtoms[0]);
                JniInchiAtom at1 = (JniInchiAtom) atomMap.get(surroundingAtoms[1]);
                JniInchiAtom at2 = (JniInchiAtom) atomMap.get(surroundingAtoms[2]);
                JniInchiAtom at3 = (JniInchiAtom) atomMap.get(surroundingAtoms[3]);
                INCHI_PARITY p = INCHI_PARITY.UNKNOWN;
                if (stereoType == Stereo.ANTI_CLOCKWISE) {
                    p = INCHI_PARITY.ODD;
                } else if (stereoType == Stereo.CLOCKWISE) {
                    p = INCHI_PARITY.EVEN;
                } else {
                    throw new CDKException("Unknown tetrahedral chirality");
                }

                JniInchiStereo0D jniStereo = new JniInchiStereo0D(atC, at0, at1, at2, at3,
                        INCHI_STEREOTYPE.TETRAHEDRAL, p);
                input.addStereo0D(jniStereo);
            } else if (stereoElem instanceof IDoubleBondStereochemistry) {
                IDoubleBondStereochemistry dbStereo = (IDoubleBondStereochemistry) stereoElem;
                IBond[] surroundingBonds = dbStereo.getBonds();
                if (surroundingBonds[0] == null || surroundingBonds[1] == null)
                    throw new CDKException("Cannot generate an InChI with incomplete double bond info");
                org.openscience.cdk.interfaces.IDoubleBondStereochemistry.Conformation stereoType = dbStereo
                        .getStereo();

                IBond stereoBond = dbStereo.getStereoBond();
                JniInchiAtom at0 = null;
                JniInchiAtom at1 = null;
                JniInchiAtom at2 = null;
                JniInchiAtom at3 = null;
                // TODO: I should check for two atom bonds... or maybe that should happen when you
                //    create a double bond stereochemistry
                if (stereoBond.contains(surroundingBonds[0].getBegin())) {
                    // first atom is A
                    at1 = (JniInchiAtom) atomMap.get(surroundingBonds[0].getBegin());
                    at0 = (JniInchiAtom) atomMap.get(surroundingBonds[0].getEnd());
                } else {
                    // first atom is X
                    at0 = (JniInchiAtom) atomMap.get(surroundingBonds[0].getBegin());
                    at1 = (JniInchiAtom) atomMap.get(surroundingBonds[0].getEnd());
                }
                if (stereoBond.contains(surroundingBonds[1].getBegin())) {
                    // first atom is B
                    at2 = (JniInchiAtom) atomMap.get(surroundingBonds[1].getBegin());
                    at3 = (JniInchiAtom) atomMap.get(surroundingBonds[1].getEnd());
                } else {
                    // first atom is Y
                    at2 = (JniInchiAtom) atomMap.get(surroundingBonds[1].getEnd());
                    at3 = (JniInchiAtom) atomMap.get(surroundingBonds[1].getBegin());
                }
                INCHI_PARITY p = INCHI_PARITY.UNKNOWN;
                if (stereoType == org.openscience.cdk.interfaces.IDoubleBondStereochemistry.Conformation.TOGETHER) {
                    p = INCHI_PARITY.ODD;
                } else if (stereoType == org.openscience.cdk.interfaces.IDoubleBondStereochemistry.Conformation.OPPOSITE) {
                    p = INCHI_PARITY.EVEN;
                } else {
                    throw new CDKException("Unknown double bond stereochemistry");
                }

                JniInchiStereo0D jniStereo = new JniInchiStereo0D(null, at0, at1, at2, at3,
                        INCHI_STEREOTYPE.DOUBLEBOND, p);
                input.addStereo0D(jniStereo);
            } else if (stereoElem instanceof ExtendedTetrahedral) {

                ExtendedTetrahedral extendedTetrahedral = (ExtendedTetrahedral) stereoElem;
                Stereo winding = extendedTetrahedral.winding();

                // The periphals (p<i>) and terminals (t<i>) are refering to
                // the following atoms. The focus (f) is also shown.
                //
                //   p0          p2
                //    \          /
                //     t0 = f = t1
                //    /         \
                //   p1         p3
                IAtom[] terminals = extendedTetrahedral.findTerminalAtoms(atomContainer);
                IAtom[] peripherals = extendedTetrahedral.peripherals();

                // InChI API is particualar about the input, each terminal atom
                // needs to be present in the list of neighbors and they must
                // be at index 1 and 2 (i.e. in the middle). This is true even
                // of explict atoms. For the implicit atoms, the terminals may
                // be in the peripherals allready and so we correct the winding
                // and reposition as needed.

                List<IBond> t0Bonds = onlySingleBonded(atomContainer.getConnectedBondsList(terminals[0]));
                List<IBond> t1Bonds = onlySingleBonded(atomContainer.getConnectedBondsList(terminals[1]));

                // first if there are two explicit atoms we need to replace one
                // with the terminal atom - the configuration does not change
                if (t0Bonds.size() == 2) {
                    IAtom replace = t0Bonds.remove(0).getOther(terminals[0]);
                    for (int i = 0; i < peripherals.length; i++)
                        if (replace == peripherals[i]) peripherals[i] = terminals[0];
                }

                if (t1Bonds.size() == 2) {
                    IAtom replace = t1Bonds.remove(0).getOther(terminals[1]);
                    for (int i = 0; i < peripherals.length; i++)
                        if (replace == peripherals[i]) peripherals[i] = terminals[1];
                }

                // the neighbor attached to each terminal atom that we will
                // define the configuration of
                IAtom t0Neighbor = t0Bonds.get(0).getOther(terminals[0]);
                IAtom t1Neighbor = t1Bonds.get(0).getOther(terminals[1]);

                // we now need to move all the atoms into the correct positions
                // everytime we exchange atoms the configuration inverts
                for (int i = 0; i < peripherals.length; i++) {
                    if (i != 0 && t0Neighbor.equals(peripherals[i])) {
                        swap(peripherals, i, 0);
                        winding = winding.invert();
                    } else if (i != 1 && terminals[0].equals(peripherals[i])) {
                        swap(peripherals, i, 1);
                        winding = winding.invert();
                    } else if (i != 2 && terminals[1].equals(peripherals[i])) {
                        swap(peripherals, i, 2);
                        winding = winding.invert();
                    } else if (i != 3 && t1Neighbor.equals(peripherals[i])) {
                        swap(peripherals, i, 3);
                        winding = winding.invert();
                    }
                }

                INCHI_PARITY parity = INCHI_PARITY.UNKNOWN;
                if (winding == Stereo.ANTI_CLOCKWISE)
                    parity = INCHI_PARITY.ODD;
                else if (winding == Stereo.CLOCKWISE)
                    parity = INCHI_PARITY.EVEN;
                else
                    throw new CDKException("Unknown extended tetrahedral chirality");

                JniInchiStereo0D jniStereo = new JniInchiStereo0D(atomMap.get(extendedTetrahedral.focus()),
                        atomMap.get(peripherals[0]), atomMap.get(peripherals[1]), atomMap.get(peripherals[2]),
                        atomMap.get(peripherals[3]), INCHI_STEREOTYPE.ALLENE, parity);
                input.addStereo0D(jniStereo);
            }
        }

        try {
            output = JniInchiWrapper.getInchi(input);
        } catch (JniInchiException jie) {
            throw new CDKException("Failed to generate InChI: " + jie.getMessage(), jie);
        }
    }
297489
private Collection<CQIE> rewriteCC(QueryConnectedComponent cc, Function headAtom,  Multimap<Predicate, CQIE> edgeDP) {
		
		List<CQIE> outputRules = new LinkedList<>();	

		TreeWitnessSet tws = TreeWitnessSet.getTreeWitnesses(cc, reasoner, generators, immutabilityTools);

		if (cc.hasNoFreeTerms()) {  
			if (!cc.isDegenerate() || cc.getLoop() != null) 
				for (Function a : getAtomsForGenerators(tws.getGeneratorsOfDetachedCC(), getFreshVariable())) {
					outputRules.add(datalogFactory.getCQIE(headAtom, a));
				}
		}

		// COMPUTE AND STORE TREE WITNESS FORMULAS
		for (TreeWitness tw : tws.getTWs()) {
			log.debug("TREE WITNESS: {}", tw);		
			List<Function> twf = new LinkedList<>();
			
			// equality atoms
			Iterator<Term> i = tw.getRoots().iterator();
			Term r0 = i.next();
			while (i.hasNext()) 
				twf.add(termFactory.getFunctionEQ(i.next(), r0));
			
			// root atoms
			for (Function a : tw.getRootAtoms()) {
				if (!(a.getFunctionSymbol() instanceof TriplePredicate))
					throw new MinorOntopInternalBugException("A triple atom was expected: " + a);

				boolean isClass = ((TriplePredicate) a.getFunctionSymbol()).getClassIRI(
						a.getTerms().stream()
								.map(immutabilityTools::convertIntoImmutableTerm)
								.collect(ImmutableCollectors.toList()))
						.isPresent();

				twf.add(isClass
						? atomFactory.getMutableTripleAtom(r0, a.getTerm(1), a.getTerm(2))
						: atomFactory.getMutableTripleAtom(r0, a.getTerm(1), r0));
			}
			
			List<Function> genAtoms = getAtomsForGenerators(tw.getGenerators(), r0);			
			boolean subsumes = false;
//			for (Function a : genAtoms) 				
//				if (twf.subsumes(a)) {
//					subsumes = true;
//					log.debug("TWF {} SUBSUMES {}", twf.getAllAtoms(), a);
//					break;
//				}

			List<List<Function>> twfs = new ArrayList<>(subsumes ? 1 : genAtoms.size());
//			if (!subsumes) {
				for (Function a : genAtoms) {				
					LinkedList<Function> twfa = new LinkedList<>(twf);
					twfa.add(a); // 
					twfs.add(twfa);
				}
//			}
//			else
//				twfs.add(twf.getAllAtoms());
			
			tw.setFormula(twfs);
		}

		final String headURI = headAtom.getFunctionSymbol().getName();
		if (!cc.isDegenerate()) {
			if (tws.hasConflicts()) { 
				// there are conflicting tree witnesses
				// use compact exponential rewriting by enumerating all compatible subsets of tree witnesses
				CompatibleTreeWitnessSetIterator iterator = tws.getIterator();
				while (iterator.hasNext()) {
					Collection<TreeWitness> compatibleTWs = iterator.next();
					log.debug("COMPATIBLE: {}", compatibleTWs);
					LinkedList<Function> mainbody = new LinkedList<Function>(); 
					
					for (Edge edge : cc.getEdges()) {
						boolean contained = false;
						for (TreeWitness tw : compatibleTWs)
							if (tw.getDomain().contains(edge.getTerm0()) && tw.getDomain().contains(edge.getTerm1())) {
								contained = true;
								log.debug("EDGE {} COVERED BY {}", edge, tw);
								break;
							}
						if (!contained) {
							log.debug("EDGE {} NOT COVERED BY ANY TW",  edge);
							mainbody.addAll(edge.getAtoms());
						}
					}
					for (TreeWitness tw : compatibleTWs) {
						Function twAtom = getHeadAtom(headURI, "_TW_" + (edgeDP.size() + 1), cc.getVariables());
						mainbody.add(twAtom);				
						for (List<Function> twfa : tw.getFormula())
							edgeDP.put(twAtom.getFunctionSymbol(), datalogFactory.getCQIE(twAtom, twfa));
					}	
					mainbody.addAll(cc.getNonDLAtoms());					
					outputRules.add(datalogFactory.getCQIE(headAtom, mainbody));
				}
			}
			else {
				// no conflicting tree witnesses
				// use polynomial tree witness rewriting by treating each edge independently 
				LinkedList<Function> mainbody = new LinkedList<>();
				for (Edge edge : cc.getEdges()) {
					log.debug("EDGE {}", edge);
					
					Function edgeAtom = null;
					for (TreeWitness tw : tws.getTWs())
						if (tw.getDomain().contains(edge.getTerm0()) && tw.getDomain().contains(edge.getTerm1())) {
							if (edgeAtom == null) {
								//IRI atomURI = edge.getBAtoms().iterator().next().getIRI().getName();
								edgeAtom = getHeadAtom(headURI, 
										"_EDGE_" + (edgeDP.size() + 1) /*+ "_" + atomURI.getRawFragment()*/, cc.getVariables());
								mainbody.add(edgeAtom);				
								
								LinkedList<Function> edgeAtoms = new LinkedList<>();
								edgeAtoms.addAll(edge.getAtoms());
								edgeDP.put(edgeAtom.getFunctionSymbol(), datalogFactory.getCQIE(edgeAtom, edgeAtoms));
							}
							
							for (List<Function> twfa : tw.getFormula())
								edgeDP.put(edgeAtom.getFunctionSymbol(), datalogFactory.getCQIE(edgeAtom, twfa));
						}
					
					if (edgeAtom == null) // no tree witnesses -- direct insertion into the main body
						mainbody.addAll(edge.getAtoms());
				}
				mainbody.addAll(cc.getNonDLAtoms());
				outputRules.add(datalogFactory.getCQIE(headAtom, mainbody));
			}
		}
		else {
			// degenerate connected component
			LinkedList<Function> loopbody = new LinkedList<>();
			Loop loop = cc.getLoop();
			log.debug("LOOP {}", loop);
			if (loop != null)
				loopbody.addAll(loop.getAtoms());
			loopbody.addAll(cc.getNonDLAtoms());
			outputRules.add(datalogFactory.getCQIE(headAtom, loopbody));
		}
		return outputRules;
	}
3564
public Coordinate viewToPan(Coordinate coordinate) {
		if (coordinate != null) {
			Vector2D position = new Vector2D(coordinate);
			double scale = mapView.getCurrentScale();
			Coordinate panOrigin = mapView.getPanOrigin();
			
			double translateX = (mapView.getViewState().getX() - panOrigin.getX()) * scale - (mapView.getWidth() / 2);
			double translateY = -(mapView.getViewState().getY() - panOrigin.getY()) * scale - (mapView.getHeight() / 2);
			position.translate(translateX , translateY);
				// TODO: implement rotation support.
			return new Coordinate(position.getX(), position.getY());
		}
		return null;
	}
880562
public void prepareTriangulation( TriangulationContext<?> tcx )
    {
        int hint = _points.size();
        if(_steinerPoints != null) {
            hint += _steinerPoints.size();
        }
        if( _holes != null ) {
            for (Polygon p : _holes) {
                hint += p.pointCount();
            }
        }
        HashMap<TriangulationPoint, TriangulationPoint> uniquePts = new HashMap<TriangulationPoint, TriangulationPoint>(hint);
        TriangulationPoint.mergeInstances(uniquePts, _points);
        if(_steinerPoints != null) {
            TriangulationPoint.mergeInstances(uniquePts, _steinerPoints);
        }
        if( _holes != null ) {
            for (Polygon p : _holes) {
                TriangulationPoint.mergeInstances(uniquePts, p._points);
            }
        }
        if( m_triangles == null )
        {
            m_triangles = new ArrayList<DelaunayTriangle>( _points.size() );
        }
        else
        {
            m_triangles.clear();
        }

        // Outer constraints
        for( int i = 0; i < _points.size()-1 ; i++ )
        {
            tcx.newConstraint( _points.get( i ), _points.get( i+1 ) );
        }
        tcx.newConstraint( _points.get( 0 ), _points.get( _points.size()-1 ) );

        // Hole constraints
        if( _holes != null )
        {
            for( Polygon p : _holes )
            {
                for( int i = 0; i < p._points.size()-1 ; i++ )
                {
                    tcx.newConstraint( p._points.get( i ), p._points.get( i+1 ) );
                }
                tcx.newConstraint( p._points.get( 0 ), p._points.get( p._points.size()-1 ) );            
            }
        }
        tcx.addPoints(uniquePts.keySet());
    }
815733
private long getIndex(T x, T y) {
        int i = elementIndices.index(x);
        int j = elementIndices.index(y);
        long index = (((long)i) << 32) | j;
        return index;
    }
637141
public static GeometryIndex getLinearRingIndex(Geometry geometry, Coordinate c) {
		if (Geometry.LINEAR_RING.equals(geometry.getGeometryType())) {
			IndexedLinearRing ring = helper.createLinearRing(geometry);
			if (ring.containsCoordinate(c)) {
				return ring.getIndex();
			}
		} else if (Geometry.POLYGON.equals(geometry.getGeometryType())) {
			IndexedPolygon polygon = helper.createPolygon(geometry);
			for (IndexedLinearRing hole : polygon.getHoles()) {
				if (hole.containsCoordinate(c)) {
					return hole.getIndex();
				}
			}
			if (polygon.getShell().containsCoordinate(c)) {
				return polygon.getShell().getIndex();
			}
		} else if (Geometry.MULTI_POLYGON.equals(geometry.getGeometryType())) {
			IndexedMultiPolygon multipolygon = helper.createMultiPolygon(geometry);
			for (IndexedPolygon polygon : multipolygon.getPolygons()) {
				for (IndexedLinearRing hole : polygon.getHoles()) {
					if (hole.containsCoordinate(c)) {
						return hole.getIndex();
					}
				}
				if (polygon.getShell().containsCoordinate(c)) {
					return polygon.getShell().getIndex();
				}
			}
		}
		return null;
	}
1309162
public <T extends ICalComponent> T getComponent(Class<T> clazz) {
		return clazz.cast(components.first(clazz));
	}
358434
private String encodeAtomExpr(int atmIdx) {
        final IAtom atom = mol.getAtom(atmIdx);

        boolean complex = mode == MODE_EXACT;

        StringBuilder sb = new StringBuilder();

        switch (atom.getAtomicNumber()) {
            case 0:  // *
                sb.append('*');
                break;
            case 5:  // B
            case 6:  // C
            case 7:  // N
            case 8:  // O
            case 15: // P
            case 16: // S
            case 9:  // F
            case 17: // Cl
            case 35: // Br
            case 53: // I
                sb.append(atom.isAromatic() ? atom.getSymbol().toLowerCase(Locale.ROOT)
                                            : atom.getSymbol());
                break;
            default:
                complex = true;
                sb.append(atom.isAromatic() ? atom.getSymbol().toLowerCase(Locale.ROOT)
                                            : atom.getSymbol());
                break;
        }

        if (mode == MODE_EXACT) {

            int hcount = atom.getImplicitHydrogenCount();
            int valence = hcount;
            int connections = hcount;

            int atmDeg = this.deg[atmIdx];
            for (int i = 0; i < atmDeg; i++) {
                IBond bond = mol.getBond(bondAdj[atmIdx][i]);
                IAtom nbr = bond.getOther(atom);
                if (nbr.getAtomicNumber() != null && nbr.getAtomicNumber() == 1)
                    hcount++;
                int bord = bond.getOrder() != null ? bond.getOrder().numeric() : 0;
                if (bord == 0)
                    throw new IllegalArgumentException("Molecule had unsupported zero-order or unset bonds!");
                valence += bord;
                connections++;
            }

            sb.append('H').append(hcount);
            sb.append('v').append(valence);
            sb.append('X').append(connections);
        }

        Integer chg = atom.getFormalCharge();
        if (chg == null) chg = 0;


        if (chg <= -1 || chg >= +1) {
            if (chg >= 0) sb.append('+');
            else sb.append('-');
            int abs = Math.abs(chg);
            if (abs > 1) sb.append(abs);
            complex = true;
        } else if (mode == MODE_EXACT) {
            sb.append("+0");
        }

        return complex ? '[' + sb.toString() + ']' : sb.toString();
    }
93372
public SimpleOrderedMap<Object> create(ComponentFacet facet, Boolean encode)
      throws IOException {
    SimpleOrderedMap<Object> mtasFacetResponse = new SimpleOrderedMap<>();
    mtasFacetResponse.add("key", facet.key);
    HashMap<MtasDataCollector<?, ?>, HashMap<String, MtasSolrMtasResult>> functionData = new HashMap<>();
    for (int i = 0; i < facet.baseFields.length; i++) {
      if (facet.baseFunctionList[i] != null) {
        for (MtasDataCollector<?, ?> functionDataCollector : facet.baseFunctionList[i]
            .keySet()) {
          SubComponentFunction[] tmpSubComponentFunctionList = facet.baseFunctionList[i]
              .get(functionDataCollector);
          if (tmpSubComponentFunctionList != null) {
            HashMap<String, MtasSolrMtasResult> tmpList = new HashMap<>();
            for (SubComponentFunction tmpSubComponentFunction : tmpSubComponentFunctionList) {
              tmpList.put(tmpSubComponentFunction.key,
                  new MtasSolrMtasResult(tmpSubComponentFunction.dataCollector,
                      tmpSubComponentFunction.dataType,
                      tmpSubComponentFunction.statsType,
                      tmpSubComponentFunction.statsItems, null, null));
            }
            functionData.put(functionDataCollector, tmpList);
          }
        }
      }
    }
    MtasSolrMtasResult data = new MtasSolrMtasResult(facet.dataCollector,
        facet.baseDataTypes, facet.baseStatsTypes, facet.baseStatsItems, null,
        facet.baseSortTypes, facet.baseSortDirections, null, facet.baseNumbers,
        functionData);

    if (encode) {
      mtasFacetResponse.add("_encoded_list", MtasSolrResultUtil.encode(data));
    } else {
      mtasFacetResponse.add("list", data);
      MtasSolrResultUtil.rewrite(mtasFacetResponse, searchComponent);
    }
    return mtasFacetResponse;
  }
1150714
public <TCoder extends BinaryEncoder & BinaryDecoder> CodecCipher setCoder(TCoder coder)
    {
        this.encoder = coder;
        this.decoder = coder;

        return this;
    }