Skip to content
Snippets Groups Projects
Commit 6cf76932 authored by Thomas Oster's avatar Thomas Oster
Browse files

Merge pull request #20 DeleteDuplicatePathsOptimizer from renebohne/LibLaserCut patch-1

parent cc5ac9bf
No related branches found
No related tags found
No related merge requests found
/**
* This file is part of LibLaserCut.
* Copyright (C) 2011 - 2014 Thomas Oster <mail@thomas-oster.de>
*
* LibLaserCut is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* LibLaserCut is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with LibLaserCut. If not, see <http://www.gnu.org/licenses/>.
*
**/
package com.t_oster.liblasercut.vectoroptimizers;
import java.util.LinkedList;
import java.util.List;
/**
* This VectorOptimizer removes all duplicate (identical) Elements
* and sorts the remaining (unique) elements with a NearestVectorOptimizer
* @author René Bohne
*/
public class DeleteDuplicatePathsOptimizer extends VectorOptimizer
{
@Override
protected List<Element> sort(List<Element> e)
{
List<Element> result = new LinkedList<Element>();
if (e.isEmpty())
{
return result;
}
List<Element> doubleEntries = new LinkedList<Element>();
for(int i=0;i<e.size();i++)
{
for(int j=0;j<e.size();j++)
{
if(i!=j)
{
if(e.get(i).equals(e.get(j)))
{
if(!doubleEntries.contains(e.get(j)))
{
doubleEntries.add(e.get(i));
}
}
}
}
}
for(Element doubleEntry : doubleEntries)
{
e.remove(doubleEntry);
}
NearestVectorOptimizer vo = new NearestVectorOptimizer();
result = vo.sort(e);
return result;
}
}
......@@ -38,7 +38,8 @@ public abstract class VectorOptimizer
FILE,
NEAREST,
INNER_FIRST,
SMALLEST_FIRST
SMALLEST_FIRST,
DELETE_DUPLICATE_PATHS
}
protected class Element
......@@ -48,6 +49,30 @@ public abstract class VectorOptimizer
Point start;
List<Point> moves = new LinkedList<Point>();
public boolean equals(Element e)
{
if(this.moves.size()==e.moves.size())
{
if (!this.start.equals(e.start) )
{
return false;//start point differs
}
for (int j = 0; j < this.moves.size(); j++)
{
if (!this.moves.get(j).equals(e.moves.get(j)))
{
return false;//one move point differs
}
}
}
else
{
return false;
}
return true;
}
void invert()
{
if (!moves.isEmpty())
......@@ -114,6 +139,8 @@ public abstract class VectorOptimizer
return new InnerFirstVectorOptimizer();
case SMALLEST_FIRST:
return new SmallestFirstVectorOptimizer();
case DELETE_DUPLICATE_PATHS:
return new DeleteDuplicatePathsOptimizer();
}
throw new IllegalArgumentException("Unknown Order Strategy: " + s);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment