Fix bugs with chinese postman solving

pull/170/head
James Ball 2023-01-19 22:16:13 +00:00
rodzic f43a82ae78
commit ece67ce7ee
4 zmienionych plików z 18 dodań i 12 usunięć

Wyświetl plik

@ -5,7 +5,7 @@ EffectsComponent::EffectsComponent(OscirenderAudioProcessor& p) : audioProcessor
addAndMakeVisible(frequency);
frequency.slider.setRange(40.0, 10000.0);
frequency.slider.setRange(0.0, 12000.0);
frequency.slider.setSkewFactorFromMidPoint(500.0);
frequency.slider.setTextValueSuffix("Hz");
frequency.slider.setValue(440.0);

Wyświetl plik

@ -43,7 +43,7 @@ pair< vector<int>, vector<double> > Dijkstra(const Graph & G, int origin, const
if(permanent[v])
continue;
double c = cost.empty() ? 1.0 : pathCost[u] + cost[G.GetEdgeIndex(u,v)];
double c = pathCost[u] + (cost.empty() ? 1.0 : cost[G.GetEdgeIndex(u,v)]);
//v has not been discovered yet
if(father[v] == -1)

Wyświetl plik

@ -4,9 +4,9 @@
Camera::Camera(double focalLength, double x, double y, double z) : focalLength(focalLength), x(x), y(y), z(z) {}
std::vector<std::unique_ptr<Shape>> Camera::draw(WorldObject& object)
{
std::vector<std::unique_ptr<Shape>> Camera::draw(WorldObject& object) {
std::vector<std::unique_ptr<Shape>> shapes;
object.rotateY += 0.001;
for (auto& edge : object.edges) {
Vector2 start = project(object.rotateX, object.rotateY, object.rotateZ, edge.x1, edge.y1, edge.z1);
Vector2 end = project(object.rotateX, object.rotateY, object.rotateZ, edge.x2, edge.y2, edge.z2);
@ -84,8 +84,8 @@ Vector2 Camera::project(double objRotateX, double objRotateY, double objRotateZ,
double x3 = cosValue * x2 - sinValue * y2;
double y3 = sinValue * x2 + cosValue * y2;
double start = x3 * focalLength / (z3 - z) + x;
double end = y3 * focalLength / (z3 - z) + y;
double start = x3 * focalLength / (z3 - this->z) + this->x;
double end = y3 * focalLength / (z3 - this->z) + this->y;
return Vector2(start, end);
}

Wyświetl plik

@ -114,15 +114,21 @@ WorldObject::WorldObject(juce::InputStream& stream) {
y /= vertices.size();
z /= vertices.size();
for (auto& v : vertices) {
v.v[0] = (v.v[0] - x) / max;
v.v[1] = (v.v[1] - y) / max;
v.v[2] = (v.v[2] - z) / max;
}
int prevVertex = -1;
for (auto& vertex : path) {
if (prevVertex != -1) {
double x1 = (vertices[prevVertex].v[0] - x) / max;
double y1 = (vertices[prevVertex].v[1] - y) / max;
double z1 = (vertices[prevVertex].v[2] - z) / max;
double x2 = (vertices[vertex].v[0] - x) / max;
double y2 = (vertices[vertex].v[1] - y) / max;
double z2 = (vertices[vertex].v[2] - z) / max;
double x1 = vertices[prevVertex].v[0];
double y1 = vertices[prevVertex].v[1];
double z1 = vertices[prevVertex].v[2];
double x2 = vertices[vertex].v[0];
double y2 = vertices[vertex].v[1];
double z2 = vertices[vertex].v[2];
edges.push_back(Line3D(x1, y1, z1, x2, y2, z2));
}