mirror of
https://github.com/csharpee/Map-Projections.git
synced 2025-12-13 00:00:07 -05:00
I'll have you arrayned for this
I replaced all the linkedlists of path commands with arraylists because it was actually making the projection exteremely slow. I could alternatively have reritten all of my for-loops over paths to be for-each instead of index-based, which would have solved the same problem, but I think arraylists are just better in general for this. it's not like I'm short on memory here. there's only one instance of me calling .remove(), and it's right after some funky indexing stuff, so a linkedlist wouldn't really help there anyway.
This commit is contained in:
parent
ef3628fb67
commit
f7d49c1149
@ -49,6 +49,7 @@ import org.xml.sax.SAXException;
|
|||||||
import javax.xml.parsers.ParserConfigurationException;
|
import javax.xml.parsers.ParserConfigurationException;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.BiConsumer;
|
import java.util.function.BiConsumer;
|
||||||
@ -334,7 +335,7 @@ public class MapDesignerVector extends MapApplication {
|
|||||||
else if (elementS instanceof GeographicPath) {
|
else if (elementS instanceof GeographicPath) {
|
||||||
GeographicPath pathS = (GeographicPath) elementS;
|
GeographicPath pathS = (GeographicPath) elementS;
|
||||||
List<Path.Command> commandsS = pathS.commands;
|
List<Path.Command> commandsS = pathS.commands;
|
||||||
List<Path.Command> commandsP = new LinkedList<>();
|
List<Path.Command> commandsP = new ArrayList<>();
|
||||||
if (commandsS.size() > 2*max(1, step)) {
|
if (commandsS.size() > 2*max(1, step)) {
|
||||||
int j = 0;
|
int j = 0;
|
||||||
while (j < commandsS.size()) {
|
while (j < commandsS.size()) {
|
||||||
|
|||||||
@ -3,7 +3,6 @@ package image;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static java.lang.Double.isFinite;
|
import static java.lang.Double.isFinite;
|
||||||
@ -69,7 +68,7 @@ public class Path {
|
|||||||
* shift a path by some amount in some direction
|
* shift a path by some amount in some direction
|
||||||
*/
|
*/
|
||||||
public static List<Command> translated(double xShift, double yShift, List<Command> path) {
|
public static List<Command> translated(double xShift, double yShift, List<Command> path) {
|
||||||
List<Command> newPath = new LinkedList<>();
|
List<Command> newPath = new ArrayList<>();
|
||||||
for (Command old: path) {
|
for (Command old: path) {
|
||||||
double[] newArgs = Arrays.copyOf(old.args, old.args.length);
|
double[] newArgs = Arrays.copyOf(old.args, old.args.length);
|
||||||
switch (old.type) {
|
switch (old.type) {
|
||||||
@ -109,7 +108,7 @@ public class Path {
|
|||||||
* either or both may be negative.
|
* either or both may be negative.
|
||||||
*/
|
*/
|
||||||
public static List<Command> scaled(double xScale, double yScale, List<Command> path) {
|
public static List<Command> scaled(double xScale, double yScale, List<Command> path) {
|
||||||
List<Command> newPath = new LinkedList<>();
|
List<Command> newPath = new ArrayList<>();
|
||||||
for (Command old: path) {
|
for (Command old: path) {
|
||||||
double[] newArgs = Arrays.copyOf(old.args, old.args.length);
|
double[] newArgs = Arrays.copyOf(old.args, old.args.length);
|
||||||
switch (old.type) {
|
switch (old.type) {
|
||||||
@ -154,7 +153,7 @@ public class Path {
|
|||||||
* positive is widdershins and negative is clockwise.
|
* positive is widdershins and negative is clockwise.
|
||||||
*/
|
*/
|
||||||
public static List<Command> rotated(double rotation, List<Command> path) {
|
public static List<Command> rotated(double rotation, List<Command> path) {
|
||||||
List<Command> newPath = new LinkedList<>();
|
List<Command> newPath = new ArrayList<>();
|
||||||
for (Command old: path) {
|
for (Command old: path) {
|
||||||
char newType = old.type;
|
char newType = old.type;
|
||||||
double[] newArgs = Arrays.copyOf(old.args, old.args.length);
|
double[] newArgs = Arrays.copyOf(old.args, old.args.length);
|
||||||
|
|||||||
@ -42,7 +42,6 @@ import java.nio.file.Files;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Stack;
|
import java.util.Stack;
|
||||||
|
|
||||||
@ -50,7 +49,6 @@ import static java.lang.Double.NaN;
|
|||||||
import static java.lang.Double.parseDouble;
|
import static java.lang.Double.parseDouble;
|
||||||
import static java.lang.Math.PI;
|
import static java.lang.Math.PI;
|
||||||
import static java.lang.Math.hypot;
|
import static java.lang.Math.hypot;
|
||||||
import static java.lang.Math.min;
|
|
||||||
import static java.lang.String.format;
|
import static java.lang.String.format;
|
||||||
import static utils.Math2.linInterp;
|
import static utils.Math2.linInterp;
|
||||||
import static utils.Math2.max;
|
import static utils.Math2.max;
|
||||||
@ -78,7 +76,7 @@ public class SVGMap implements Iterable<SVGMap.SVGElement>, SavableImage {
|
|||||||
* @throws ParserConfigurationException if the SAXParser object can't be constructed for some reason
|
* @throws ParserConfigurationException if the SAXParser object can't be constructed for some reason
|
||||||
*/
|
*/
|
||||||
public SVGMap(File file) throws IOException, SAXException, ParserConfigurationException {
|
public SVGMap(File file) throws IOException, SAXException, ParserConfigurationException {
|
||||||
elements = new LinkedList<>(); // the list elements
|
elements = new ArrayList<>(); // the list elements
|
||||||
|
|
||||||
final SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
|
final SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
|
||||||
|
|
||||||
@ -467,7 +465,7 @@ public class SVGMap implements Iterable<SVGMap.SVGElement>, SavableImage {
|
|||||||
*/
|
*/
|
||||||
public static GeographicPath breakWraps(GeographicPath continuous, double inSize, boolean strict) { //break excessively long commands, as they are likely wrapping over a discontinuity
|
public static GeographicPath breakWraps(GeographicPath continuous, double inSize, boolean strict) { //break excessively long commands, as they are likely wrapping over a discontinuity
|
||||||
if (continuous.commands.size() <= 2) return continuous;
|
if (continuous.commands.size() <= 2) return continuous;
|
||||||
List<Path.Command> broken = new LinkedList<>();
|
List<Path.Command> broken = new ArrayList<>();
|
||||||
double[] lens = {0, 0, 0}; //the revolving array of command lengths
|
double[] lens = {0, 0, 0}; //the revolving array of command lengths
|
||||||
for (int i = 0; i < continuous.commands.size(); i ++) {
|
for (int i = 0; i < continuous.commands.size(); i ++) {
|
||||||
if (i < continuous.commands.size()-1 && continuous.commands.get(i+1).type != 'M')
|
if (i < continuous.commands.size()-1 && continuous.commands.get(i+1).type != 'M')
|
||||||
@ -502,7 +500,7 @@ public class SVGMap implements Iterable<SVGMap.SVGElement>, SavableImage {
|
|||||||
if (cmd.type == 'M') { //separated by movetos
|
if (cmd.type == 'M') { //separated by movetos
|
||||||
if (currentPart != null)
|
if (currentPart != null)
|
||||||
parts.add(currentPart);
|
parts.add(currentPart);
|
||||||
currentPart = new LinkedList<Path.Command>();
|
currentPart = new ArrayList<Path.Command>();
|
||||||
}
|
}
|
||||||
else if (currentPart == null)
|
else if (currentPart == null)
|
||||||
throw new RuntimeException(format(
|
throw new RuntimeException(format(
|
||||||
@ -511,7 +509,7 @@ public class SVGMap implements Iterable<SVGMap.SVGElement>, SavableImage {
|
|||||||
}
|
}
|
||||||
parts.add(currentPart);
|
parts.add(currentPart);
|
||||||
|
|
||||||
List<Path.Command> closed = new LinkedList<Path.Command>();
|
List<Path.Command> closed = new ArrayList<Path.Command>();
|
||||||
for (int i = 0; i < parts.size(); i ++) { //now look through those parts
|
for (int i = 0; i < parts.size(); i ++) { //now look through those parts
|
||||||
List<Path.Command> partI = parts.get(i);
|
List<Path.Command> partI = parts.get(i);
|
||||||
if (partI.size() > 1
|
if (partI.size() > 1
|
||||||
|
|||||||
@ -355,7 +355,7 @@ public abstract class Projection {
|
|||||||
*/
|
*/
|
||||||
public List<Path.Command> drawGraticule(double spacing, double precision, double outW, double outH,
|
public List<Path.Command> drawGraticule(double spacing, double precision, double outW, double outH,
|
||||||
double maxLat, double maxLon, double[] pole) {
|
double maxLat, double maxLon, double[] pole) {
|
||||||
List<Path.Command> output = new LinkedList<>();
|
List<Path.Command> output = new ArrayList<>();
|
||||||
|
|
||||||
for (int y = 0; y < (int)(maxLat/spacing); y ++) {
|
for (int y = 0; y < (int)(maxLat/spacing); y ++) {
|
||||||
output.addAll(drawLoxodrome( //northern parallel
|
output.addAll(drawLoxodrome( //northern parallel
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user