public void ScaleNodeWeight(IVector2 _node, double _scaleF, bool _allDirs = false) { if (Bidirectional) { var selNode = new IVector2(_node + IVector2.Yp); if (m_Nodes.InBounds(selNode)) { m_Nodes[selNode] = m_Nodes[selNode].CreateUpdatedEdge(G2Dir.D, m_Nodes[selNode].GetEdge(G2Dir.D) * _scaleF); } selNode = new IVector2(_node + IVector2.Xp); if (m_Nodes.InBounds(selNode)) { m_Nodes[selNode] = m_Nodes[selNode].CreateUpdatedEdge(G2Dir.L, m_Nodes[selNode].GetEdge(G2Dir.L) * _scaleF); } selNode = new IVector2(_node + IVector2.Yn); if (m_Nodes.InBounds(selNode)) { m_Nodes[selNode] = m_Nodes[selNode].CreateUpdatedEdge(G2Dir.U, m_Nodes[selNode].GetEdge(G2Dir.U) * _scaleF); } selNode = new IVector2(_node + IVector2.Xn); if (m_Nodes.InBounds(selNode)) { m_Nodes[selNode] = m_Nodes[selNode].CreateUpdatedEdge(G2Dir.R, m_Nodes[selNode].GetEdge(G2Dir.R) * _scaleF); } if (_allDirs) { selNode = new IVector2(_node + IVector2.XnYp); if (m_Nodes.InBounds(selNode)) { m_Nodes[selNode] = m_Nodes[selNode].CreateUpdatedEdge(G2Dir.DR, m_Nodes[selNode].GetEdge(G2Dir.DR) * _scaleF); } selNode = new IVector2(_node + IVector2.XpYp); if (m_Nodes.InBounds(selNode)) { m_Nodes[selNode] = m_Nodes[selNode].CreateUpdatedEdge(G2Dir.DL, m_Nodes[selNode].GetEdge(G2Dir.DL) * _scaleF); } selNode = new IVector2(_node + IVector2.XpYn); if (m_Nodes.InBounds(selNode)) { m_Nodes[selNode] = m_Nodes[selNode].CreateUpdatedEdge(G2Dir.UL, m_Nodes[selNode].GetEdge(G2Dir.UL) * _scaleF); } selNode = new IVector2(_node + IVector2.XnYn); if (m_Nodes.InBounds(selNode)) { m_Nodes[selNode] = m_Nodes[selNode].CreateUpdatedEdge(G2Dir.UR, m_Nodes[selNode].GetEdge(G2Dir.UR) * _scaleF); } } } else { if (!m_Nodes.InBounds(_node)) { return; } var newWeight = m_Nodes[_node].Weight * _scaleF; m_Nodes[_node] = new Graph2dNode(newWeight, Bidirectional); } }
/*public void SetEdgeWeight(IVector2 _node, G2Dir _direction, double _weight) * { * m_Nodes[_node] = m_Nodes[_node].CreateUpdatedEdge(_direction, _weight); * }*/ /// <summary> /// Updates all neighbors' edges weight to _weight. /// </summary> /// <param name="_node"></param> /// <param name="_weight"></param> public void SetNodeWeight(IVector2 _node, double _weight, bool _allDirs = false) { if (InBounds(_node)) { if (Bidirectional) { IVector2 selNode = new IVector2(_node + IVector2.Yp); if (m_Nodes.InBounds(selNode)) { m_Nodes[selNode] = m_Nodes[selNode].CreateUpdatedEdge(G2Dir.D, _weight); } selNode = new IVector2(_node + IVector2.Xp); if (m_Nodes.InBounds(selNode)) { m_Nodes[selNode] = m_Nodes[selNode].CreateUpdatedEdge(G2Dir.L, _weight); } selNode = new IVector2(_node + IVector2.Yn); if (m_Nodes.InBounds(selNode)) { m_Nodes[selNode] = m_Nodes[selNode].CreateUpdatedEdge(G2Dir.U, _weight); } selNode = new IVector2(_node + IVector2.Xn); if (m_Nodes.InBounds(selNode)) { m_Nodes[selNode] = m_Nodes[selNode].CreateUpdatedEdge(G2Dir.R, _weight); } if (_allDirs) { selNode = new IVector2(_node + IVector2.XnYp); if (m_Nodes.InBounds(selNode)) { m_Nodes[selNode] = m_Nodes[selNode].CreateUpdatedEdge(G2Dir.DR, _weight); } selNode = new IVector2(_node + IVector2.XpYp); if (m_Nodes.InBounds(selNode)) { m_Nodes[selNode] = m_Nodes[selNode].CreateUpdatedEdge(G2Dir.DL, _weight); } selNode = new IVector2(_node + IVector2.XpYn); if (m_Nodes.InBounds(selNode)) { m_Nodes[selNode] = m_Nodes[selNode].CreateUpdatedEdge(G2Dir.UL, _weight); } selNode = new IVector2(_node + IVector2.XnYn); if (m_Nodes.InBounds(selNode)) { m_Nodes[selNode] = m_Nodes[selNode].CreateUpdatedEdge(G2Dir.UR, _weight); } } } else { m_Nodes[_node] = new Graph2dNode(_weight, false); } } }