Support e notation in SVGs, and correctly skip over small shapes when rendering

pull/42/head v1.16.2
James Ball 2021-12-18 13:50:34 +00:00 zatwierdzone przez James H Ball
rodzic b5d2861714
commit aadeb6f95d
5 zmienionych plików z 33 dodań i 19 usunięć

Wyświetl plik

@ -6,7 +6,7 @@
<groupId>sh.ball</groupId> <groupId>sh.ball</groupId>
<artifactId>osci-render</artifactId> <artifactId>osci-render</artifactId>
<version>1.16.1</version> <version>1.16.2</version>
<name>osci-render</name> <name>osci-render</name>

Wyświetl plik

@ -112,11 +112,17 @@ public class ShapeAudioPlayer implements AudioPlayer<List<Shape>> {
count = 0; count = 0;
} }
if (shapeDrawn > length) { // Need to skip all shapes that the lengthIncrement draws over.
// We do -= length here rather than resetting to 0 since it is correct // This is especially an issue when there are lots of small lines being
// to skip a small bit of the next shape, in line with the length increment // drawn.
while (shapeDrawn > length) {
shapeDrawn -= length; shapeDrawn -= length;
currentShape++; currentShape++;
// otherwise, index out of bounds
if (currentShape >= frame.size()) {
break;
}
length = getCurrentShape().getLength();
} }
double proportionalLength = trace * frameLength; double proportionalLength = trace * frameLength;

Wyświetl plik

@ -89,8 +89,8 @@ public class Controller implements Initializable, FrequencyListener, MidiListene
// frames // frames
private static final InputStream DEFAULT_OBJ = Controller.class.getResourceAsStream("/models/cube.obj"); private static final InputStream DEFAULT_OBJ = Controller.class.getResourceAsStream("/models/cube.obj");
private final ExecutorService executor = Executors.newSingleThreadExecutor(); private final ExecutorService executor = Executors.newSingleThreadExecutor();
private final List<byte[]> openFiles = new ArrayList<>(); private List<byte[]> openFiles = new ArrayList<>();
private final List<String> frameSourcePaths = new ArrayList<>(); private List<String> frameSourcePaths = new ArrayList<>();
private List<FrameSource<List<Shape>>> frameSources = new ArrayList<>(); private List<FrameSource<List<Shape>>> frameSources = new ArrayList<>();
private FrameProducer<List<Shape>> producer; private FrameProducer<List<Shape>> producer;
private int currentFrameSource; private int currentFrameSource;
@ -669,24 +669,28 @@ public class Controller implements Initializable, FrequencyListener, MidiListene
} }
private void updateFiles(List<byte[]> files, List<String> names) throws IOException, ParserConfigurationException, SAXException { private void updateFiles(List<byte[]> files, List<String> names) throws IOException, ParserConfigurationException, SAXException {
List<FrameSource<List<Shape>>> oldFrameSources = frameSources; List<FrameSource<List<Shape>>> newFrameSources = new ArrayList<>();
frameSources = new ArrayList<>(); List<String> newFrameSourcePaths = new ArrayList<>();
frameSourcePaths.clear(); List<byte[]> newOpenFiles = new ArrayList<>();
openFiles.clear();
jkLabel.setVisible(files.size() > 1);
framesPlaying = framesPlaying && files.size() > 1;
for (int i = 0; i < files.size(); i++) { for (int i = 0; i < files.size(); i++) {
try { try {
frameSources.add(ParserFactory.getParser(names.get(i), files.get(i)).parse()); newFrameSources.add(ParserFactory.getParser(names.get(i), files.get(i)).parse());
frameSourcePaths.add(names.get(i)); newFrameSourcePaths.add(names.get(i));
openFiles.add(files.get(i)); newOpenFiles.add(files.get(i));
} catch (IOException ignored) {} } catch (IOException ignored) {}
} }
oldFrameSources.forEach(FrameSource::disable); if (newFrameSources.size() > 0) {
jkLabel.setVisible(newFrameSources.size() > 1);
framesPlaying = framesPlaying && newFrameSources.size() > 1;
frameSources.forEach(FrameSource::disable);
frameSources = newFrameSources;
frameSourcePaths = newFrameSourcePaths;
openFiles = newOpenFiles;
changeFrameSource(0); changeFrameSource(0);
} }
}
// selects a new file or folder for files to be rendered from // selects a new file or folder for files to be rendered from
private void chooseFile(File chosenFile) { private void chooseFile(File chosenFile) {

Wyświetl plik

@ -11,7 +11,10 @@ class MoveTo {
// Parses moveto commands (M and m commands) // Parses moveto commands (M and m commands)
private static List<Shape> parseMoveTo(SvgState state, List<Float> args, boolean isAbsolute) { private static List<Shape> parseMoveTo(SvgState state, List<Float> args, boolean isAbsolute) {
if (args.size() % 2 != 0 || args.size() < 2) { if (args.size() % 2 != 0 || args.size() < 2) {
throw new IllegalArgumentException("SVG moveto command has incorrect number of arguments."); for (Float arg : args) {
System.out.println(arg);
}
throw new IllegalArgumentException("SVG moveto command has incorrect number of arguments.\n");
} }
Vector2 vec = new Vector2(args.get(0), args.get(1)); Vector2 vec = new Vector2(args.get(0), args.get(1));

Wyświetl plik

@ -77,7 +77,7 @@ public class SvgParser extends FileParser<FrameSource<List<Shape>>> {
private String[] preProcessPath(String path) throws IllegalArgumentException { private String[] preProcessPath(String path) throws IllegalArgumentException {
// Replace all commas with spaces and then remove unnecessary whitespace // Replace all commas with spaces and then remove unnecessary whitespace
path = path.replace(',', ' '); path = path.replace(',', ' ');
path = path.replace("-", " -"); path = path.replaceAll("(?<!e)-", " -");
path = path.replaceAll("\\s+", " "); path = path.replaceAll("\\s+", " ");
path = path.replaceAll("(^\\s|\\s$)", ""); path = path.replaceAll("(^\\s|\\s$)", "");
@ -112,6 +112,7 @@ public class SvgParser extends FileParser<FrameSource<List<Shape>>> {
} }
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace();
System.out.println(Arrays.toString(decimalSplit)); System.out.println(Arrays.toString(decimalSplit));
System.out.println(command); System.out.println(command);
} }