<commit_before>#include <other/core/mesh/HalfedgeGraph.h>
#include <other/core/python/Class.h>

namespace other {

OTHER_DEFINE_TYPE(HalfedgeGraph)

HalfedgeGraph::HalfedgeGraph() {}

HalfedgeGraph::HalfedgeGraph(const HalfedgeGraph& g)
  : halfedges_(g.halfedges_.copy())
  , vertex_to_edge_(g.vertex_to_edge_.copy())
{}

HalfedgeGraph::~HalfedgeGraph() {}

OTHER_CORE_EXPORT Ref<HalfedgeGraph> HalfedgeGraph::copy() const { return new_<HalfedgeGraph>(*this); }

bool HalfedgeGraph::valid(VertexId v)   const { 
  return vertex_to_edge_.valid(v);
}
bool HalfedgeGraph::valid(HalfedgeId e) const { 
  return halfedges_.valid(e);
}
bool HalfedgeGraph::valid(EdgeId e)     const { 
  return e.valid() && halfedges_.valid(halfedge(e,false));
}

VertexId HalfedgeGraph::add_vertex() {
  return vertex_to_edge_.append(HalfedgeId());
}

void HalfedgeGraph::add_vertices(int n) {
  assert(n >= 0);
  vertex_to_edge_.flat.resize(vertex_to_edge_.size() + n);
  assert(n == 0 || vertex_to_edge_.flat.back().valid() == false); // Check that new elements were correctly initialized
}

Array<VertexId> HalfedgeGraph::one_ring(VertexId v) const {
  Array<VertexId> result;
  for(const HalfedgeId e : outgoing(v)) {
    assert(src(e) == v);
    result.append(dst(e));
  }
  return result;
}

bool halfedges_linked(const HalfedgeGraph& g, const HalfedgeId e) {
  const auto en = g.next(e);
  const auto ep = g.prev(e);
  return (g.prev(g.next(e)) == e) && (g.src(g.next(e)) == g.src(g.reverse(e)))
      && (g.next(g.prev(e)) == e) && (g.src(e) == g.src(g.reverse(g.prev(e))));
}
template<int d> bool halfedges_linked(const HalfedgeGraph& g, const Vector<HalfedgeId, d> edges) {
  for(const HalfedgeId& e : edges)
    if(!halfedges_linked(g, e))
      return false;
  return true;
}

OTHER_CORE_EXPORT EdgeId HalfedgeGraph::split_edge(const EdgeId e, const VertexId use_vertex) {
  const int base = halfedges_.size();
  assert(base % 2 == 0); // Should have even number of halfedges
  const HalfedgeId src_to_dst = halfedge(e, false);
  const HalfedgeId dst_to_src = halfedge(e, true);
  const HalfedgeId v_to_dst = HalfedgeId(base + 0);
  const HalfedgeId dst_to_v = HalfedgeId(base + 1);
  const HalfedgeId src_to_v = src_to_dst; // Origional edge will now go to v
  const HalfedgeId v_to_src = dst_to_src; // And it's reverse will go back from v

  const VertexId orig_dst = dst(e);

  assert(vertex_to_edge_.valid(use_vertex) && !vertex_to_edge_[use_vertex].valid()); // Must be valid vertex with no edges
  vertex_to_edge_[use_vertex] = v_to_dst;
  
  OTHER_ASSERT(v_to_dst == halfedges_.append(HalfedgeInfo({src_to_v, next(src_to_dst), use_vertex})));
  OTHER_ASSERT(dst_to_v == halfedges_.append(HalfedgeInfo({prev(dst_to_src), v_to_src, orig_dst})));
  
  halfedges_[next(v_to_dst)].prev = v_to_dst;
  halfedges_[prev(dst_to_v)].next = dst_to_v;<commit_msg>HalfedgeGraph: Remove an unused function<commit_after>#include <other/core/mesh/HalfedgeGraph.h>
#include <other/core/python/Class.h>

namespace other {

OTHER_DEFINE_TYPE(HalfedgeGraph)

HalfedgeGraph::HalfedgeGraph() {}

HalfedgeGraph::HalfedgeGraph(const HalfedgeGraph& g)
  : halfedges_(g.halfedges_.copy())
  , vertex_to_edge_(g.vertex_to_edge_.copy())
{}

HalfedgeGraph::~HalfedgeGraph() {}

OTHER_CORE_EXPORT Ref<HalfedgeGraph> HalfedgeGraph::copy() const { return new_<HalfedgeGraph>(*this); }

bool HalfedgeGraph::valid(VertexId v)   const { 
  return vertex_to_edge_.valid(v);
}
bool HalfedgeGraph::valid(HalfedgeId e) const { 
  return halfedges_.valid(e);
}
bool HalfedgeGraph::valid(EdgeId e)     const { 
  return e.valid() && halfedges_.valid(halfedge(e,false));
}

VertexId HalfedgeGraph::add_vertex() {
  return vertex_to_edge_.append(HalfedgeId());
}

void HalfedgeGraph::add_vertices(int n) {
  assert(n >= 0);
  vertex_to_edge_.flat.resize(vertex_to_edge_.size() + n);
  assert(n == 0 || vertex_to_edge_.flat.back().valid() == false); // Check that new elements were correctly initialized
}

Array<VertexId> HalfedgeGraph::one_ring(VertexId v) const {
  Array<VertexId> result;
  for(const HalfedgeId e : outgoing(v)) {
    assert(src(e) == v);
    result.append(dst(e));
  }
  return result;
}

OTHER_CORE_EXPORT EdgeId HalfedgeGraph::split_edge(const EdgeId e, const VertexId use_vertex) {
  const int base = halfedges_.size();
  assert(base % 2 == 0); // Should have even number of halfedges
  const HalfedgeId src_to_dst = halfedge(e, false);
  const HalfedgeId dst_to_src = halfedge(e, true);
  const HalfedgeId v_to_dst = HalfedgeId(base + 0);
  const HalfedgeId dst_to_v = HalfedgeId(base + 1);
  const HalfedgeId src_to_v = src_to_dst; // Origional edge will now go to v
  const HalfedgeId v_to_src = dst_to_src; // And it's reverse will go back from v

  const VertexId orig_dst = dst(e);

  assert(vertex_to_edge_.valid(use_vertex) && !vertex_to_edge_[use_vertex].valid()); // Must be valid vertex with no edges
  vertex_to_edge_[use_vertex] = v_to_dst;
  
  OTHER_ASSERT(v_to_dst == halfedges_.append(HalfedgeInfo({src_to_v, next(src_to_dst), use_vertex})));
  OTHER_ASSERT(dst_to_v == halfedges_.append(HalfedgeInfo({prev(dst_to_src), v_to_src, orig_dst})));
  
  halfedges_[next(v_to_dst)].prev = v_to_dst;
  halfedges_[prev(dst_to_v)].next = dst_to_v;
{'fraction_non_alphanumeric': 0.13584256782575468, 'fraction_numerical': 0.0022927015666794038, 'mean_word_length': 5.462962962962963, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '883666', 'n_tokens_mistral': 1942, 'n_tokens_neox': 1868, 'n_words': 381}