2424
2525package com .esri .core .geometry ;
2626
27- import java .util .ArrayList ;
2827import java .util .Arrays ;
29- import java .util .Collections ;
3028import java .util .Comparator ;
3129
30+ import static com .esri .core .geometry .SizeOf .SIZE_OF_EDGE ;
31+ import static com .esri .core .geometry .SizeOf .SIZE_OF_SIMPLE_RASTERIZER ;
32+ import static com .esri .core .geometry .SizeOf .sizeOfIntArray ;
33+ import static com .esri .core .geometry .SizeOf .sizeOfObjectArray ;
34+
3235/**
3336 * Simple scanline rasterizer. Caller provides a callback to draw pixels to actual surface.
3437 *
@@ -44,15 +47,22 @@ public class SimpleRasterizer {
4447 * Winding fill rule
4548 */
4649 public final static int WINDING = 1 ;
47-
48- public static interface ScanCallback {
50+
51+ public interface ScanCallback {
4952 /**
5053 * Rasterizer calls this method for each scan it produced
5154 * @param scans array of scans. Scans are triplets of numbers. The start X coordinate for the scan (inclusive),
5255 * the end X coordinate of the scan (exclusive), the Y coordinate for the scan.
5356 * @param scanCount3 The number of initialized elements in the scans array. The scan count is scanCount3 / 3.
5457 */
55- public abstract void drawScan (int [] scans , int scanCount3 );
58+ void drawScan (int [] scans , int scanCount3 );
59+
60+ /**
61+ * Returns an estimate of this object size in bytes.
62+ *
63+ * @return Returns an estimate of this object size in bytes.
64+ */
65+ long estimateMemorySize ();
5666 }
5767
5868 public SimpleRasterizer () {
@@ -340,17 +350,50 @@ final boolean addSegmentStroke(double x1, double y1, double x2, double y2, doubl
340350 }
341351
342352 public final ScanCallback getScanCallback () { return callback_ ; }
343-
344-
353+
354+ public long estimateMemorySize ()
355+ {
356+ // callback_ is only a pointer, the actual size is accounted for in the caller of setup()
357+ long size = SIZE_OF_SIMPLE_RASTERIZER +
358+ (activeEdgesTable_ != null ? activeEdgesTable_ .estimateMemorySize () : 0 ) +
359+ (scanBuffer_ != null ? sizeOfIntArray (scanBuffer_ .length ) : 0 );
360+
361+ if (ySortedEdges_ != null ) {
362+ size += sizeOfObjectArray (ySortedEdges_ .length );
363+ for (int i = 0 ; i < ySortedEdges_ .length ; i ++) {
364+ if (ySortedEdges_ [i ] != null ) {
365+ size += ySortedEdges_ [i ].estimateMemorySize ();
366+ }
367+ }
368+ }
369+
370+ if (sortBuffer_ != null ) {
371+ size += sizeOfObjectArray (sortBuffer_ .length );
372+ for (int i = 0 ; i < sortBuffer_ .length ; i ++) {
373+ if (sortBuffer_ [i ] != null ) {
374+ size += sortBuffer_ [i ].estimateMemorySize ();
375+ }
376+ }
377+ }
378+
379+ return size ;
380+ }
381+
345382 //PRIVATE
346383
347- private static class Edge {
384+ static class Edge {
348385 long x ;
349386 long dxdy ;
350387 int y ;
351388 int ymax ;
352389 int dir ;
353390 Edge next ;
391+
392+ long estimateMemorySize ()
393+ {
394+ // next is only a pointer, the actual size is accounted for in SimpleRasterizer#estimateMemorySize
395+ return SIZE_OF_EDGE ;
396+ }
354397 }
355398
356399 private final void advanceAET_ () {
0 commit comments