Skip to content

Instantly share code, notes, and snippets.

View mcsee's full-sized avatar
🏠
Working from home

mcsee mcsee

🏠
Working from home
View GitHub Profile
@mcsee
mcsee / point.c
Last active July 15, 2020 23:54
Struct Point in C
struct Point {
float x;
float y;
}
struct Point {
float angle;
float distance;
}
<?
final class Point {
private $x;
private $y;
}
<?
final class Point {
private $angle;
private $distance;
}
<?
final class Point {
private $x;
private $y;
public function x() {
return $this->x;
}
<?
final class Point {
private $angle;
private $distance;
public function x() {
return $this->distance * cos($this->angle);
}
<?
final class Polygon {
public $vertices;
}
<?
final class Polygon {
private $vertices;
public function getVertices(): Collection {
return $this->vertices;
}
public function setVertices(Collection $newVertices) {
<?
final class Polygon {
private $vertices;
private function __construct(Collection $newVertices) {
if (count($newVertices < 3)) {
throw new
Exception('Cannot create a polygon with less than 3 vertices');
<?
$triangle =
new Polygon([new Point(1, 1), new Point(2, 2), new Point(3, 3)]);
$triangle->setVertices([new Point(1, 1)]);