Skip to content

Instantly share code, notes, and snippets.

View cjameshuff's full-sized avatar

Christopher James Huff cjameshuff

View GitHub Profile
@cjameshuff
cjameshuff / gist:85642de07f2af4e0b21efae6a97b22df
Created January 1, 2018 00:19
Clang 5.0 toolchain install
# https://stackoverflow.com/questions/39332406/install-libc-on-ubuntu
# Adapted for Clang 5.0
sudo apt-get update
sudo apt-get install -y clang-5.0 clang-5.0-doc \
libclang-common-5.0-dev libclang-5.0-dev libclang1-5.0 libclang1-5.0-dbg \
libllvm5.0 libllvm5.0-dbg lldb-5.0 llvm-5.0 llvm-5.0-dev llvm-5.0-runtime \
clang-format-5.0 python-clang-5.0 liblldb-5.0-dev lld-5.0 libfuzzer-5.0-dev \
subversion cmake
@cjameshuff
cjameshuff / format.cpp
Last active January 26, 2017 23:09
boost::format with type-safe C-style format strings
#include "boost/format.hpp"
#include <string>
#include <utility>
inline auto fmt_r(boost::format & format) -> boost::format & {return format;}
template<typename T, typename... Args>
auto fmt_r(boost::format & format, T && val, Args &&... args) -> boost::format & {
return fmt_r(format % std::forward<T>(val), std::forward<Args>(args)...);
}
#include <cstdlib>
#include <iostream>
#include <iterator>
#include "boost/format.hpp"
using boost::format;
namespace iter {
template<typename T>
auto BBox::SlopeTest(const t_ClassifiedRay<T> & ray) const -> bool
{
auto && tl = (minExt - ray.origin)*ray.rdir;
auto && th = (maxExt - ray.origin)*ray.rdir;
auto && tmin = std::min(tl.x, th.x);
auto && tmax = std::max(tl.x, th.x);
tmin = std::max(tmin, std::min(std::min(tl.y, th.y), tmax));
tmax = std::min(tmax, std::max(std::max(tl.y, th.y), tmin));
@cjameshuff
cjameshuff / lambdafun.cpp
Last active November 14, 2015 16:32
Fun with lambdas
#include <cstdlib>
#include <iostream>
#include "boost/format.hpp"
using boost::format;
namespace iter {
def to_bin(bits) bits.to_s(2).rjust(64, '0') end
x = 0xFFFFFFFFFFFFFFFF
puts to_bin(x)
x = ((x & 0x00000000001FFC00) << 20) | (x & 0x00000000000003FF)
puts to_bin(x)
x = ((x & 0x000001F8000003E0) << 10) | (x & 0x00000007C000001F)
puts to_bin(x)
x = ((x & 0x00070006000C0018) << 6) | (x & 0x0000E001C0038007)
#ifndef TEST_DEFS_H
#define TEST_DEFS_H
#include "flexproto.h"
using namespace flexproto;
struct Point {
int32_t x;
int32_t y;
qeg.GenerateFromFaces(faces.size(), vertices.size(),
[this](ind_t faceIdx, ind_t & a, ind_t & b, ind_t & c){
auto & face = faces[faceIdx];
a = face.vertices[0];
b = face.vertices[1];
c = face.vertices[2];
}
);
{
parts: {
test_shape: {
shape: union
children: [
{shape: sphere, center: [0, 0, 5], radius: 4.5}
{shape: sphere, center: [-2, 0,-1], radius: 2.1}
{shape: sphere, center: [2, 0,-1], radius: 2.1}
]
}
// *****************************************************************************
// The MIT License (MIT)
//
// Copyright (c) 2013 Christopher James Huff
// https://github.com/cjameshuff/
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell