This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def approx_pi (iterations): | |
''' pi approximation based on Archimedes' geometric method (find the | |
perimeter of a regular hexagon subdivided n times, and use that | |
as an approximation to C = 2*pi*r, with r = 1.0). | |
Note: Becomes increasingly inaccurate when iterations > 15 due to | |
the limitations of Python's floating point numbers. Would have to | |
implement bignums w/ an extremely accurate sqrt fcn to get better | |
precision. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "primes.hpp" | |
#include <vector> | |
#include <iostream> | |
// #include <sstream> | |
#include <cstdio> | |
// #include <thread> | |
// #include <future> | |
// #include <queue> | |
#include <algorithm> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
typedef int64_t entity_id; | |
entity_id newUUID () { | |
entity_id id = 0; | |
return ++id; | |
} | |
enum class EntityType { | |
Empty, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Copyright (c) 2014, Seiji Emery | |
// All rights reserved. | |
#ifndef __STACK_HPP__ | |
#define __STACK_HPP__ | |
#include <algorithm> | |
#include <cassert> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Quick guide to some C++11 features and good programming practices | |
// Constructors | |
// Suppose we have a class like this, and want to add constructors to it | |
class MyClass { | |
public: | |
// public members and methods... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// avl_tree2.hpp | |
// AVLTree | |
// | |
// Created by Seiji Emery on 11/18/14. | |
// Copyright (c) 2014 Seiji Emery. All rights reserved. | |
// | |
#ifndef AVLTree_avl_tree2_hpp | |
#define AVLTree_avl_tree2_hpp |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Kind of a boring example, but suppose you're writing a vector graphics renderer and need to | |
// both store and render several types of shapes including circles, rectangles, and polygons | |
// made up of multiple lines. These all have different type signatures (a circle is not a box), | |
// so to store them as one type you'll have to use polymorphism. | |
// There's two ways to do this in C++: via OOP, or using the older, procedural C-style. | |
// The object-oriented approach: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Generate n-dimensional cube vertex/edges (opengl) | |
void genVerts (int dimensions, float scale = 1.0f) { | |
assert(dimensions > 1 && dimensions <= 4); | |
auto posVal = scale * 0.5f; | |
auto negVal = -posVal; | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Copyright (c) 2014 Seiji Emery. All rights reserved. | |
#pragma once | |
#include "aabb.hpp" | |
#include "vec2.hpp" | |
// Quadtree impl. | |
// Note: This implementation relies on bulk insertion (list of objects is known ahead of time); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef __math2d_Vec2_h__ | |
#define __math2d_Vec2_h__ | |
#include <cmath> | |
#include <ostream> | |
#define DEFN_IMM_VECTOR_OP(op) \ | |
friend Vec2 operator op (const Vec2 &a, const Vec2 &b) { \ | |
return { a.x op b.x, a.y op b.y }; \ | |
} |