On 05/01/13 09:51, Carlos Dávila wrote:
The txt file I use as base for my TYP files contains some 60 points
defined. Most of them are correctly displayed when compiled with mkgmap,
but a few of them are not (see them below).

Thanks for supplying your complete file.

I found that the index portions of the file are not being sorted by
type.  Strange that has never been discovered before... I even have a
comment reminding me that something will need to be sorted.

Attached patch fixes. Pre-compiled version at http://files.mkgmap.org.uk/detail/81


..Steve
Index: src/uk/me/parabola/imgfmt/app/typ/TYPFile.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- src/uk/me/parabola/imgfmt/app/typ/TYPFile.java	(revision 2434)
+++ src/uk/me/parabola/imgfmt/app/typ/TYPFile.java	(revision )
@@ -61,9 +61,6 @@
 	}
 
 	public void write() {
-		// HEADER_LEN => 1. Image
-		//Collections.sort(images, BitmapImage.comparator());
-		// TODO we will probably have to sort something.
 
 		ImgFileWriter writer = getWriter();
 		writer.position(TYPHeader.HEADER_LEN);
@@ -163,6 +160,8 @@
 	private void writeSection(ImgFileWriter writer, Section dataSection, Section indexSection,
 			List<? extends TypElement> elementData)
 	{
+		Collections.sort(elementData);
+
 		SectionWriter subWriter = dataSection.makeSectionWriter(writer);
 		CharsetEncoder encoder = data.getEncoder();
 		for (TypElement elem : elementData)
@@ -172,16 +171,15 @@
 		int size = dataSection.getSize();
 		int typeSize = indexSection.getItemSize();
 		int psize = ptrSize(size);
-		//if (psize == 1)
-		//	psize = 2;
+
 		indexSection.setItemSize((char) (typeSize + psize));
 
 		subWriter = indexSection.makeSectionWriter(writer);
 		for (TypElement elem : elementData) {
 			int offset = elem.getOffset();
 			int type = elem.getTypeForFile();
-			putN(writer, typeSize, type);
-			putN(writer, psize, offset);
+			putN(subWriter, typeSize, type);
+			putN(subWriter, psize, offset);
 		}
 		Utils.closeFile(subWriter);
 
Index: src/uk/me/parabola/imgfmt/app/typ/TypElement.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- src/uk/me/parabola/imgfmt/app/typ/TypElement.java	(revision 2434)
+++ src/uk/me/parabola/imgfmt/app/typ/TypElement.java	(revision )
@@ -29,7 +29,7 @@
  *
  * @author Steve Ratcliffe
  */
-public abstract class TypElement {
+public abstract class TypElement implements Comparable<TypElement> {
 	private int type;
 	private int subType;
 
@@ -53,6 +53,24 @@
 
 	public int getType() {
 		return type;
+	}
+
+	/**
+	 * We sort these by type.
+	 * Only the index needs to be sorted (probably) but we don't create the index separately.
+	 *
+	 * @param o The other object to compare against.
+	 * @return The usual -1, 0, 1 for the other object being less than, equal, greater than than this.
+	 */
+	public int compareTo(TypElement o) {
+		int t1 = getTypeForFile();
+		int t2 = o.getTypeForFile();
+		if (t1 == t2)
+			return 0;
+		else if (t1 < t2)
+			return -1;
+		else
+			return 1;
 	}
 
 	/**
_______________________________________________
mkgmap-dev mailing list
[email protected]
http://lists.mkgmap.org.uk/mailman/listinfo/mkgmap-dev

Reply via email to