
// BuildShapes.java
// Martin Davis
// The LocationTech Technology (LTT) Group; Vivid Solutions
// https://github.com/locationtech/jts
// Modified by Andrew Davison, ad@coe.psu.ac.th, March 2023

/* Create shapes using a collection of points.

   Move/rotate a shape using AffineTransformation.

   Tests their similarity using HausdorffSimilarityMeasure 
   and AreaSimilarityMeasure

   Usage:
    > compile BuildShapes.java
    > run BuildShapes
*/


import org.locationtech.jts.geom.*;
import org.locationtech.jts.geom.util.*;
import org.locationtech.jts.algorithm.match.*;



public class BuildShapes
{
  private static final int NUM_SHAPES = 4;


  public static void main(String[] args)
  {
    GeomsViewer gv = Utils.view("Shapes");
    GeometryFactory gf = new GeometryFactory();

    Geometry[] shapes = new Geometry[NUM_SHAPES];

    shapes[0] = Utils.regularShape(70, 70, 50, 3);  // triangle
    gv.add("tri", shapes[0]);

    shapes[1] = Utils.rotate(shapes[0], 30);   
                 // clockwise rotation, creating a new shape
    shapes[1].apply(AffineTransformation.translationInstance(0, 100));  // move down
    gv.add("rotTri", shapes[1]);

    shapes[2] = Utils.regularShape(150, 70, 50, 6);  // hexagon
    gv.add("hexa", shapes[2]);
 
    shapes[3] = Utils.circle(150, 170, 50);
    gv.add("circle", shapes[3]);


    HausdorffSimilarityMeasure hsm = new HausdorffSimilarityMeasure();
    AreaSimilarityMeasure asm = new AreaSimilarityMeasure();
    System.out.println("\nSimilarity Measures:");
    for (int i = 0; i < NUM_SHAPES-1; i++)
      for (int j = i+1; j < NUM_SHAPES; j++)
        System.out.printf(
            "%s(%d) similar %s(%d) == %.2f (Hausdorff Dist), %.2f (Intersect Area)\n", 
                     Utils.getLabel(shapes[i]), i, Utils.getLabel(shapes[j]), j,
                     hsm.measure(shapes[i], shapes[j]),
                     asm.measure(shapes[i], shapes[j]) );

  }  // end of main()


}  // end of BuildShapes class