Commit e0777e74 by Maarten L. Hekkelman

minor updates

parent cf465134
...@@ -686,7 +686,7 @@ class Row ...@@ -686,7 +686,7 @@ class Row
} }
template<typename... Ts, size_t N> template<typename... Ts, size_t N>
std::tuple<Ts...> get(char const * const (&columns)[N]) std::tuple<Ts...> get(char const * const (&columns)[N]) const
{ {
static_assert(sizeof...(Ts) == N, "Number of columns should be equal to number of types to return"); static_assert(sizeof...(Ts) == N, "Number of columns should be equal to number of types to return");
...@@ -1087,7 +1087,7 @@ template<typename T> ...@@ -1087,7 +1087,7 @@ template<typename T>
Condition operator==(const Key& key, const T& v) Condition operator==(const Key& key, const T& v)
{ {
std::ostringstream s; std::ostringstream s;
s << "== " << v; s << " == " << v;
return Condition(new detail::KeyCompareConditionImpl(key.mItemTag, [tag = key.mItemTag, v](const Category& c, const Row& r, bool icase) return Condition(new detail::KeyCompareConditionImpl(key.mItemTag, [tag = key.mItemTag, v](const Category& c, const Row& r, bool icase)
{ return r[tag].template compare<T>(v, icase) == 0; }, s.str())); { return r[tag].template compare<T>(v, icase) == 0; }, s.str()));
...@@ -1123,7 +1123,7 @@ template<typename T> ...@@ -1123,7 +1123,7 @@ template<typename T>
Condition operator>(const Key& key, const T& v) Condition operator>(const Key& key, const T& v)
{ {
std::ostringstream s; std::ostringstream s;
s << ">" << v; s << " > " << v;
return Condition(new detail::KeyCompareConditionImpl(key.mItemTag, [tag = key.mItemTag, v](const Category& c, const Row& r, bool icase) return Condition(new detail::KeyCompareConditionImpl(key.mItemTag, [tag = key.mItemTag, v](const Category& c, const Row& r, bool icase)
{ return r[tag].template compare<T>(v, icase) > 0; }, s.str())); { return r[tag].template compare<T>(v, icase) > 0; }, s.str()));
...@@ -1133,7 +1133,7 @@ template<typename T> ...@@ -1133,7 +1133,7 @@ template<typename T>
Condition operator>=(const Key& key, const T& v) Condition operator>=(const Key& key, const T& v)
{ {
std::ostringstream s; std::ostringstream s;
s << ">=" << v; s << " >= " << v;
return Condition(new detail::KeyCompareConditionImpl(key.mItemTag, [tag = key.mItemTag, v](const Category& c, const Row& r, bool icase) return Condition(new detail::KeyCompareConditionImpl(key.mItemTag, [tag = key.mItemTag, v](const Category& c, const Row& r, bool icase)
{ return r[tag].template compare<T>(v, icase) >= 0; }, s.str())); { return r[tag].template compare<T>(v, icase) >= 0; }, s.str()));
...@@ -1143,7 +1143,7 @@ template<typename T> ...@@ -1143,7 +1143,7 @@ template<typename T>
Condition operator<(const Key& key, const T& v) Condition operator<(const Key& key, const T& v)
{ {
std::ostringstream s; std::ostringstream s;
s << "<" << v; s << " < " << v;
return Condition(new detail::KeyCompareConditionImpl(key.mItemTag, [tag = key.mItemTag, v](const Category& c, const Row& r, bool icase) return Condition(new detail::KeyCompareConditionImpl(key.mItemTag, [tag = key.mItemTag, v](const Category& c, const Row& r, bool icase)
{ return r[tag].template compare<T>(v, icase) < 0; }, s.str())); { return r[tag].template compare<T>(v, icase) < 0; }, s.str()));
...@@ -1153,7 +1153,7 @@ template<typename T> ...@@ -1153,7 +1153,7 @@ template<typename T>
Condition operator<=(const Key& key, const T& v) Condition operator<=(const Key& key, const T& v)
{ {
std::ostringstream s; std::ostringstream s;
s << "<=" << v; s << " <= " << v;
return Condition(new detail::KeyCompareConditionImpl(key.mItemTag, [tag = key.mItemTag, v](const Category& c, const Row& r, bool icase) return Condition(new detail::KeyCompareConditionImpl(key.mItemTag, [tag = key.mItemTag, v](const Category& c, const Row& r, bool icase)
{ return r[tag].template compare<T>(v, icase) <= 0; }, s.str())); { return r[tag].template compare<T>(v, icase) <= 0; }, s.str()));
...@@ -1824,6 +1824,12 @@ class Category ...@@ -1824,6 +1824,12 @@ class Category
RowSet getChildren(Row r, Category& childCat); RowSet getChildren(Row r, Category& childCat);
RowSet getChildren(Row r, const char* childCat); RowSet getChildren(Row r, const char* childCat);
RowSet getParents(Row r, Category& parentCat);
RowSet getParents(Row r, const char* parentCat);
RowSet getLinked(Row r, Category& cat);
RowSet getLinked(Row r, const char* cat);
bool isValid(); bool isValid();
void validateLinks() const; void validateLinks() const;
...@@ -1904,7 +1910,13 @@ class File ...@@ -1904,7 +1910,13 @@ class File
bool isValid(); bool isValid();
void validateLinks() const; void validateLinks() const;
Datablock& firstDatablock() { return *mHead; } Datablock& firstDatablock()
{
if (mHead == nullptr)
throw std::runtime_error("No datablocks in file");
return *mHead;
}
void append(Datablock* e); void append(Datablock* e);
Datablock* get(const std::string& name) const; Datablock* get(const std::string& name) const;
......
...@@ -340,6 +340,16 @@ double CosinusAngle(const PointF<F>& p1, const PointF<F>& p2, const PointF<F>& p ...@@ -340,6 +340,16 @@ double CosinusAngle(const PointF<F>& p1, const PointF<F>& p2, const PointF<F>& p
return result; return result;
} }
template<typename F>
auto DistancePointToLine(const PointF<F> &l1, const PointF<F> &l2, const PointF<F> &p)
{
auto line = l2 - l1;
auto p_to_l1 = p - l1;
auto p_to_l2 = p - l2;
auto cross = CrossProduct(p_to_l1, p_to_l2);
return cross.length() / line.length();
}
// -------------------------------------------------------------------- // --------------------------------------------------------------------
// For e.g. simulated annealing, returns a new point that is moved in // For e.g. simulated annealing, returns a new point that is moved in
// a random direction with a distance randomly chosen from a normal // a random direction with a distance randomly chosen from a normal
......
...@@ -1904,6 +1904,55 @@ RowSet Category::getChildren(Row r, Category& childCat) ...@@ -1904,6 +1904,55 @@ RowSet Category::getChildren(Row r, Category& childCat)
return result; return result;
} }
RowSet Category::getParents(Row r, const char* parentCat)
{
return getParents(r, mDb[parentCat]);
}
RowSet Category::getParents(Row r, Category& parentCat)
{
assert(mValidator != nullptr);
assert(mCatValidator != nullptr);
RowSet result(parentCat);
for (auto& link: mValidator->getLinksForChild(mName))
{
if (link->mParentCategory != parentCat.mName)
continue;
Condition cond;
for (size_t ix = 0; ix < link->mChildKeys.size(); ++ix)
{
const char* value = r[link->mChildKeys[ix]].c_str();
cond = std::move(cond) && (Key(link->mParentKeys[ix]) == value);
}
auto parents = parentCat.find(std::move(cond));
result.insert(result.end(), parents.begin(), parents.end());
}
// remove duplicates
result.make_unique();
return result;
}
RowSet Category::getLinked(Row r, const char* cat)
{
return getLinked(r, mDb[cat]);
}
RowSet Category::getLinked(Row r, Category& cat)
{
RowSet result = getChildren(r, cat);
if (result.empty())
result = getParents(r, cat);
return result;
}
bool Category::isValid() bool Category::isValid()
{ {
bool result = true; bool result = true;
...@@ -2582,7 +2631,7 @@ void Row::assign(size_t column, const std::string& value, bool skipUpdateLinked) ...@@ -2582,7 +2631,7 @@ void Row::assign(size_t column, const std::string& value, bool skipUpdateLinked)
} }
} }
if (cif::VERBOSE >= 2) if (cif::VERBOSE > 2)
{ {
std::cerr << "Parent: " << linked->mParentCategory << " Child: " << linked->mChildCategory << std::endl std::cerr << "Parent: " << linked->mParentCategory << " Child: " << linked->mChildCategory << std::endl
<< cond << std::endl; << cond << std::endl;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment