public void record(float value) { longAvg = longAvg * (1 - LONG_FRACTION) + value * LONG_FRACTION; shortAvg = shortAvg * (1 - SHORT_FRACTION) + value * SHORT_FRACTION; min = JBoxUtils.min(value, min); max = JBoxUtils.max(value, max); }
/** Returns the closest value to 'a' that is in between 'low' and 'high' */ public final static float clamp(final float a, final float low, final float high) { return max(low, min(a, high)); }
@Override public int getMaxBalance() { int maxBalance = 0; for (int i = 0; i < m_nodeCapacity; ++i) { if (m_height[i] <= 1) { continue; } assert (m_child1[i] != NULL_NODE); int child1 = m_child1[i]; int child2 = m_child2[i]; int balance = JBoxUtils.abs(m_height[child2] - m_height[child1]); maxBalance = JBoxUtils.max(maxBalance, balance); } return maxBalance; }
@Override public int getMaxBalance() { int maxBalance = 0; for (int i = 0; i < m_nodeCapacity; ++i) { final DynamicTreeNode node = m_nodes[i]; if (node.height <= 1) { continue; } assert (node.child1 == null == false); DynamicTreeNode child1 = node.child1; DynamicTreeNode child2 = node.child2; int balance = JBoxUtils.abs(child2.height - child1.height); maxBalance = JBoxUtils.max(maxBalance, balance); } return maxBalance; }
private final int computeHeight(int node) { assert (0 <= node && node < m_nodeCapacity); if (m_child1[node] == NULL_NODE) { return 0; } int height1 = computeHeight(m_child1[node]); int height2 = computeHeight(m_child2[node]); return 1 + JBoxUtils.max(height1, height2); }
private final int computeHeight(DynamicTreeNode node) { assert (0 <= node.id && node.id < m_nodeCapacity); if (node.child1 == null) { return 0; } int height1 = computeHeight(node.child1); int height2 = computeHeight(node.child2); return 1 + JBoxUtils.max(height1, height2); }
m_aabb[C].combine(m_aabb[A], m_aabb[F]); m_height[A] = 1 + JBoxUtils.max(m_height[B], m_height[G]); m_height[C] = 1 + JBoxUtils.max(m_height[A], m_height[F]); } else { m_child2[C] = iG; m_aabb[C].combine(m_aabb[A], m_aabb[G]); m_height[A] = 1 + JBoxUtils.max(m_height[B], m_height[F]); m_height[C] = 1 + JBoxUtils.max(m_height[A], m_height[G]); m_aabb[B].combine(m_aabb[A], m_aabb[D]); m_height[A] = 1 + JBoxUtils.max(m_height[C], m_height[E]); m_height[B] = 1 + JBoxUtils.max(m_height[A], m_height[D]); } else { m_child2[B] = iE; m_aabb[B].combine(m_aabb[A], m_aabb[E]); m_height[A] = 1 + JBoxUtils.max(m_height[C], m_height[D]); m_height[B] = 1 + JBoxUtils.max(m_height[A], m_height[E]);
m_height[index] = 1 + JBoxUtils.max(m_height[child1], m_height[child2]);
index.height = 1 + JBoxUtils.max(child1.height, child2.height);
float h = pressurePerWeight * JBoxUtils.max(0.0f, JBoxUtils.min(w, JBoxSettings.maxParticleWeight) - JBoxSettings.minParticleWeight); m_accumulationBuffer[i] = h;
private void validateMetrics(int node) { if (node == NULL_NODE) { return; } int child1 = m_child1[node]; int child2 = m_child2[node]; if (child1 == NULL_NODE) { assert (child1 == NULL_NODE); assert (child2 == NULL_NODE); assert (m_height[node] == 0); return; } assert (child1 != NULL_NODE && 0 <= child1 && child1 < m_nodeCapacity); assert (child2 != child1 && 0 <= child2 && child2 < m_nodeCapacity); int height1 = m_height[child1]; int height2 = m_height[child2]; int height; height = 1 + JBoxUtils.max(height1, height2); assert (m_height[node] == height); AABB aabb = new AABB(); aabb.combine(m_aabb[child1], m_aabb[child2]); assert (aabb.lowerBound.equals(m_aabb[node].lowerBound)); assert (aabb.upperBound.equals(m_aabb[node].upperBound)); validateMetrics(child1); validateMetrics(child2); }
private void validateMetrics(DynamicTreeNode node) { if (node == null) { return; } DynamicTreeNode child1 = node.child1; DynamicTreeNode child2 = node.child2; if (node.child1 == null) { assert (child1 == null); assert (child2 == null); assert (node.height == 0); return; } assert (child1 != null && 0 <= child1.id && child1.id < m_nodeCapacity); assert (child2 != null && 0 <= child2.id && child2.id < m_nodeCapacity); int height1 = child1.height; int height2 = child2.height; int height; height = 1 + JBoxUtils.max(height1, height2); assert (node.height == height); AABB aabb = new AABB(); aabb.combine(child1.aabb, child2.aabb); assert (aabb.lowerBound.equals(node.aabb.lowerBound)); assert (aabb.upperBound.equals(node.aabb.upperBound)); validateMetrics(child1); validateMetrics(child2); }
parent.child1 = child1; parent.child2 = child2; parent.height = 1 + JBoxUtils.max(child1.height, child2.height); parent.aabb.combine(child1.aabb, child2.aabb); parent.parent = null;
int newLen = JBoxUtils.max(old.length * 2, childCount); m_proxies = new FixtureProxy[newLen]; System.arraycopy(old, 0, m_proxies, 0, old.length);
m_positionConstraints = new ContactPositionConstraint[JBoxUtils.max(old.length * 2, m_count)]; System.arraycopy(old, 0, m_positionConstraints, 0, old.length); for (int i = old.length; i < m_positionConstraints.length; i++) { m_velocityConstraints = new ContactVelocityConstraint[JBoxUtils.max(old.length * 2, m_count)]; System.arraycopy(old, 0, m_velocityConstraints, 0, old.length); for (int i = old.length; i < m_velocityConstraints.length; i++) {
assert (child2 != null); index.height = 1 + JBoxUtils.max(child1.height, child2.height); index.aabb.combine(child1.aabb, child2.aabb);
assert (child2 != NULL_NODE); m_height[index] = 1 + JBoxUtils.max(m_height[child1], m_height[child2]); m_aabb[index].combine(m_aabb[child1], m_aabb[child2]);
JBoxUtils.clamp(translation, -JBoxSettings.maxLinearCorrection, JBoxSettings.maxLinearCorrection); linearError = JBoxUtils.max(linearError, JBoxUtils.abs(translation)); active = true; } else if (translation <= m_lowerTranslation) { JBoxUtils.clamp(translation - m_lowerTranslation + JBoxSettings.linearSlop, -JBoxSettings.maxLinearCorrection, 0.0f); linearError = JBoxUtils.max(linearError, m_lowerTranslation - translation); active = true; } else if (translation >= m_upperTranslation) { JBoxUtils.clamp(translation - m_upperTranslation - JBoxSettings.linearSlop, 0.0f, JBoxSettings.maxLinearCorrection); linearError = JBoxUtils.max(linearError, translation - m_upperTranslation); active = true;
m_impulse.z = JBoxUtils.max(m_impulse.z, 0.0f); } else if (m_limitState == LimitState.AT_UPPER) { m_impulse.z = JBoxUtils.min(m_impulse.z, 0.0f);