Skip to content

Commit

Permalink
Suppression de ArduinoSTL.
Browse files Browse the repository at this point in the history
Signed-off-by: Yoan Blanc <[email protected]>
  • Loading branch information
greut committed Nov 28, 2016
1 parent 7cbead7 commit 6ddb7d8
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/programme/declarations.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <Servo.h> // Installer Servo
#include <Servo.h>
#include <EEPROM.h>
#include <math.h>

Expand Down
10 changes: 5 additions & 5 deletions src/programme/dessins.h
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
#include <ArduinoSTL.h> // Install ArduinoSTL
#include "shared.h"
#include "declarations.h"

void etoile(double cx=0, double cy=100, double r=50) {
pair_double point;
double x;
double y;
double position;
double t;

for(t = 0; t < 6*M_PI; t += par) {
position = 6 * M_PI / t;
if (_etoile(point, cx, cy, r, position)) {
toAngle(point.first, point.second);
if (_etoile(x, y, cx, cy, r, position)) {
toAngle(x, y);
moveServos();
if (debug) log("HYPO", t, point.first, point.second);
if (debug) log("HYPO", t, x, y);
}
}
}
Expand Down
7 changes: 3 additions & 4 deletions src/programme/shared.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
#include <math.h>
#include "shared.h"

// Étoile à 5 branches
//
// https://en.wikipedia.org/wiki/Hypotrochoid
bool _etoile(pair_double& output, double cx, double cy, double r, double position=0)
bool _etoile(double& x, double& y, double cx, double cy, double r, double position=0)
{
// Division par zéro
if (r <= 0) {
Expand All @@ -22,6 +21,6 @@ bool _etoile(pair_double& output, double cx, double cy, double r, double positio
// t va de 0 à 6 pi
double t = position * 6 * M_PI;

output.first = cx + (r - r2) * cos(t) + r * cos((r - r2) / r2 * t);
output.second = cy + (r - r2) * sin(t) - r * sin((r - r2) / r2 * t);
x = cx + (r - r2) * cos(t) + r * cos((r - r2) / r2 * t);
y = cy + (r - r2) * sin(t) - r * sin((r - r2) / r2 * t);
}
6 changes: 2 additions & 4 deletions src/programme/shared.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#include <vector>
#include <math.h>

#pragma once

typedef std::pair<double,double> pair_double;

bool _etoile(pair_double& output, double cx, double cy, double r, double par);
bool _etoile(double& x, double& y, double cx, double cy, double r, double par);
11 changes: 7 additions & 4 deletions src/swig/shared.i
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
%module shared
%include "std_pair.i"

%template(pair_double) std::pair<double,double>;
%include "typemaps.i"
%apply double *OUTPUT { double& x }
%apply double *OUTPUT { double& y }

%{
#include <vector>

extern bool _etoile(
std::pair<double,double>& output,
double& x,
double& y,
double cx,
double cy,
double r,
Expand All @@ -16,7 +18,8 @@ extern bool _etoile(
%}

extern bool _etoile(
std::pair<double,double>& output,
double& x,
double& y,
double cx,
double cy,
double r,
Expand Down
9 changes: 5 additions & 4 deletions src/swig/src/Dessin.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import java.util.ArrayList;

public class Dessin {
public static String VERSION="0.0.2";
public static String VERSION="0.0.3";

public static void main(String[] argv) {
// Ceci est un test.
Expand All @@ -19,10 +19,11 @@ public static List<PVector> etoile(float cx, float cy, float r) {

public static List<PVector> etoile(float cx, float cy, float r, float steps) {
List<PVector> points = new ArrayList<PVector>();
pair_double point = new pair_double();
double[] x = new double[]{0};
double[] y = new double[]{0};
for(double i=0; i <= 1; i += 1/steps) {
if (shared._etoile(point, (double) cx, (double) cy, (double) r, i)) {
points.add(new PVector((float) point.getFirst(), (float) point.getSecond()));
if (shared._etoile(x, y, (double) cx, (double) cy, (double) r, i)) {
points.add(new PVector((float) x[0], (float) y[0]));
} else {
System.err.printf("Appel à etoile(%f, %f, %f, %d) a échoué.", cx, cy, r, i);
return points;
Expand Down

0 comments on commit 6ddb7d8

Please sign in to comment.