mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-03 10:22:45 -04:00
is_ancestor_of(), get_common_ancestor()
This commit is contained in:
parent
350eafbd02
commit
4a5e1e825e
@ -316,6 +316,47 @@ is_same_graph(const NodePath &other) const {
|
|||||||
return (find_common_ancestor(*this, other, a_count, b_count) != (NodePathComponent *)NULL);
|
return (find_common_ancestor(*this, other, a_count, b_count) != (NodePathComponent *)NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: NodePath::is_ancestor_of
|
||||||
|
// Access: Published
|
||||||
|
// Description: Returns true if the node represented by this NodePath
|
||||||
|
// is a parent or other ancestor of the other NodePath,
|
||||||
|
// or false if it is not.
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
INLINE bool NodePath::
|
||||||
|
is_ancestor_of(const NodePath &other) const {
|
||||||
|
int a_count, b_count;
|
||||||
|
if (find_common_ancestor(*this, other, a_count, b_count) == (NodePathComponent *)NULL) {
|
||||||
|
// Not related.
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// They are related; now b is descended from a only if a is the
|
||||||
|
// common ancestor (which is to say, a_count == 0).
|
||||||
|
return (a_count == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: NodePath::get_common_ancestor
|
||||||
|
// Access: Published
|
||||||
|
// Description: Returns the lowest NodePath that both of these two
|
||||||
|
// NodePaths have in common: the first ancestor that
|
||||||
|
// both of them share. If the two NodePaths are
|
||||||
|
// unrelated, returns NodePath::not_found().
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
INLINE NodePath NodePath::
|
||||||
|
get_common_ancestor(const NodePath &other) const {
|
||||||
|
int a_count, b_count;
|
||||||
|
NodePathComponent *common = find_common_ancestor(*this, other, a_count, b_count);
|
||||||
|
if (common == (NodePathComponent *)NULL) {
|
||||||
|
return NodePath::not_found();
|
||||||
|
}
|
||||||
|
|
||||||
|
NodePath result;
|
||||||
|
result._head = common;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: NodePath::get_num_children
|
// Function: NodePath::get_num_children
|
||||||
// Access: Published
|
// Access: Published
|
||||||
|
@ -192,6 +192,8 @@ PUBLISHED:
|
|||||||
INLINE int get_key() const;
|
INLINE int get_key() const;
|
||||||
|
|
||||||
INLINE bool is_same_graph(const NodePath &other) const;
|
INLINE bool is_same_graph(const NodePath &other) const;
|
||||||
|
INLINE bool is_ancestor_of(const NodePath &other) const;
|
||||||
|
INLINE NodePath get_common_ancestor(const NodePath &other) const;
|
||||||
|
|
||||||
// Methods that return collections of NodePaths derived from or
|
// Methods that return collections of NodePaths derived from or
|
||||||
// related to this one.
|
// related to this one.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user