inline typename harel_bfs_traits<Graph, WeightMap>::weight ns_difference( typename harel_bfs_traits<Graph, WeightMap>::neighbor_similarity_map &one, typename harel_bfs_traits<Graph, WeightMap>::neighbor_similarity_map &two) { typedef typename harel_bfs_traits<Graph,WeightMap>::neighbor_similarity_map nsmap; typedef typename harel_bfs_traits<Graph,WeightMap>::weight weight_type; typedef typename harel_bfs_traits<Graph,WeightMap>::vertex key_type; typedef typename nsmap::iterator iter; weight_type diff = 0; iter one_i, two_i; for(one_i = one.begin(), two_i = two.begin(); one_i != one.end(); ++one_i) { iter it; if ((it = two.find((*one_i).first)) != two.end()) { // we found the same key in the other iterator // if it's not at our current position, copy all the elements up to // our current position while(two_i != it) { diff += t_abs((*two_i).second); ++two_i; } // now do this element diff += t_abs((*one_i).second - (*two_i).second); ++two_i; } else { diff += t_abs((*one_i).second); } } // lastly if our second list still contains elements, keep going while(two_i != two.end()) { diff += t_abs((*two_i).second); ++two_i; } return diff; }
cString::cString(const int64 number, uint base /* = DefaultStringBase*/, uint optMem /* = DefaultStringPage*/) : m_buffer(NULL), m_stringLength(0) { // Init the object createEmptyString(optMem); // Covert the number into positive value uint64 nm = t_abs(number); /* Check sign */ if (number < 0) { concat(m_stringNegativeInteger); } /* Covert the number into a string */ cString positiveString(nm, base); concat(positiveString); }
void SecondPassBinary::resolveStack(BinaryDependencies::DependencyObject& dependency, FirstPassBinary& firstPass, addressNumericValue binaryAddress, addressNumericValue dependencyAddress, uint dataStartAddress) { uint relocatePositionTo = dependencyAddress; uint currentPosition = binaryAddress + dependency.m_position; int distance = relocatePositionTo; distance-= currentPosition; switch (dependency.m_type) { case BinaryDependencies::DEP_STACK_ARG: distance = firstPass.getStackSize() + firstPass.getNonVolatilesSize(); break; case BinaryDependencies::DEP_STACK_LOCAL: distance = firstPass.getStackSize(); break; case BinaryDependencies::DEP_STACK_TEMP: distance = firstPass.getStackSize() - firstPass.getStackBaseSize(); break; default: CHECK_FAIL(); } switch (dependency.m_length) { case BinaryDependencies::DEP_8BIT: { if (dependency.m_shouldAddExistValue) distance += ((char)m_data[dataStartAddress + dependency.m_position]); // If we fails here, it means that the basic-block should have been arranged better CHECK_RELOCATION_RANGE(t_abs(distance), 0x100); distance >>= dependency.m_shiftRightCount; m_data[dataStartAddress + dependency.m_position] = ((int8)(distance)); } break; /* case BinaryDependencies::DEP_3BIT_3SKIP: { uint16 oldValue = cEndian::readUint16(m_data.getBuffer() + dependency.m_position + dataStartAddress, OpcodeSubsystems::isLittleEndian(m_type)); if (dependency.m_shouldAddExistValue) { // TODO! Pavel - It's doesn't look right... distance += makeInt(((oldValue >> 3) & 0x07), 3); } // If we fails here, it means that the basic-block should have been arranged better CHECK_RELOCATION_RANGE(t_abs(distance), 0x100); // TODO! Pavel - It's doesn't look right... oldValue = (oldValue & 0xF83F) + ((distance & 3) << 6) + ((distance & 0x1C) << 4); cEndian::writeUint16(m_data.getBuffer() + dependency.m_position + dataStartAddress, oldValue, OpcodeSubsystems::isLittleEndian(m_type)); } break; */ case BinaryDependencies::DEP_4BIT_LOWER: { char oldVal = ((char)m_data[dataStartAddress + dependency.m_position]); if (dependency.m_shouldAddExistValue) distance += makeInt(oldVal & 0x0F, 4); distance >>= dependency.m_shiftRightCount; CHECK_RELOCATION_RANGE(t_abs(distance), 0x10); m_data[dataStartAddress + dependency.m_position] = ((int8)((oldVal & 0xF0) + (distance & 0x0F))); } break; case BinaryDependencies::DEP_5BIT_5SPACE: { uint16 oldValue = cEndian::readUint16(m_data.getBuffer() + dependency.m_position + dataStartAddress, OpcodeSubsystems::isLittleEndian(m_type)); if (dependency.m_shouldAddExistValue) { distance+= makeInt((((oldValue >> 8) << 2) + (oldValue & 3)) & 0x1F, 5); } oldValue = (oldValue & 0xF83F) + ((distance & 3) << 6) + ((distance & 0x1C) << 4); CHECK_RELOCATION_RANGE(t_abs(distance), 0x20); cEndian::writeUint16(m_data.getBuffer() + dependency.m_position + dataStartAddress, oldValue, OpcodeSubsystems::isLittleEndian(m_type)); } break; case BinaryDependencies::DEP_8BIT_4SPACE: { uint16 oldValue = cEndian::readUint16(m_data.getBuffer() + dependency.m_position + dataStartAddress, OpcodeSubsystems::isLittleEndian(m_type)); if (dependency.m_shouldAddExistValue) { distance += makeInt(((oldValue & 0xF00) >> 4) + (oldValue & 0x0F), 8); } CHECK_RELOCATION_RANGE(t_abs(distance), 0x100); oldValue = ((distance & 0xF0) << 4) + (oldValue & 0xF0F0) + (distance & 0x0F); cEndian::writeUint16(m_data.getBuffer() + dependency.m_position + dataStartAddress, oldValue, OpcodeSubsystems::isLittleEndian(m_type)); }
unsigned int add_arc_as_cubics(int max_recursion, Builder *B, float tol, vec2 start_pt, vec2 end_pt, vec2 center, float radius, float start_angle, float angle) { /* One way to approximate an arc with a cubic-bezier is as * follows (taken from GLyphy which is likely take its * computations from Cairo). * * D = tan(angle / 4) * p0 = start of arc * p3 = end of arc * vp = p3 - p1 * jp = J(vp) * A = (1 - D^2) / 3 * B = (2 * D) / 3 * p1 = p0 + A * vp - B * jp * p2 = p1 - A * vp - B * jp * * and the error between the arc and [p0, p1, p2, p3] is given by * * error <= |vp| * |D|^5 / (54(1 + D^2)) * * Now, |angle| < 2 * PI, implies |angle| / 4 < PI / 4 thus |D| < 1, giving * * error <= |vp| * |D|^5 / 27 * * thus we need: * * |tan(|angle| / 4)|^5 < (27 * tol) / |vp| * * since, tan() is increasing function, * * |angle| < 4 * pow(atan((27 * tol) / |vp|), 0.20f) * */ vec2 vp(end_pt - start_pt); vec2 jp(-vp.y(), vp.x()); float mag_vp(vp.magnitude()); float goal, angle_max; if (mag_vp < tol) { B->line_to(end_pt); return 1; } /* half the tolerance for the cubic to quadratic and half * the tolerance for arc to cubic. */ tol *= 0.5f; goal = t_min(1.0f, (27.0f * tol) / vp.magnitude()); angle_max = t_min(FASTUIDRAW_PI, 4.0f * std::pow(fastuidraw::t_atan(goal), 0.20f)); float angle_remaining(angle); float current_angle(start_angle); float angle_direction(t_sign(angle)); float angle_advance(angle_max * angle_direction); vec2 last_pt(start_pt); unsigned int return_value(0); while (t_abs(angle_remaining) > angle_max) { float next_angle(current_angle + angle_advance); float cos_next_angle(t_cos(next_angle)); float sin_next_angle(t_sin(next_angle)); vec2 next_delta, next_pt; next_pt.x() = center.x() + cos_next_angle * radius; next_pt.y() = center.y() + sin_next_angle * radius; return_value += add_arc_as_single_cubic(max_recursion, B, tol, last_pt, next_pt, angle_advance); current_angle += angle_advance; angle_remaining -= angle_advance; last_pt = next_pt; } return_value += add_arc_as_single_cubic(max_recursion, B, tol, last_pt, end_pt, angle_remaining); return return_value; }