// File: tomfunkhouser[P]gaps/pkgs/R3Shapes/R3Mesh.cpp
// Function: gaps::R3Mesh::AddRandomNoise(double)
void R3Mesh::
AddRandomNoise(RNScalar factor)
{
  // Change every vertex position
  bbox = R3null_box;
  for (int i = 0; i < NVertices(); i++) {
    R3MeshVertex *vertex = Vertex(i);
    RNLength max_distance = factor * VertexAverageEdgeLength(vertex);
    R3Vector random_vector(RNRandomScalar(), RNRandomScalar(), RNRandomScalar());
    vertex->position += max_distance * random_vector;
    vertex->flags.Remove(R3_MESH_VERTEX_NORMAL_UPTODATE);
    bbox.Union(vertex->position);
  }

  // Mark every edge out of date
  for (int i = 0; i < NEdges(); i++) {
    R3MeshEdge *edge = Edge(i);
    edge->flags.Remove(R3_MESH_EDGE_LENGTH_UPTODATE);
  }

  // Mark every face out of date
  for (int i = 0; i < NFaces(); i++) {
    R3MeshFace *face = Face(i);
    face->flags.Remove(R3_MESH_FACE_PLANE_UPTODATE | R3_MESH_FACE_BBOX_UPTODATE);
  }

  // Invalidate GL buffer objects
  InvalidateGLBufferObjects();
}

// Assembly:
subq $0xe8, %rsp
movq %rdi, 0xe0(%rsp)
movsd %xmm0, 0xd8(%rsp)
movq 0xe0(%rsp), %rdi
movq %rdi, 0x50(%rsp)
addq $0xf8, %rdi
leaq 0x15ebc5(%rip), %rsi    # 0x1787e8
callq 0x37500
movl $0x0, 0xd4(%rsp)
movq 0x50(%rsp), %rdi
movl 0xd4(%rsp), %eax
movl %eax, 0x4c(%rsp)
callq 0x135e0
movl %eax, %ecx
movl 0x4c(%rsp), %eax
cmpl %ecx, %eax
jge 0x19d7c
movq 0x50(%rsp), %rdi
movl 0xd4(%rsp), %esi
callq 0x13630
movq 0x50(%rsp), %rdi
movq %rax, 0xc8(%rsp)
movsd 0xd8(%rsp), %xmm0
movsd %xmm0, 0x28(%rsp)
movq 0xc8(%rsp), %rsi
callq 0x16db0
movaps %xmm0, %xmm1
movsd 0x28(%rsp), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, 0xc0(%rsp)
callq 0xd4710
movsd %xmm0, 0x38(%rsp)
callq 0xd4710
movsd %xmm0, 0x30(%rsp)
callq 0xd4710
movsd 0x30(%rsp), %xmm1
movaps %xmm0, %xmm2
movsd 0x38(%rsp), %xmm0
leaq 0xa8(%rsp), %rdi
callq 0x6fcb0
movsd 0xc0(%rsp), %xmm0
leaq 0x90(%rsp), %rdi
leaq 0xa8(%rsp), %rsi
callq 0x13800
movq 0xc8(%rsp), %rdi
addq $0x18, %rdi
leaq 0x90(%rsp), %rsi
callq 0x6f290
movq 0xc8(%rsp), %rax
addq $0x78, %rax
movq %rax, 0x40(%rsp)
leaq 0x88(%rsp), %rdi
movl $0x2, %esi
callq 0x13d80
movq 0x40(%rsp), %rdi
movq 0x88(%rsp), %rsi
callq 0x372b0
movq 0x50(%rsp), %rdi
addq $0xf8, %rdi
movq 0xc8(%rsp), %rsi
addq $0x18, %rsi
callq 0x444b0
movl 0xd4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xd4(%rsp)
jmp 0x19c33
movl $0x0, 0x84(%rsp)
movq 0x50(%rsp), %rdi
movl 0x84(%rsp), %eax
movl %eax, 0x24(%rsp)
callq 0x135c0
movl %eax, %ecx
movl 0x24(%rsp), %eax
cmpl %ecx, %eax
jge 0x19dfb
movq 0x50(%rsp), %rdi
movl 0x84(%rsp), %esi
callq 0x36930
movq %rax, 0x78(%rsp)
movq 0x78(%rsp), %rax
addq $0x38, %rax
movq %rax, 0x18(%rsp)
leaq 0x70(%rsp), %rdi
movl $0x2, %esi
callq 0x13d80
movq 0x18(%rsp), %rdi
movq 0x70(%rsp), %rsi
callq 0x372b0
movl 0x84(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x84(%rsp)
jmp 0x19d87
movl $0x0, 0x6c(%rsp)
movq 0x50(%rsp), %rdi
movl 0x6c(%rsp), %eax
movl %eax, 0x14(%rsp)
callq 0x135a0
movl %eax, %ecx
movl 0x14(%rsp), %eax
cmpl %ecx, %eax
jge 0x19e6d
movq 0x50(%rsp), %rdi
movl 0x6c(%rsp), %esi
callq 0x136d0
movq %rax, 0x60(%rsp)
movq 0x60(%rsp), %rax
addq $0xa8, %rax
movq %rax, 0x8(%rsp)
leaq 0x58(%rsp), %rdi
movl $0xc, %esi
callq 0x13d80
movq 0x8(%rsp), %rdi
movq 0x58(%rsp), %rsi
callq 0x372b0
movl 0x6c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x6c(%rsp)
jmp 0x19e03
movq 0x50(%rsp), %rdi
movq (%rdi), %rax
callq *0x290(%rax)
addq $0xe8, %rsp
retq
nopw %cs:(%rax,%rax)